mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-19 19:08:08 +00:00
backend: move constant functions first
`root_commit_id()`, `root_change_id()`, and `empty_tree_id()` were strangely ordered between `write_symlink()` and `read_tree().
This commit is contained in:
parent
742df2758b
commit
d575aaeca8
5 changed files with 50 additions and 50 deletions
|
@ -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<Box<dyn Read>> {
|
||||
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<Tree> {
|
||||
self.inner.read_tree(path, id)
|
||||
}
|
||||
|
|
|
@ -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<Box<dyn Read>>;
|
||||
|
||||
fn write_file(&self, path: &RepoPath, contents: &mut dyn Read) -> BackendResult<FileId>;
|
||||
|
@ -486,12 +492,6 @@ pub trait Backend: Send + Sync + Debug {
|
|||
|
||||
fn write_symlink(&self, path: &RepoPath, target: &str) -> BackendResult<SymlinkId>;
|
||||
|
||||
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<Tree>;
|
||||
|
||||
fn write_tree(&self, path: &RepoPath, contents: &Tree) -> BackendResult<TreeId>;
|
||||
|
|
|
@ -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<Box<dyn Read>> {
|
||||
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<Tree> {
|
||||
if id == &self.empty_tree_id {
|
||||
return Ok(Tree::default());
|
||||
|
|
|
@ -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<Box<dyn Read>> {
|
||||
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<Tree> {
|
||||
let path = self.tree_path(id);
|
||||
let buf = fs::read(path).map_err(|err| map_not_found_err(err, id))?;
|
||||
|
|
|
@ -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<Self>) -> Commit {
|
||||
self.get_commit(self.backend.root_commit_id()).unwrap()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue