mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-16 00:56:23 +00:00
refs: directly assign ancestor (index, id) pair in find_pair_to_remove()
This commit is contained in:
parent
9140e5b686
commit
fe3be99f0d
1 changed files with 7 additions and 14 deletions
|
@ -77,26 +77,19 @@ fn find_pair_to_remove(
|
||||||
// "adds" is an ancestor of the other, then pick the descendant.
|
// "adds" is an ancestor of the other, then pick the descendant.
|
||||||
for (add_index1, add1) in adds.iter().enumerate() {
|
for (add_index1, add1) in adds.iter().enumerate() {
|
||||||
for (add_index2, add2) in adds.iter().enumerate().skip(add_index1 + 1) {
|
for (add_index2, add2) in adds.iter().enumerate().skip(add_index1 + 1) {
|
||||||
let first_add_is_ancestor;
|
let (add_index, add) = if add1 == add2 || index.is_ancestor(add1, add2) {
|
||||||
if add1 == add2 || index.is_ancestor(add1, add2) {
|
(add_index1, add1)
|
||||||
first_add_is_ancestor = true;
|
|
||||||
} else if index.is_ancestor(add2, add1) {
|
} else if index.is_ancestor(add2, add1) {
|
||||||
first_add_is_ancestor = false;
|
(add_index2, add2)
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
};
|
||||||
if removes.is_empty() {
|
if removes.is_empty() {
|
||||||
if first_add_is_ancestor {
|
return Some((None, add_index));
|
||||||
return Some((None, add_index1));
|
|
||||||
} else {
|
|
||||||
return Some((None, add_index2));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (remove_index, remove) in removes.iter().enumerate() {
|
for (remove_index, remove) in removes.iter().enumerate() {
|
||||||
if first_add_is_ancestor && index.is_ancestor(remove, add1) {
|
if index.is_ancestor(remove, add) {
|
||||||
return Some((Some(remove_index), add_index1));
|
return Some((Some(remove_index), add_index));
|
||||||
} else if !first_add_is_ancestor && index.is_ancestor(remove, add2) {
|
|
||||||
return Some((Some(remove_index), add_index2));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue