mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-16 00:56:23 +00:00
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:
parent
c02f87170d
commit
de7b5cf8b0
4 changed files with 16 additions and 1 deletions
|
@ -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>;
|
||||
|
|
|
@ -164,6 +164,10 @@ impl Debug for GitBackend {
|
|||
}
|
||||
|
||||
impl Backend for GitBackend {
|
||||
fn name(&self) -> &str {
|
||||
"git"
|
||||
}
|
||||
|
||||
fn hash_length(&self) -> usize {
|
||||
HASH_LENGTH
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue