backends: deduplicate definition of backend names

I copied the example set by `DefaultSubmoduleStore`.
This commit is contained in:
Martin von Zweigbergk 2023-10-14 06:09:33 -07:00 committed by Martin von Zweigbergk
parent 9186d0fd38
commit f8be0b2030
7 changed files with 31 additions and 11 deletions

View file

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

View file

@ -45,6 +45,6 @@ impl DefaultSubmoduleStore {
impl SubmoduleStore for DefaultSubmoduleStore {
fn name(&self) -> &str {
DefaultSubmoduleStore::name()
Self::name()
}
}

View file

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

View file

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

View file

@ -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))),
);

View file

@ -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) {

View file

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