diff --git a/lib/src/commit.rs b/lib/src/commit.rs index 391e67aa2..98d013741 100644 --- a/lib/src/commit.rs +++ b/lib/src/commit.rs @@ -110,16 +110,7 @@ impl Commit { } pub fn merged_tree(&self) -> Result { - match &self.data.root_tree { - MergedTreeId::Legacy(id) => { - let tree = self.store.get_tree(&RepoPath::root(), id)?; - Ok(MergedTree::Legacy(tree)) - } - MergedTreeId::Merge(ids) => { - let trees = ids.try_map(|id| self.store.get_tree(&RepoPath::root(), id))?; - Ok(MergedTree::Merge(trees)) - } - } + self.store.get_root_tree(&self.data.root_tree) } // TODO(#1624): delete when all callers have been updated to support tree-level diff --git a/lib/src/store.rs b/lib/src/store.rs index 5339041a5..020c21497 100644 --- a/lib/src/store.rs +++ b/lib/src/store.rs @@ -21,10 +21,12 @@ use std::sync::{Arc, RwLock}; use crate::backend; use crate::backend::{ - Backend, BackendResult, ChangeId, CommitId, ConflictId, FileId, SymlinkId, TreeId, TreeValue, + Backend, BackendResult, ChangeId, CommitId, ConflictId, FileId, MergedTreeId, SymlinkId, + TreeId, TreeValue, }; use crate::commit::Commit; use crate::merge::Merge; +use crate::merged_tree::MergedTree; use crate::repo_path::RepoPath; use crate::tree::Tree; use crate::tree_builder::TreeBuilder; @@ -125,6 +127,19 @@ impl Store { Ok(data) } + pub fn get_root_tree(self: &Arc, id: &MergedTreeId) -> BackendResult { + match &id { + MergedTreeId::Legacy(id) => { + let tree = self.get_tree(&RepoPath::root(), id)?; + Ok(MergedTree::Legacy(tree)) + } + MergedTreeId::Merge(ids) => { + let trees = ids.try_map(|id| self.get_tree(&RepoPath::root(), id))?; + Ok(MergedTree::Merge(trees)) + } + } + } + pub fn write_tree( self: &Arc, path: &RepoPath,