mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-03 21:08:27 +00:00
tree: rewrite sub_tree_recursive() to not use known_sub_tree()
This is the only place where the caller of known_sub_tree() doesn't know the full repo path.
This commit is contained in:
parent
589917a53c
commit
db7facb78e
1 changed files with 5 additions and 18 deletions
|
@ -159,27 +159,14 @@ impl Tree {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sub_tree_recursive(&self, components: &[RepoPathComponent]) -> Option<Tree> {
|
fn sub_tree_recursive(&self, components: &[RepoPathComponent]) -> Option<Tree> {
|
||||||
if components.is_empty() {
|
if let Some((first, tail)) = components.split_first() {
|
||||||
|
tail.iter()
|
||||||
|
.try_fold(self.sub_tree(first)?, |tree, name| tree.sub_tree(name))
|
||||||
|
} else {
|
||||||
// TODO: It would be nice to be able to return a reference here, but
|
// TODO: It would be nice to be able to return a reference here, but
|
||||||
// then we would have to figure out how to share Tree instances
|
// then we would have to figure out how to share Tree instances
|
||||||
// across threads.
|
// across threads.
|
||||||
Some(Tree {
|
Some(self.clone())
|
||||||
store: self.store.clone(),
|
|
||||||
dir: self.dir.clone(),
|
|
||||||
id: self.id.clone(),
|
|
||||||
data: self.data.clone(),
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
match self.data.entry(&components[0]) {
|
|
||||||
None => None,
|
|
||||||
Some(entry) => match entry.value() {
|
|
||||||
TreeValue::Tree(sub_tree_id) => {
|
|
||||||
let sub_tree = self.known_sub_tree(entry.name(), sub_tree_id);
|
|
||||||
sub_tree.sub_tree_recursive(&components[1..])
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue