repo: move backend loading onto the StoreFactories struct
@@ -314,25 +314,9 @@ impl StoreFactories {
pub fn add_backend(&mut self, name: &str, factory: BackendFactory) {
self.backend_factories.insert(name.to_string(), factory);
}
-}
-#[derive(Clone)]
-pub struct RepoLoader {
- repo_path: PathBuf,
- repo_settings: RepoSettings,
- store: Arc<Store>,
- op_store: Arc<dyn OpStore>,
- op_heads_store: Arc<OpHeadsStore>,
- index_store: Arc<IndexStore>,
-}
-
-impl RepoLoader {
- pub fn init(
- user_settings: &UserSettings,
- repo_path: &Path,
- store_factories: &StoreFactories,
- ) -> Self {
- let store_path = repo_path.join("store");
+ pub fn load_backend(&self, store_path: &Path) -> Box<dyn Backend> {
+ // TODO: Change the 'backend' file to 'type', for consistency with other stores
let backend_type = match fs::read_to_string(store_path.join("backend")) {
Ok(content) => content,
Err(err) if err.kind() == ErrorKind::NotFound => {
@@ -349,11 +333,31 @@ impl RepoLoader {
panic!("Failed to read backend type");
}
};
- let backend_factory = store_factories
+ let backend_factory = self
.backend_factories
.get(&backend_type)
.expect("Unexpected backend type");
- let store = Store::new(backend_factory(&store_path));
+ backend_factory(store_path)
+ }
+}
+
+#[derive(Clone)]
+pub struct RepoLoader {
+ repo_path: PathBuf,
+ repo_settings: RepoSettings,
+ store: Arc<Store>,
+ op_store: Arc<dyn OpStore>,
+ op_heads_store: Arc<OpHeadsStore>,
+ index_store: Arc<IndexStore>,
+}
+
+impl RepoLoader {
+ pub fn init(
+ user_settings: &UserSettings,
+ repo_path: &Path,
+ store_factories: &StoreFactories,
+ ) -> Self {
+ let store = Store::new(store_factories.load_backend(&repo_path.join("store")));
let repo_settings = user_settings.with_repo(repo_path).unwrap();
let op_store: Arc<dyn OpStore> = Arc::new(SimpleOpStore::load(&repo_path.join("op_store")));
let op_heads_store = Arc::new(OpHeadsStore::load(repo_path.join("op_heads")));
