mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-16 00:56:23 +00:00
merged_tree: extract function for merged iterator of basenames in diff
I'm going to reuse this for stream/async diffing.
This commit is contained in:
parent
b72f04ba61
commit
c9ce80a82a
1 changed files with 27 additions and 21 deletions
|
@ -442,6 +442,32 @@ fn all_tree_basenames(trees: &Merge<Tree>) -> impl Iterator<Item = &RepoPathComp
|
||||||
.dedup()
|
.dedup()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn merged_tree_basenames<'a>(
|
||||||
|
tree1: &'a MergedTree,
|
||||||
|
tree2: &'a MergedTree,
|
||||||
|
) -> Box<dyn Iterator<Item = &'a RepoPathComponent> + 'a> {
|
||||||
|
fn merge_iters<'a>(
|
||||||
|
iter1: impl Iterator<Item = &'a RepoPathComponent> + 'a,
|
||||||
|
iter2: impl Iterator<Item = &'a RepoPathComponent> + 'a,
|
||||||
|
) -> Box<dyn Iterator<Item = &'a RepoPathComponent> + 'a> {
|
||||||
|
Box::new(iter1.merge(iter2).dedup())
|
||||||
|
}
|
||||||
|
match (&tree1, &tree2) {
|
||||||
|
(MergedTree::Legacy(before), MergedTree::Legacy(after)) => {
|
||||||
|
merge_iters(before.data().names(), after.data().names())
|
||||||
|
}
|
||||||
|
(MergedTree::Merge(before), MergedTree::Legacy(after)) => {
|
||||||
|
merge_iters(all_tree_basenames(before), after.data().names())
|
||||||
|
}
|
||||||
|
(MergedTree::Legacy(before), MergedTree::Merge(after)) => {
|
||||||
|
merge_iters(before.data().names(), all_tree_basenames(after))
|
||||||
|
}
|
||||||
|
(MergedTree::Merge(before), MergedTree::Merge(after)) => {
|
||||||
|
merge_iters(all_tree_basenames(before), all_tree_basenames(after))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn merge_trees(merge: &Merge<Tree>) -> Result<Merge<Tree>, TreeMergeError> {
|
fn merge_trees(merge: &Merge<Tree>) -> Result<Merge<Tree>, TreeMergeError> {
|
||||||
if let Some(tree) = merge.resolve_trivial() {
|
if let Some(tree) = merge.resolve_trivial() {
|
||||||
return Ok(Merge::resolved(tree.clone()));
|
return Ok(Merge::resolved(tree.clone()));
|
||||||
|
@ -762,27 +788,7 @@ struct TreeEntryDiffIterator<'a> {
|
||||||
|
|
||||||
impl<'a> TreeEntryDiffIterator<'a> {
|
impl<'a> TreeEntryDiffIterator<'a> {
|
||||||
fn new(before: &'a MergedTree, after: &'a MergedTree) -> Self {
|
fn new(before: &'a MergedTree, after: &'a MergedTree) -> Self {
|
||||||
fn merge_iters<'a>(
|
let basename_iter = merged_tree_basenames(before, after);
|
||||||
iter1: impl Iterator<Item = &'a RepoPathComponent> + 'a,
|
|
||||||
iter2: impl Iterator<Item = &'a RepoPathComponent> + 'a,
|
|
||||||
) -> Box<dyn Iterator<Item = &'a RepoPathComponent> + 'a> {
|
|
||||||
Box::new(iter1.merge(iter2).dedup())
|
|
||||||
}
|
|
||||||
let basename_iter: Box<dyn Iterator<Item = &'a RepoPathComponent> + 'a> =
|
|
||||||
match (before, after) {
|
|
||||||
(MergedTree::Legacy(before), MergedTree::Legacy(after)) => {
|
|
||||||
merge_iters(before.data().names(), after.data().names())
|
|
||||||
}
|
|
||||||
(MergedTree::Merge(before), MergedTree::Legacy(after)) => {
|
|
||||||
merge_iters(all_tree_basenames(before), after.data().names())
|
|
||||||
}
|
|
||||||
(MergedTree::Legacy(before), MergedTree::Merge(after)) => {
|
|
||||||
merge_iters(before.data().names(), all_tree_basenames(after))
|
|
||||||
}
|
|
||||||
(MergedTree::Merge(before), MergedTree::Merge(after)) => {
|
|
||||||
merge_iters(all_tree_basenames(before), all_tree_basenames(after))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
TreeEntryDiffIterator {
|
TreeEntryDiffIterator {
|
||||||
before,
|
before,
|
||||||
after,
|
after,
|
||||||
|
|
Loading…
Reference in a new issue