2 * Copyright (c) Meta Platforms, Inc. and affiliates.
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
10 #include "watchman/thirdparty/jansson/jansson.h"
16 class SavedStateInterface
;
19 using SavedStateFactory
= std::unique_ptr
<SavedStateInterface
> (*)(
20 w_string_piece storageType
,
21 const json_ref
& savedStateConfig
,
24 std::function
<void(PerfSample
&)> extraSampleMetadata
);
26 // An interface that returns information about saved states associated with
27 // specific source control commits. Clients using scm-aware queries can
28 // receive information about the most recent known good saved state when the
29 // mergebase changes, along with the changed files since that saved state. The
30 // client can then update the current state based on the saved state and the
31 // modified files since that state's commit, rather than processing all
32 // changes since the prior mergebase.
33 class SavedStateInterface
{
35 virtual ~SavedStateInterface();
37 // The commit ID of a saved state and a JSON blob of information clients can
38 // use to access the saved state. The contents of the info varies with the
40 struct SavedStateResult
{
42 std::optional
<json_ref
> savedStateInfo
;
44 // Returns saved state information for the most recent commit prior to and
45 // including lookupCommitId that has a valid saved state for the specified
46 // storage key. The contents of the storage key and the return value vary with
48 SavedStateResult
getMostRecentSavedState(w_string_piece lookupCommitId
) const;
52 w_string projectMetadata_
;
54 explicit SavedStateInterface(const json_ref
& savedStateConfig
);
55 virtual SavedStateResult
getMostRecentSavedStateImpl(
56 w_string_piece lookupCommitId
) const = 0;
58 } // namespace watchman