[v1,5/9] diff --color-moved-ws: fix false positives
diff mbox series

Message ID 20181116110356.12311-6-phillip.wood@talktalk.net
State New
Headers show
  • diff --color-moved-ws fixes and enhancment
Related show

Commit Message

Phillip Wood Nov. 16, 2018, 11:03 a.m. UTC
From: Phillip Wood <phillip.wood@dunelm.org.uk>

'diff --color-moved-ws=allow-indentation-change' can color lines as
moved when they are in fact different. For example in commit
1a07e59c3e ("Update messages in preparation for i18n", 2018-07-21) the

-               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

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
 diff.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff mbox series

diff --git a/diff.c b/diff.c
index 9b9811988b..53a7ab5aca 100644
--- a/diff.c
+++ b/diff.c
@@ -1104,10 +1104,10 @@  static void mark_color_as_moved(struct diff_options *o,
-		l->flags |= DIFF_SYMBOL_MOVED_LINE;
-		if (o->color_moved == COLOR_MOVED_PLAIN)
+		if (o->color_moved == COLOR_MOVED_PLAIN) {
+			l->flags |= DIFF_SYMBOL_MOVED_LINE;
+		}
 		if (o->color_moved_ws_handling &
@@ -1141,10 +1141,13 @@  static void mark_color_as_moved(struct diff_options *o,
 			block_length = 0;
-		block_length++;
+		if (pmb_nr) {
+			block_length++;
-		if (flipped_block && o->color_moved != COLOR_MOVED_BLOCKS)
+			l->flags |= DIFF_SYMBOL_MOVED_LINE;
+			if (flipped_block && o->color_moved != COLOR_MOVED_BLOCKS)
+				l->flags |= DIFF_SYMBOL_MOVED_LINE_ALT;
+		}
 	adjust_last_block(o, n, block_length);