mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-20 03:20:08 +00:00
merged_tree: inline next_impl()
and poll_next_impl()
This commit is contained in:
parent
ad86dd1c1b
commit
bce8550db1
1 changed files with 48 additions and 59 deletions
|
@ -695,8 +695,50 @@ impl<'matcher> TreeDiffIterator<'matcher> {
|
||||||
Ok(Merge::resolved(Tree::empty(store.clone(), dir.to_owned())))
|
Ok(Merge::resolved(Tree::empty(store.clone(), dir.to_owned())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn next_impl(&mut self) -> Option<TreeDiffEntry> {
|
impl TreeDiffDirItem {
|
||||||
|
fn from_trees(
|
||||||
|
dir: &RepoPath,
|
||||||
|
trees1: &Merge<Tree>,
|
||||||
|
trees2: &Merge<Tree>,
|
||||||
|
matcher: &dyn Matcher,
|
||||||
|
) -> Self {
|
||||||
|
let mut entries = vec![];
|
||||||
|
for (name, before, after) in merged_tree_entry_diff(trees1, trees2) {
|
||||||
|
let path = dir.join(name);
|
||||||
|
let tree_before = before.is_tree();
|
||||||
|
let tree_after = after.is_tree();
|
||||||
|
// Check if trees and files match, but only if either side is a tree or a file
|
||||||
|
// (don't query the matcher unnecessarily).
|
||||||
|
let tree_matches = (tree_before || tree_after) && !matcher.visit(&path).is_nothing();
|
||||||
|
let file_matches = (!tree_before || !tree_after) && matcher.matches(&path);
|
||||||
|
|
||||||
|
// Replace trees or files that don't match by `Merge::absent()`
|
||||||
|
let before = if (tree_before && tree_matches) || (!tree_before && file_matches) {
|
||||||
|
before
|
||||||
|
} else {
|
||||||
|
Merge::absent()
|
||||||
|
};
|
||||||
|
let after = if (tree_after && tree_matches) || (!tree_after && file_matches) {
|
||||||
|
after
|
||||||
|
} else {
|
||||||
|
Merge::absent()
|
||||||
|
};
|
||||||
|
if before.is_absent() && after.is_absent() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
entries.push((path, before.cloned(), after.cloned()));
|
||||||
|
}
|
||||||
|
entries.reverse();
|
||||||
|
Self { entries }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Iterator for TreeDiffIterator<'_> {
|
||||||
|
type Item = TreeDiffEntry;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
while let Some(top) = self.stack.last_mut() {
|
while let Some(top) = self.stack.last_mut() {
|
||||||
let (path, before, after) = match top {
|
let (path, before, after) = match top {
|
||||||
TreeDiffItem::Dir(dir) => match dir.entries.pop() {
|
TreeDiffItem::Dir(dir) => match dir.entries.pop() {
|
||||||
|
@ -776,52 +818,6 @@ impl<'matcher> TreeDiffIterator<'matcher> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TreeDiffDirItem {
|
|
||||||
fn from_trees(
|
|
||||||
dir: &RepoPath,
|
|
||||||
trees1: &Merge<Tree>,
|
|
||||||
trees2: &Merge<Tree>,
|
|
||||||
matcher: &dyn Matcher,
|
|
||||||
) -> Self {
|
|
||||||
let mut entries = vec![];
|
|
||||||
for (name, before, after) in merged_tree_entry_diff(trees1, trees2) {
|
|
||||||
let path = dir.join(name);
|
|
||||||
let tree_before = before.is_tree();
|
|
||||||
let tree_after = after.is_tree();
|
|
||||||
// Check if trees and files match, but only if either side is a tree or a file
|
|
||||||
// (don't query the matcher unnecessarily).
|
|
||||||
let tree_matches = (tree_before || tree_after) && !matcher.visit(&path).is_nothing();
|
|
||||||
let file_matches = (!tree_before || !tree_after) && matcher.matches(&path);
|
|
||||||
|
|
||||||
// Replace trees or files that don't match by `Merge::absent()`
|
|
||||||
let before = if (tree_before && tree_matches) || (!tree_before && file_matches) {
|
|
||||||
before
|
|
||||||
} else {
|
|
||||||
Merge::absent()
|
|
||||||
};
|
|
||||||
let after = if (tree_after && tree_matches) || (!tree_after && file_matches) {
|
|
||||||
after
|
|
||||||
} else {
|
|
||||||
Merge::absent()
|
|
||||||
};
|
|
||||||
if before.is_absent() && after.is_absent() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
entries.push((path, before.cloned(), after.cloned()));
|
|
||||||
}
|
|
||||||
entries.reverse();
|
|
||||||
Self { entries }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Iterator for TreeDiffIterator<'_> {
|
|
||||||
type Item = TreeDiffEntry;
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
self.next_impl()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Stream of differences between two trees.
|
/// Stream of differences between two trees.
|
||||||
pub struct TreeDiffStreamImpl<'matcher> {
|
pub struct TreeDiffStreamImpl<'matcher> {
|
||||||
matcher: &'matcher dyn Matcher,
|
matcher: &'matcher dyn Matcher,
|
||||||
|
@ -1028,11 +1024,12 @@ impl<'matcher> TreeDiffStreamImpl<'matcher> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn poll_next_impl(
|
impl Stream for TreeDiffStreamImpl<'_> {
|
||||||
mut self: Pin<&mut Self>,
|
type Item = TreeDiffEntry;
|
||||||
cx: &mut Context<'_>,
|
|
||||||
) -> Poll<Option<TreeDiffEntry>> {
|
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
// Go through all pending tree futures and poll them.
|
// Go through all pending tree futures and poll them.
|
||||||
self.poll_tree_futures(cx);
|
self.poll_tree_futures(cx);
|
||||||
|
|
||||||
|
@ -1084,14 +1081,6 @@ impl<'matcher> TreeDiffStreamImpl<'matcher> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Stream for TreeDiffStreamImpl<'_> {
|
|
||||||
type Item = TreeDiffEntry;
|
|
||||||
|
|
||||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
|
||||||
self.as_mut().poll_next_impl(cx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Helps with writing trees with conflicts. You start by creating an instance
|
/// Helps with writing trees with conflicts. You start by creating an instance
|
||||||
/// of this type with one or more base trees. You then add overrides on top. The
|
/// of this type with one or more base trees. You then add overrides on top. The
|
||||||
/// overrides may be conflicts. Then you can write the result as a legacy tree
|
/// overrides may be conflicts. Then you can write the result as a legacy tree
|
||||||
|
|
Loading…
Reference in a new issue