Re-sync with internal repository
[hiphop-php.git] / third-party / watchman / src / watchman / saved_state / SavedStateInterface.h
bloba1a5e328403a50d294f9362bb3a3450ecb780fa6
1 /*
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.
6 */
8 #pragma once
10 #include "watchman/thirdparty/jansson/jansson.h"
12 namespace watchman {
14 class Configuration;
15 class PerfSample;
16 class SavedStateInterface;
17 class SCM;
19 using SavedStateFactory = std::unique_ptr<SavedStateInterface> (*)(
20 w_string_piece storageType,
21 const json_ref& savedStateConfig,
22 const SCM* scm,
23 Configuration config,
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 {
34 public:
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
39 // storage type.
40 struct SavedStateResult {
41 w_string commitId;
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
47 // the storage type.
48 SavedStateResult getMostRecentSavedState(w_string_piece lookupCommitId) const;
50 protected:
51 w_string project_;
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