merged_tree: make TreeEntriesIterator accept trees as &Merge<Tree>

Suppose we add copy information to MergedTree, a MergedTree can be considered
a root tree representation plus global metadata. I think Merge<Tree> is a better
type for sub trees.
This commit is contained in:
Yuya Nishihara 2024-08-08 18:16:48 +09:00
parent 8a3e4ad966
commit 12434b49b8

View file

@ -266,7 +266,7 @@ impl MergedTree {
&self, &self,
matcher: &'matcher dyn Matcher, matcher: &'matcher dyn Matcher,
) -> TreeEntriesIterator<'matcher> { ) -> TreeEntriesIterator<'matcher> {
TreeEntriesIterator::new(self, matcher) TreeEntriesIterator::new(&self.trees, matcher)
} }
/// Stream of the differences between this tree and another tree. /// Stream of the differences between this tree and another tree.
@ -462,12 +462,12 @@ struct TreeEntriesDirItem {
} }
impl TreeEntriesDirItem { impl TreeEntriesDirItem {
fn new(tree: &MergedTree, matcher: &dyn Matcher) -> Self { fn new(trees: &Merge<Tree>, matcher: &dyn Matcher) -> Self {
let mut entries = vec![]; let mut entries = vec![];
let dir = tree.dir(); let dir = trees.first().dir();
for name in tree.names() { for name in all_tree_basenames(trees) {
let path = dir.join(name); let path = dir.join(name);
let value = tree.value(name).to_merge(); let value = trees_value(trees, name).to_merge();
if value.is_tree() { if value.is_tree() {
// TODO: Handle the other cases (specific files and trees) // TODO: Handle the other cases (specific files and trees)
if matcher.visit(&path).is_nothing() { if matcher.visit(&path).is_nothing() {
@ -484,10 +484,10 @@ impl TreeEntriesDirItem {
} }
impl<'matcher> TreeEntriesIterator<'matcher> { impl<'matcher> TreeEntriesIterator<'matcher> {
fn new(tree: &MergedTree, matcher: &'matcher dyn Matcher) -> Self { fn new(trees: &Merge<Tree>, matcher: &'matcher dyn Matcher) -> Self {
Self { Self {
store: tree.store().clone(), store: trees.first().store().clone(),
stack: vec![TreeEntriesDirItem::new(tree, matcher)], stack: vec![TreeEntriesDirItem::new(trees, matcher)],
matcher, matcher,
} }
} }
@ -504,9 +504,8 @@ impl Iterator for TreeEntriesIterator<'_> {
Ok(trees) => trees.unwrap(), Ok(trees) => trees.unwrap(),
Err(err) => return Some((path, Err(err))), Err(err) => return Some((path, Err(err))),
}; };
let merged_tree = MergedTree { trees };
self.stack self.stack
.push(TreeEntriesDirItem::new(&merged_tree, self.matcher)); .push(TreeEntriesDirItem::new(&trees, self.matcher));
} else { } else {
return Some((path, Ok(value))); return Some((path, Ok(value)));
} }