Skip to content

Commit a4ca146

Browse files
dschogitster
authored andcommitted
diff --color-words -U0: fix the location of hunk headers
Colored word diff without context lines firstly printed all the hunk headers among each other and then printed the diff. This was due to the code relying on getting at least one context line at the end of each hunk, where the colored words would be flushed (it is done that way to be able to ignore rewrapped lines). Noticed by Markus Heidelberg. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 168eff3 commit a4ca146

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

diff.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,12 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
656656
for (i = 0; i < len && line[i] == '@'; i++)
657657
;
658658
if (2 <= i && i < len && line[i] == ' ') {
659+
/* flush --color-words even for --unified=0 */
660+
if (ecbdata->diff_words &&
661+
(ecbdata->diff_words->minus.text.size ||
662+
ecbdata->diff_words->plus.text.size))
663+
diff_words_show(ecbdata->diff_words);
664+
659665
ecbdata->nparents = i - 1;
660666
len = sane_truncate_line(ecbdata, line, len);
661667
emit_line(ecbdata->file,

t/t4034-diff-words.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ cat > expect <<\EOF
7777
<GREEN>aeff = aeff * ( aaa )<RESET>
7878
EOF
7979

80-
test_expect_failure 'word diff without context' '
80+
test_expect_success 'word diff without context' '
8181
8282
word_diff --color-words --unified=0
8383

0 commit comments

Comments
 (0)