forked from mirrors/jj
TreeDiffIterator: simplify conditions by separating trees from non-trees
This commit is contained in:
parent
29fe1e9737
commit
ef6e5c7ec2
1 changed files with 45 additions and 52 deletions
|
@ -166,62 +166,55 @@ impl Iterator for TreeDiffIterator {
|
||||||
|
|
||||||
// Note: whenever we say "file" below, it may also be a symlink or a conflict.
|
// Note: whenever we say "file" below, it may also be a symlink or a conflict.
|
||||||
if let Some((name, before, after)) = self.entry_iterator.next() {
|
if let Some((name, before, after)) = self.entry_iterator.next() {
|
||||||
|
let tree_before = matches!(before, Some(TreeValue::Tree(_)));
|
||||||
|
let tree_after = matches!(after, Some(TreeValue::Tree(_)));
|
||||||
|
if tree_before || tree_after {
|
||||||
|
let subdir = RepoPathComponent::from(name.as_str());
|
||||||
|
let subdir_path = self.dir.join(&subdir);
|
||||||
|
let before_tree = match before {
|
||||||
|
Some(TreeValue::Tree(id_before)) => {
|
||||||
|
self.tree1.known_sub_tree(&subdir, &id_before)
|
||||||
|
}
|
||||||
|
_ => Tree::null(self.tree1.store().clone(), subdir_path.clone()),
|
||||||
|
};
|
||||||
|
let after_tree = match after {
|
||||||
|
Some(TreeValue::Tree(id_after)) => {
|
||||||
|
self.tree2.known_sub_tree(&subdir, &id_after)
|
||||||
|
}
|
||||||
|
_ => Tree::null(self.tree2.store().clone(), subdir_path.clone()),
|
||||||
|
};
|
||||||
|
self.subdir_iterator = Some(Box::new(TreeDiffIterator::new(
|
||||||
|
subdir_path,
|
||||||
|
before_tree,
|
||||||
|
after_tree,
|
||||||
|
)));
|
||||||
|
}
|
||||||
let file_path = self.dir.join(&RepoPathComponent::from(name.as_str()));
|
let file_path = self.dir.join(&RepoPathComponent::from(name.as_str()));
|
||||||
let subdir = RepoPathComponent::from(name.as_str());
|
if !tree_before && tree_after {
|
||||||
let subdir_path = self.dir.join(&subdir);
|
if let Some(file_before) = before {
|
||||||
// TODO: simplify this mess
|
|
||||||
match (before, after) {
|
|
||||||
(Some(TreeValue::Tree(id_before)), Some(TreeValue::Tree(id_after))) => {
|
|
||||||
self.subdir_iterator = Some(Box::new(TreeDiffIterator::new(
|
|
||||||
subdir_path,
|
|
||||||
self.tree1.known_sub_tree(&subdir, &id_before),
|
|
||||||
self.tree2.known_sub_tree(&subdir, &id_after),
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
(Some(TreeValue::Tree(id_before)), Some(file_after)) => {
|
|
||||||
self.subdir_iterator = Some(Box::new(TreeDiffIterator::new(
|
|
||||||
subdir_path.clone(),
|
|
||||||
self.tree1.known_sub_tree(&subdir, &id_before),
|
|
||||||
Tree::null(self.tree2.store().clone(), subdir_path),
|
|
||||||
)));
|
|
||||||
self.added_file = Some((file_path, file_after.clone()));
|
|
||||||
}
|
|
||||||
(Some(file_before), Some(TreeValue::Tree(id_after))) => {
|
|
||||||
self.subdir_iterator = Some(Box::new(TreeDiffIterator::new(
|
|
||||||
subdir_path.clone(),
|
|
||||||
Tree::null(self.tree1.store().clone(), subdir_path),
|
|
||||||
self.tree2.known_sub_tree(&subdir, &id_after),
|
|
||||||
)));
|
|
||||||
return Some((file_path, Diff::Removed(file_before.clone())));
|
return Some((file_path, Diff::Removed(file_before.clone())));
|
||||||
}
|
}
|
||||||
(Some(file_before), Some(file_after)) => {
|
} else if tree_before && !tree_after {
|
||||||
return Some((
|
if let Some(file_after) = after {
|
||||||
file_path,
|
self.added_file = Some((file_path, file_after.clone()));
|
||||||
Diff::Modified(file_before.clone(), file_after.clone()),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
(None, Some(TreeValue::Tree(id_after))) => {
|
} else if !tree_before && !tree_after {
|
||||||
self.subdir_iterator = Some(Box::new(TreeDiffIterator::new(
|
match (before, after) {
|
||||||
subdir_path.clone(),
|
(Some(file_before), Some(file_after)) => {
|
||||||
Tree::null(self.tree1.store().clone(), subdir_path),
|
return Some((
|
||||||
self.tree2.known_sub_tree(&subdir, &id_after),
|
file_path,
|
||||||
)));
|
Diff::Modified(file_before.clone(), file_after.clone()),
|
||||||
}
|
));
|
||||||
(None, Some(value_after)) => {
|
}
|
||||||
return Some((file_path, Diff::Added(value_after.clone())));
|
(None, Some(file_after)) => {
|
||||||
}
|
return Some((file_path, Diff::Added(file_after.clone())));
|
||||||
(Some(TreeValue::Tree(id_before)), None) => {
|
}
|
||||||
self.subdir_iterator = Some(Box::new(TreeDiffIterator::new(
|
(Some(file_before), None) => {
|
||||||
subdir_path.clone(),
|
return Some((file_path, Diff::Removed(file_before.clone())));
|
||||||
self.tree1.known_sub_tree(&subdir, &id_before),
|
}
|
||||||
Tree::null(self.tree2.store().clone(), subdir_path),
|
(None, None) => {
|
||||||
)));
|
panic!("unexpected diff")
|
||||||
}
|
}
|
||||||
(Some(value_before), None) => {
|
|
||||||
return Some((file_path, Diff::Removed(value_before.clone())));
|
|
||||||
}
|
|
||||||
(None, None) => {
|
|
||||||
panic!("unexpected diff")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue