From de7b5cf8b052b736c93688ba6da6429fc478f585 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Thu, 22 Sep 2022 21:01:38 -0700 Subject: [PATCH] repo: write format ("git" or "local") to disk on init We currently determine if the repo uses the Git backend or the local backend by checking for presence of a `.jj/repo/store/git_target` file. To make it easier to add out-of-tree backends, let's instead add a file that indicates which backend to use. --- lib/src/backend.rs | 4 ++++ lib/src/git_backend.rs | 4 ++++ lib/src/local_backend.rs | 4 ++++ lib/src/repo.rs | 5 ++++- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/src/backend.rs b/lib/src/backend.rs index c267dc9a5..2c9e03da8 100644 --- a/lib/src/backend.rs +++ b/lib/src/backend.rs @@ -398,6 +398,10 @@ pub fn make_root_commit(empty_tree_id: TreeId) -> Commit { } pub trait Backend: Send + Sync + Debug { + /// A unique name that identifies this backend. Written to + /// `.jj/repo/store/backend` when the repo is created. + fn name(&self) -> &str; + fn hash_length(&self) -> usize; fn git_repo(&self) -> Option; diff --git a/lib/src/git_backend.rs b/lib/src/git_backend.rs index 7143a722a..9649218be 100644 --- a/lib/src/git_backend.rs +++ b/lib/src/git_backend.rs @@ -164,6 +164,10 @@ impl Debug for GitBackend { } impl Backend for GitBackend { + fn name(&self) -> &str { + "git" + } + fn hash_length(&self) -> usize { HASH_LENGTH } diff --git a/lib/src/local_backend.rs b/lib/src/local_backend.rs index c041e6187..711d734b1 100644 --- a/lib/src/local_backend.rs +++ b/lib/src/local_backend.rs @@ -110,6 +110,10 @@ fn not_found_to_backend_error(err: std::io::Error) -> BackendError { } impl Backend for LocalBackend { + fn name(&self) -> &str { + "local" + } + fn hash_length(&self) -> usize { 64 } diff --git a/lib/src/repo.rs b/lib/src/repo.rs index f8548e73d..86e053baa 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -142,7 +142,10 @@ impl ReadonlyRepo { ) -> Arc { let repo_path = repo_path.canonicalize().unwrap(); ReadonlyRepo::init_repo_dir(&repo_path); - let store = Store::new(backend_factory(&repo_path.join("store"))); + let store_path = repo_path.join("store"); + let backend = backend_factory(&store_path); + fs::write(&store_path.join("backend"), backend.name()).unwrap(); + let store = Store::new(backend); let repo_settings = user_settings.with_repo(&repo_path).unwrap(); let op_store: Arc = Arc::new(SimpleOpStore::init(repo_path.join("op_store"))); let mut root_view = op_store::View::default();