Debian Codegraph @

lib/src/default_backend_factories.rs

raw
1 // Copyright 2026 The Jujutsu Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 //! Provides the default backend factories, i.e. `GitBackend` (if the `git`
16 //! feature is enabled), `SimpleOpStore`, `LocalWorkingCopy`, etc.
17
18 use crate::default_index::DefaultIndexStore;
19 use crate::default_submodule_store::DefaultSubmoduleStore;
20 use crate::local_working_copy::LocalWorkingCopy;
21 use crate::local_working_copy::LocalWorkingCopyFactory;
22 use crate::repo::StoreFactories;
23 use crate::simple_backend::SimpleBackend;
24 use crate::simple_op_heads_store::SimpleOpHeadsStore;
25 use crate::simple_op_store::SimpleOpStore;
26 use crate::working_copy::WorkingCopyFactory;
27 use crate::workspace::WorkingCopyFactories;
28
29 /// Returns default store factories.
30 pub fn default_backend_factories() -> StoreFactories {
31 let mut factories = StoreFactories::empty();
32
33 // Backends
34 factories.add_backend(
35 SimpleBackend::name(),
36 Box::new(|_settings, store_path| Ok(Box::new(SimpleBackend::load(store_path)))),
37 );
38 #[cfg(feature = "git")]
39 factories.add_backend(
40 crate::git_backend::GitBackend::name(),
41 Box::new(|settings, store_path| {
42 Ok(Box::new(crate::git_backend::GitBackend::load(
43 settings, store_path,
44 )?))
45 }),
46 );
47 #[cfg(feature = "testing")]
48 factories.add_backend(
49 crate::secret_backend::SecretBackend::name(),
50 Box::new(|settings, store_path| {
51 Ok(Box::new(crate::secret_backend::SecretBackend::load(
52 settings, store_path,
53 )?))
54 }),
55 );
56
57 // OpStores
58 factories.add_op_store(
59 SimpleOpStore::name(),
60 Box::new(|_settings, store_path, root_data| {
61 Ok(Box::new(SimpleOpStore::load(store_path, root_data)))
62 }),
63 );
64
65 // OpHeadsStores
66 factories.add_op_heads_store(
67 SimpleOpHeadsStore::name(),
68 Box::new(|_settings, store_path| Ok(Box::new(SimpleOpHeadsStore::load(store_path)))),
69 );
70
71 // Index
72 factories.add_index_store(
73 DefaultIndexStore::name(),
74 Box::new(|_settings, store_path| Ok(Box::new(DefaultIndexStore::load(store_path)))),
75 );
76
77 // SubmoduleStores
78 factories.add_submodule_store(
79 DefaultSubmoduleStore::name(),
80 Box::new(|_settings, store_path| Ok(Box::new(DefaultSubmoduleStore::load(store_path)))),
81 );
82
83 factories
84 }
85
86 /// Returns default working copy factories.
87 pub fn default_working_copy_factories() -> WorkingCopyFactories {
88 let mut factories = WorkingCopyFactories::new();
89 factories.insert(
90 LocalWorkingCopy::name().to_owned(),
91 Box::new(LocalWorkingCopyFactory {}),
92 );
93 factories
94 }
95
96 /// Returns the default (local-disk) working copy factory.
97 pub fn default_working_copy_factory() -> Box<dyn WorkingCopyFactory> {
98 Box::new(LocalWorkingCopyFactory {})
99 }