summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2021-12-09 10:29:59 +0000
committerJunio C Hamano <gitster@pobox.com>2021-12-09 13:24:05 -0800
commiteb315457f65e1d6b77cde3933b6a175e649fb34b (patch)
treedfaff824bdeb5192ca86e47f217bf699b0aedd2f /diff.c
parent0990658bf85a0763ffd628b1dd57a33c27b25450 (diff)
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>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/diff.c b/diff.c
index 1e1b5127d1..53f0df7532 100644
--- a/diff.c
+++ b/diff.c
@@ -1176,6 +1176,7 @@ static void mark_color_as_moved(struct diff_options *o,
struct moved_block *pmb = NULL; /* potentially moved blocks */
int pmb_nr = 0, pmb_alloc = 0;
int n, flipped_block = 0, block_length = 0;
+ enum diff_symbol last_symbol = 0;
for (n = 0; n < o->emitted_symbols->nr; n++) {
@@ -1183,7 +1184,6 @@ static void mark_color_as_moved(struct diff_options *o,
struct moved_entry *key;
struct moved_entry *match = NULL;
struct emitted_diff_symbol *l = &o->emitted_symbols->buf[n];
- enum diff_symbol last_symbol = 0;
switch (l->s) {
case DIFF_SYMBOL_PLUS:
@@ -1251,7 +1251,7 @@ static void mark_color_as_moved(struct diff_options *o,
&pmb, &pmb_alloc,
&pmb_nr);
- if (contiguous && pmb_nr && last_symbol != l->s)
+ if (contiguous && pmb_nr && last_symbol == l->s)
flipped_block = (flipped_block + 1) % 2;
else
flipped_block = 0;