diff --color-moved: unify moved block growth functions

After the last two commits pmb_advance_or_null() and pmb_advance_or_null_multi_match() differ only in the comparison they perform. Lets simplify the code by combining them into a single function. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Phillip Wood committed Dec 9, 2021 at 10:30 UTC ff046a0066f55cb730ced3f8eb54d508dcd3a4c7
1 file changed +12 -29
diff.c
+12 -29
@@ -1002,36 +1002,23 @@ static void pmb_advance_or_null(struct diff_options *o,
1002 unsigned flags = o->color_moved_ws_handling & XDF_WHITESPACE_FLAGS;
1003
1004 for (i = 0; i < pmb_nr; i++) {
1005 + int match;
1006 struct moved_entry *prev = pmb[i].match;
1007 struct moved_entry *cur = (prev && prev->next_line) ?
1008 prev->next_line : NULL;
1008 - if (cur && xdiff_compare_lines(cur->es->line, cur->es->len,
1009 - l->line, l->len,
1010 - flags)) {
1011 - pmb[i].match = cur;
1012 - } else {
1013 - pmb[i].match = NULL;
1014 - }
1015 - }
1016 -}
1009
1018 -static void pmb_advance_or_null_multi_match(struct diff_options *o,
1019 - struct emitted_diff_symbol *l,
1020 - struct moved_block *pmb,
1021 - int pmb_nr)
1022 -{
1023 - int i;
1024 -
1025 - for (i = 0; i < pmb_nr; i++) {
1026 - struct moved_entry *prev = pmb[i].match;
1027 - struct moved_entry *cur = (prev && prev->next_line) ?
1028 - prev->next_line : NULL;
1029 - if (cur && !cmp_in_block_with_wsd(cur, l, &pmb[i])) {
1030 - /* Advance to the next line */
1010 + if (o->color_moved_ws_handling &
1011 + COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
1012 + match = cur &&
1013 + !cmp_in_block_with_wsd(cur, l, &pmb[i]);
1014 + else
1015 + match = cur &&
1016 + xdiff_compare_lines(cur->es->line, cur->es->len,
1017 + l->line, l->len, flags);
1018 + if (match)
1019 pmb[i].match = cur;
1032 - } else {
1020 + else
1021 moved_block_clear(&pmb[i]);
1034 - }
1022 }
1023 }
1024
@@ -1194,11 +1181,7 @@ static void mark_color_as_moved(struct diff_options *o,
1181 continue;
1182 }
1183
1197 - if (o->color_moved_ws_handling &
1198 - COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
1199 - pmb_advance_or_null_multi_match(o, l, pmb, pmb_nr);
1200 - else
1201 - pmb_advance_or_null(o, l, pmb, pmb_nr);
1184 + pmb_advance_or_null(o, l, pmb, pmb_nr);
1185
1186 pmb_nr = shrink_potential_moved_blocks(pmb, pmb_nr);
1187