Skip to content

Commit

Permalink
merged_tree: drop legacy tree handling from ConflictsDirItem constructor
Browse files Browse the repository at this point in the history
No callers pass in a legacy tree.
  • Loading branch information
yuja committed Nov 20, 2023
1 parent 4ad3db2 commit 16620e0
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions lib/src/merged_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,27 +614,16 @@ struct ConflictsDirItem {
entries: Vec<(RepoPath, MergedTreeValue)>,
}

impl From<&MergedTree> for ConflictsDirItem {
fn from(merged_tree: &MergedTree) -> Self {
let dir = merged_tree.dir();

let basename_iter: Box<dyn Iterator<Item = &RepoPathComponent>> = match merged_tree {
MergedTree::Legacy(tree) => Box::new(
tree.entries_non_recursive()
.filter(|entry| matches!(entry.value(), &TreeValue::Conflict(_)))
.map(|entry| entry.name()),
),
MergedTree::Merge(trees) => {
if trees.is_resolved() {
Box::new(iter::empty())
} else {
Box::new(all_tree_basenames(trees))
}
}
};
impl From<&Merge<Tree>> for ConflictsDirItem {
fn from(trees: &Merge<Tree>) -> Self {
let dir = trees.first().dir();
if trees.is_resolved() {
return ConflictsDirItem { entries: vec![] };
}

let mut entries = vec![];
for basename in basename_iter {
match merged_tree.value(basename) {
for basename in all_tree_basenames(trees) {
match trees_value(trees, basename) {
MergedTreeVal::Resolved(_) => {}
MergedTreeVal::Conflict(tree_values) => {
entries.push((dir.join(basename), tree_values));
Expand Down Expand Up @@ -664,9 +653,9 @@ impl ConflictIterator {
store: tree.store().clone(),
conflicts_iter: tree.conflicts().into_iter(),
},
MergedTree::Merge(_) => ConflictIterator::Merge {
MergedTree::Merge(trees) => ConflictIterator::Merge {
store: tree.store().clone(),
stack: vec![ConflictsDirItem::from(tree)],
stack: vec![ConflictsDirItem::from(trees)],
},
}
}
Expand Down Expand Up @@ -695,7 +684,7 @@ impl Iterator for ConflictIterator {
// TODO: propagate errors
if let Some(trees) = tree_values.to_tree_merge(store, &path).unwrap() {
// If all sides are trees or missing, descend into the merged tree
stack.push(ConflictsDirItem::from(&MergedTree::Merge(trees)));
stack.push(ConflictsDirItem::from(&trees));
} else {
// Otherwise this is a conflict between files, trees, etc. If they could
// be automatically resolved, they should have been when the top-level
Expand Down

0 comments on commit 16620e0

Please sign in to comment.