mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-07 21:27:06 +00:00
merged_tree: make ConflictIterator
a struct
This commit is contained in:
parent
109391f9c7
commit
7596935285
1 changed files with 18 additions and 25 deletions
|
@ -556,18 +556,15 @@ impl From<&Merge<Tree>> for ConflictsDirItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: replace by a struct
|
struct ConflictIterator {
|
||||||
enum ConflictIterator {
|
store: Arc<Store>,
|
||||||
Merge {
|
stack: Vec<ConflictsDirItem>,
|
||||||
store: Arc<Store>,
|
|
||||||
stack: Vec<ConflictsDirItem>,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConflictIterator {
|
impl ConflictIterator {
|
||||||
fn new(tree: &MergedTree) -> Self {
|
fn new(tree: &MergedTree) -> Self {
|
||||||
match tree {
|
match tree {
|
||||||
MergedTree::Merge(trees) => ConflictIterator::Merge {
|
MergedTree::Merge(trees) => ConflictIterator {
|
||||||
store: tree.store().clone(),
|
store: tree.store().clone(),
|
||||||
stack: vec![ConflictsDirItem::from(trees)],
|
stack: vec![ConflictsDirItem::from(trees)],
|
||||||
},
|
},
|
||||||
|
@ -579,27 +576,23 @@ impl Iterator for ConflictIterator {
|
||||||
type Item = (RepoPathBuf, MergedTreeValue);
|
type Item = (RepoPathBuf, MergedTreeValue);
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
match self {
|
while let Some(top) = self.stack.last_mut() {
|
||||||
ConflictIterator::Merge { store, stack } => {
|
if let Some((path, tree_values)) = top.entries.pop() {
|
||||||
while let Some(top) = stack.last_mut() {
|
// TODO: propagate errors
|
||||||
if let Some((path, tree_values)) = top.entries.pop() {
|
if let Some(trees) = tree_values.to_tree_merge(&self.store, &path).unwrap() {
|
||||||
// TODO: propagate errors
|
// If all sides are trees or missing, descend into the merged tree
|
||||||
if let Some(trees) = tree_values.to_tree_merge(store, &path).unwrap() {
|
self.stack.push(ConflictsDirItem::from(&trees));
|
||||||
// If all sides are trees or missing, descend into the merged tree
|
} else {
|
||||||
stack.push(ConflictsDirItem::from(&trees));
|
// Otherwise this is a conflict between files, trees, etc. If they could
|
||||||
} else {
|
// be automatically resolved, they should have been when the top-level
|
||||||
// Otherwise this is a conflict between files, trees, etc. If they could
|
// tree conflict was written, so we assume that they can't be.
|
||||||
// be automatically resolved, they should have been when the top-level
|
return Some((path, tree_values));
|
||||||
// tree conflict was written, so we assume that they can't be.
|
|
||||||
return Some((path, tree_values));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
stack.pop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None
|
} else {
|
||||||
|
self.stack.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue