conflicts: in materialize_merge_result(), always use adds.get(index)

I don't think this is more readable than the original code, but it gives
diff1/right1 and diff2/right2 pairs consistent names.
This commit is contained in:
Yuya Nishihara 2023-02-24 13:46:36 +09:00
parent 410be93339
commit 0b083b2ddb

View file

@ -196,17 +196,18 @@ pub fn materialize_merge_result(
output.write_all(CONFLICT_START_LINE)?;
let mut add_index = 0;
for left in &removes {
if add_index == adds.len() {
let right1 = if let Some(right1) = adds.get(add_index) {
right1
} else {
// If we have no more positive terms, emit the remaining negative
// terms as snapshots.
output.write_all(CONFLICT_MINUS_LINE)?;
output.write_all(left)?;
continue;
}
let diff1 =
Diff::for_tokenizer(&[left, &adds[add_index]], &find_line_ranges)
.hunks()
.collect_vec();
};
let diff1 = Diff::for_tokenizer(&[left, right1], &find_line_ranges)
.hunks()
.collect_vec();
// Check if the diff against the next positive term is better. Since
// we want to preserve the order of the terms, we don't match against
// any later positive terms.
@ -219,7 +220,7 @@ pub fn materialize_merge_result(
// the current positive term as a snapshot and the next
// positive term as a diff.
output.write_all(CONFLICT_PLUS_LINE)?;
output.write_all(&adds[add_index])?;
output.write_all(right1)?;
output.write_all(CONFLICT_DIFF_LINE)?;
write_diff_hunks(&diff2, output)?;
add_index += 2;