]> git.ipfire.org Git - thirdparty/git.git/commit - t/t4015-diff-whitespace.sh
diff --color-moved=zebra: fix alternate coloring
authorPhillip Wood <phillip.wood@dunelm.org.uk>
Thu, 9 Dec 2021 10:29:59 +0000 (10:29 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Dec 2021 21:24:05 +0000 (13:24 -0800)
commiteb315457f65e1d6b77cde3933b6a175e649fb34b
treedfaff824bdeb5192ca86e47f217bf699b0aedd2f
parent0990658bf85a0763ffd628b1dd57a33c27b25450
diff --color-moved=zebra: fix alternate coloring

b0a2ba4776 ("diff --color-moved=zebra: be stricter with color
alternation", 2018-11-23) sought to avoid using the alternate colors
unless there are two adjacent moved blocks of the same
sign. Unfortunately it contains two bugs that prevented it from fixing
the problem properly. Firstly `last_symbol` is reset at the start of
each iteration of the loop losing the symbol of the last line and
secondly when deciding whether to use the alternate color it should be
checking if the current line is the same sign of the last line, not a
different sign. The combination of the two errors means that we still
use the alternate color when we should do but we also use it when we
shouldn't. This is most noticable when using
--color-moved-ws=allow-indentation-change with hunks like

-this line gets indented
+    this line gets indented

where the post image is colored with newMovedAlternate rather than
newMoved. While this does not matter much, the next commit will change
the coloring to be correct in this case, so lets fix the bug here to
make it clear why the output is changing and add a regression test.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff.c
t/t4015-diff-whitespace.sh