Skip to content

Commit 2034b47

Browse files
phillipwoodgitster
authored andcommitted
diff --color-moved-ws: fix false positives
'diff --color-moved-ws=allow-indentation-change' can color lines as moved when they are in fact different. For example in commit 1a07e59 ("Update messages in preparation for i18n", 2018-07-21) the lines - die (_("must end with a color")); + die(_("must end with a color")); are colored as moved even though they are different. This is because if there is a fuzzy match for the first line of a potential moved block the line is marked as moved before the potential match is checked to see if it actually matches. The fix is to delay marking the line as moved until after we have checked that there really is at least one matching potential moved block. Note that the test modified in the last commit still fails because adding an unmoved line between two moved blocks that are already separated by unmoved lines changes the color of the block following the addition. This should not be the case and will be fixed in the next commit. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 10acc5f commit 2034b47

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

diff.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,10 +1106,10 @@ static void mark_color_as_moved(struct diff_options *o,
11061106
continue;
11071107
}
11081108

1109-
l->flags |= DIFF_SYMBOL_MOVED_LINE;
1110-
1111-
if (o->color_moved == COLOR_MOVED_PLAIN)
1109+
if (o->color_moved == COLOR_MOVED_PLAIN) {
1110+
l->flags |= DIFF_SYMBOL_MOVED_LINE;
11121111
continue;
1112+
}
11131113

11141114
if (o->color_moved_ws_handling &
11151115
COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
@@ -1143,10 +1143,13 @@ static void mark_color_as_moved(struct diff_options *o,
11431143
block_length = 0;
11441144
}
11451145

1146-
block_length++;
1146+
if (pmb_nr) {
1147+
block_length++;
11471148

1148-
if (flipped_block && o->color_moved != COLOR_MOVED_BLOCKS)
1149-
l->flags |= DIFF_SYMBOL_MOVED_LINE_ALT;
1149+
l->flags |= DIFF_SYMBOL_MOVED_LINE;
1150+
if (flipped_block && o->color_moved != COLOR_MOVED_BLOCKS)
1151+
l->flags |= DIFF_SYMBOL_MOVED_LINE_ALT;
1152+
}
11501153
}
11511154
adjust_last_block(o, n, block_length);
11521155

0 commit comments

Comments
 (0)