mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-28 23:32:41 +00:00
store: add function to look up MergedTree
by MergedTreeId
We'll start seeing `MergedTreeId` in more places and we'll want it to be easy to look up the tree.
This commit is contained in:
parent
2dd2e77170
commit
1577b408a6
2 changed files with 17 additions and 11 deletions
|
@ -110,16 +110,7 @@ impl Commit {
|
|||
}
|
||||
|
||||
pub fn merged_tree(&self) -> Result<MergedTree, BackendError> {
|
||||
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
|
||||
|
|
|
@ -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<Self>, id: &MergedTreeId) -> BackendResult<MergedTree> {
|
||||
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<Self>,
|
||||
path: &RepoPath,
|
||||
|
|
Loading…
Reference in a new issue