From 79a066290faa0fdeb163b6823eb9de43f6df40ab Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Tue, 19 Sep 2023 03:55:51 -0700 Subject: [PATCH] backend: move constant functions first `root_commit_id()`, `root_change_id()`, and `empty_tree_id()` were strangely ordered between `write_symlink()` and `read_tree(). --- cli/examples/custom-backend/main.rs | 24 ++++++++++++------------ lib/src/backend.rs | 12 ++++++------ lib/src/git_backend.rs | 24 ++++++++++++------------ lib/src/local_backend.rs | 24 ++++++++++++------------ lib/src/store.rs | 16 ++++++++-------- 5 files changed, 50 insertions(+), 50 deletions(-) diff --git a/cli/examples/custom-backend/main.rs b/cli/examples/custom-backend/main.rs index 98173b2d20..5a39f39ab7 100644 --- a/cli/examples/custom-backend/main.rs +++ b/cli/examples/custom-backend/main.rs @@ -103,6 +103,18 @@ impl Backend for JitBackend { self.inner.change_id_length() } + fn root_commit_id(&self) -> &CommitId { + self.inner.root_commit_id() + } + + fn root_change_id(&self) -> &ChangeId { + self.inner.root_change_id() + } + + fn empty_tree_id(&self) -> &TreeId { + self.inner.empty_tree_id() + } + fn read_file(&self, path: &RepoPath, id: &FileId) -> BackendResult> { self.inner.read_file(path, id) } @@ -119,18 +131,6 @@ impl Backend for JitBackend { self.inner.write_symlink(path, target) } - fn root_commit_id(&self) -> &CommitId { - self.inner.root_commit_id() - } - - fn root_change_id(&self) -> &ChangeId { - self.inner.root_change_id() - } - - fn empty_tree_id(&self) -> &TreeId { - self.inner.empty_tree_id() - } - fn read_tree(&self, path: &RepoPath, id: &TreeId) -> BackendResult { self.inner.read_tree(path, id) } diff --git a/lib/src/backend.rs b/lib/src/backend.rs index a4ff9badd9..bfb702a816 100644 --- a/lib/src/backend.rs +++ b/lib/src/backend.rs @@ -478,6 +478,12 @@ pub trait Backend: Send + Sync + Debug { /// The length of change IDs in bytes. fn change_id_length(&self) -> usize; + fn root_commit_id(&self) -> &CommitId; + + fn root_change_id(&self) -> &ChangeId; + + fn empty_tree_id(&self) -> &TreeId; + fn read_file(&self, path: &RepoPath, id: &FileId) -> BackendResult>; fn write_file(&self, path: &RepoPath, contents: &mut dyn Read) -> BackendResult; @@ -486,12 +492,6 @@ pub trait Backend: Send + Sync + Debug { fn write_symlink(&self, path: &RepoPath, target: &str) -> BackendResult; - fn root_commit_id(&self) -> &CommitId; - - fn root_change_id(&self) -> &ChangeId; - - fn empty_tree_id(&self) -> &TreeId; - fn read_tree(&self, path: &RepoPath, id: &TreeId) -> BackendResult; fn write_tree(&self, path: &RepoPath, contents: &Tree) -> BackendResult; diff --git a/lib/src/git_backend.rs b/lib/src/git_backend.rs index bac37ffe40..e90b981419 100644 --- a/lib/src/git_backend.rs +++ b/lib/src/git_backend.rs @@ -480,6 +480,18 @@ impl Backend for GitBackend { CHANGE_ID_LENGTH } + fn root_commit_id(&self) -> &CommitId { + &self.root_commit_id + } + + fn root_change_id(&self) -> &ChangeId { + &self.root_change_id + } + + fn empty_tree_id(&self) -> &TreeId { + &self.empty_tree_id + } + fn read_file(&self, _path: &RepoPath, id: &FileId) -> BackendResult> { let git_blob_id = validate_git_object_id(id)?; let locked_repo = self.repo.lock().unwrap(); @@ -530,18 +542,6 @@ impl Backend for GitBackend { Ok(SymlinkId::new(oid.as_bytes().to_vec())) } - fn root_commit_id(&self) -> &CommitId { - &self.root_commit_id - } - - fn root_change_id(&self) -> &ChangeId { - &self.root_change_id - } - - fn empty_tree_id(&self) -> &TreeId { - &self.empty_tree_id - } - fn read_tree(&self, _path: &RepoPath, id: &TreeId) -> BackendResult { if id == &self.empty_tree_id { return Ok(Tree::default()); diff --git a/lib/src/local_backend.rs b/lib/src/local_backend.rs index 7bc6cbf340..86ae13ea6c 100644 --- a/lib/src/local_backend.rs +++ b/lib/src/local_backend.rs @@ -131,6 +131,18 @@ impl Backend for LocalBackend { CHANGE_ID_LENGTH } + fn root_commit_id(&self) -> &CommitId { + &self.root_commit_id + } + + fn root_change_id(&self) -> &ChangeId { + &self.root_change_id + } + + fn empty_tree_id(&self) -> &TreeId { + &self.empty_tree_id + } + fn read_file(&self, _path: &RepoPath, id: &FileId) -> BackendResult> { let path = self.file_path(id); let file = File::open(path).map_err(|err| map_not_found_err(err, id))?; @@ -179,18 +191,6 @@ impl Backend for LocalBackend { Ok(id) } - fn root_commit_id(&self) -> &CommitId { - &self.root_commit_id - } - - fn root_change_id(&self) -> &ChangeId { - &self.root_change_id - } - - fn empty_tree_id(&self) -> &TreeId { - &self.empty_tree_id - } - fn read_tree(&self, _path: &RepoPath, id: &TreeId) -> BackendResult { let path = self.tree_path(id); let buf = fs::read(path).map_err(|err| map_not_found_err(err, id))?; diff --git a/lib/src/store.rs b/lib/src/store.rs index c2ef06e6bf..a82be9f3db 100644 --- a/lib/src/store.rs +++ b/lib/src/store.rs @@ -76,14 +76,6 @@ impl Store { self.backend.change_id_length() } - pub fn empty_tree_id(&self) -> &TreeId { - self.backend.empty_tree_id() - } - - pub fn empty_merged_tree_id(&self) -> MergedTreeId { - MergedTreeId::Legacy(self.backend.empty_tree_id().clone()) - } - pub fn root_commit_id(&self) -> &CommitId { self.backend.root_commit_id() } @@ -92,6 +84,14 @@ impl Store { self.backend.root_change_id() } + pub fn empty_tree_id(&self) -> &TreeId { + self.backend.empty_tree_id() + } + + pub fn empty_merged_tree_id(&self) -> MergedTreeId { + MergedTreeId::Legacy(self.backend.empty_tree_id().clone()) + } + pub fn root_commit(self: &Arc) -> Commit { self.get_commit(self.backend.root_commit_id()).unwrap() }