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.
This commit is contained in:
Martin von Zweigbergk 2022-09-22 21:01:38 -07:00 committed by Martin von Zweigbergk
parent c02f87170d
commit de7b5cf8b0
4 changed files with 16 additions and 1 deletions

View file

@ -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<git2::Repository>;

View file

@ -164,6 +164,10 @@ impl Debug for GitBackend {
}
impl Backend for GitBackend {
fn name(&self) -> &str {
"git"
}
fn hash_length(&self) -> usize {
HASH_LENGTH
}

View file

@ -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
}

View file

@ -142,7 +142,10 @@ impl ReadonlyRepo {
) -> Arc<ReadonlyRepo> {
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<dyn OpStore> = Arc::new(SimpleOpStore::init(repo_path.join("op_store")));
let mut root_view = op_store::View::default();