Skip to content

Commit ff046a0

Browse files
phillipwoodgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 08fba10 commit ff046a0

File tree

1 file changed

+12
-29
lines changed

1 file changed

+12
-29
lines changed

diff.c

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,36 +1002,23 @@ static void pmb_advance_or_null(struct diff_options *o,
10021002
unsigned flags = o->color_moved_ws_handling & XDF_WHITESPACE_FLAGS;
10031003

10041004
for (i = 0; i < pmb_nr; i++) {
1005+
int match;
10051006
struct moved_entry *prev = pmb[i].match;
10061007
struct moved_entry *cur = (prev && prev->next_line) ?
10071008
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-
}
10171009

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)
10311019
pmb[i].match = cur;
1032-
} else {
1020+
else
10331021
moved_block_clear(&pmb[i]);
1034-
}
10351022
}
10361023
}
10371024

@@ -1194,11 +1181,7 @@ static void mark_color_as_moved(struct diff_options *o,
11941181
continue;
11951182
}
11961183

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);
12021185

12031186
pmb_nr = shrink_potential_moved_blocks(pmb, pmb_nr);
12041187

0 commit comments

Comments
 (0)