refs: use swap_remove() in non-trivial merge of ref targets

I'm going to add a Merge method that removes negative/positive terms pair, and
swap_remove() is the easiest option. The order of the conflicted ref targets
doesn't matter.
This commit is contained in:
Yuya Nishihara 2023-11-06 17:18:38 +09:00
parent e4b0e629c9
commit 93601541cb
2 changed files with 4 additions and 4 deletions

View file

@ -133,8 +133,8 @@ fn merge_ref_targets_non_trivial(
) -> Merge<Option<CommitId>> {
let (mut removes, mut adds) = conflict.take();
while let Some((remove_index, add_index)) = find_pair_to_remove(index, &removes, &adds) {
removes.remove(remove_index);
adds.remove(add_index);
removes.swap_remove(remove_index);
adds.swap_remove(add_index);
}
Merge::new(removes, adds)
}

View file

@ -196,7 +196,7 @@ fn test_merge_ref_targets() {
// TODO: "removes" should have commit 2, just like it does in the next test case
RefTarget::from_legacy_form(
[commit1.id().clone()],
[commit4.id().clone(), commit3.id().clone()]
[commit3.id().clone(), commit4.id().clone()]
)
);
@ -213,7 +213,7 @@ fn test_merge_ref_targets() {
),
RefTarget::from_legacy_form(
[commit2.id().clone()],
[commit3.id().clone(), commit4.id().clone()]
[commit4.id().clone(), commit3.id().clone()]
)
);