mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-06 05:04:18 +00:00
backends: deduplicate definition of backend names
I copied the example set by `DefaultSubmoduleStore`.
This commit is contained in:
parent
9186d0fd38
commit
f8be0b2030
7 changed files with 31 additions and 11 deletions
|
@ -60,6 +60,10 @@ pub struct DefaultIndexStore {
|
|||
}
|
||||
|
||||
impl DefaultIndexStore {
|
||||
pub fn name() -> &'static str {
|
||||
"default"
|
||||
}
|
||||
|
||||
pub fn init(dir: &Path) -> Self {
|
||||
std::fs::create_dir(dir.join("operations")).unwrap();
|
||||
DefaultIndexStore {
|
||||
|
@ -207,7 +211,7 @@ impl IndexStore for DefaultIndexStore {
|
|||
}
|
||||
|
||||
fn name(&self) -> &str {
|
||||
"default"
|
||||
Self::name()
|
||||
}
|
||||
|
||||
fn get_index_at_op(&self, op: &Operation, store: &Arc<Store>) -> Box<dyn ReadonlyIndex> {
|
||||
|
|
|
@ -45,6 +45,6 @@ impl DefaultSubmoduleStore {
|
|||
|
||||
impl SubmoduleStore for DefaultSubmoduleStore {
|
||||
fn name(&self) -> &str {
|
||||
DefaultSubmoduleStore::name()
|
||||
Self::name()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,6 +102,10 @@ pub struct GitBackend {
|
|||
}
|
||||
|
||||
impl GitBackend {
|
||||
pub fn name() -> &'static str {
|
||||
"git"
|
||||
}
|
||||
|
||||
fn new(repo: git2::Repository, extra_metadata_store: TableStore) -> Self {
|
||||
let root_commit_id = CommitId::from_bytes(&[0; HASH_LENGTH]);
|
||||
let root_change_id = ChangeId::from_bytes(&[0; CHANGE_ID_LENGTH]);
|
||||
|
@ -487,7 +491,7 @@ impl Backend for GitBackend {
|
|||
}
|
||||
|
||||
fn name(&self) -> &str {
|
||||
"git"
|
||||
Self::name()
|
||||
}
|
||||
|
||||
fn commit_id_length(&self) -> usize {
|
||||
|
|
|
@ -68,6 +68,10 @@ pub struct LocalBackend {
|
|||
}
|
||||
|
||||
impl LocalBackend {
|
||||
pub fn name() -> &'static str {
|
||||
"local"
|
||||
}
|
||||
|
||||
pub fn init(store_path: &Path) -> Self {
|
||||
fs::create_dir(store_path.join("commits")).unwrap();
|
||||
fs::create_dir(store_path.join("trees")).unwrap();
|
||||
|
@ -122,7 +126,7 @@ impl Backend for LocalBackend {
|
|||
}
|
||||
|
||||
fn name(&self) -> &str {
|
||||
"local"
|
||||
Self::name()
|
||||
}
|
||||
|
||||
fn commit_id_length(&self) -> usize {
|
||||
|
|
|
@ -359,29 +359,29 @@ impl Default for StoreFactories {
|
|||
|
||||
// Backends
|
||||
factories.add_backend(
|
||||
"local",
|
||||
LocalBackend::name(),
|
||||
Box::new(|store_path| Ok(Box::new(LocalBackend::load(store_path)))),
|
||||
);
|
||||
factories.add_backend(
|
||||
"git",
|
||||
GitBackend::name(),
|
||||
Box::new(|store_path| Ok(Box::new(GitBackend::load(store_path)?))),
|
||||
);
|
||||
|
||||
// OpStores
|
||||
factories.add_op_store(
|
||||
"simple_op_store",
|
||||
SimpleOpStore::name(),
|
||||
Box::new(|store_path| Box::new(SimpleOpStore::load(store_path))),
|
||||
);
|
||||
|
||||
// OpHeadsStores
|
||||
factories.add_op_heads_store(
|
||||
"simple_op_heads_store",
|
||||
SimpleOpHeadsStore::name(),
|
||||
Box::new(|store_path| Box::new(SimpleOpHeadsStore::load(store_path))),
|
||||
);
|
||||
|
||||
// Index
|
||||
factories.add_index_store(
|
||||
"default",
|
||||
DefaultIndexStore::name(),
|
||||
Box::new(|store_path| Box::new(DefaultIndexStore::load(store_path))),
|
||||
);
|
||||
|
||||
|
|
|
@ -37,6 +37,10 @@ impl Debug for SimpleOpHeadsStore {
|
|||
}
|
||||
|
||||
impl SimpleOpHeadsStore {
|
||||
pub fn name() -> &'static str {
|
||||
"simple_op_heads_store"
|
||||
}
|
||||
|
||||
pub fn init(dir: &Path) -> Self {
|
||||
let op_heads_dir = dir.join("heads");
|
||||
fs::create_dir(&op_heads_dir).unwrap();
|
||||
|
@ -85,7 +89,7 @@ impl OpHeadsStoreLock<'_> for SimpleOpHeadsStoreLock<'_> {
|
|||
|
||||
impl OpHeadsStore for SimpleOpHeadsStore {
|
||||
fn name(&self) -> &str {
|
||||
"simple_op_heads_store"
|
||||
Self::name()
|
||||
}
|
||||
|
||||
fn add_op_head(&self, id: &OperationId) {
|
||||
|
|
|
@ -61,6 +61,10 @@ pub struct SimpleOpStore {
|
|||
}
|
||||
|
||||
impl SimpleOpStore {
|
||||
pub fn name() -> &'static str {
|
||||
"simple_op_store"
|
||||
}
|
||||
|
||||
/// Creates an empty OpStore, panics if it already exists
|
||||
pub fn init(store_path: &Path) -> Self {
|
||||
fs::create_dir(store_path.join("views")).unwrap();
|
||||
|
@ -88,7 +92,7 @@ impl SimpleOpStore {
|
|||
|
||||
impl OpStore for SimpleOpStore {
|
||||
fn name(&self) -> &str {
|
||||
"simple_op_store"
|
||||
Self::name()
|
||||
}
|
||||
|
||||
fn read_view(&self, id: &ViewId) -> OpStoreResult<View> {
|
||||
|
|
Loading…
Reference in a new issue