Skip to content

Commit d404a3e

Browse files
committed
Merge branch 'js/maint-diff-color-words' into maint
* js/maint-diff-color-words: diff --color-words: bit of clean-up diff --color-words -U0: fix the location of hunk headers t4034-diff-words: add a test for word diff without context Conflicts: diff.c
2 parents ee16339 + 76fd282 commit d404a3e

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

diff.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -685,14 +685,18 @@ static void diff_words_show(struct diff_words_data *diff_words)
685685
diff_words->minus.text.size = diff_words->plus.text.size = 0;
686686
}
687687

688+
/* In "color-words" mode, show word-diff of words accumulated in the buffer */
689+
static void diff_words_flush(struct emit_callback *ecbdata)
690+
{
691+
if (ecbdata->diff_words->minus.text.size ||
692+
ecbdata->diff_words->plus.text.size)
693+
diff_words_show(ecbdata->diff_words);
694+
}
695+
688696
static void free_diff_words_data(struct emit_callback *ecbdata)
689697
{
690698
if (ecbdata->diff_words) {
691-
/* flush buffers */
692-
if (ecbdata->diff_words->minus.text.size ||
693-
ecbdata->diff_words->plus.text.size)
694-
diff_words_show(ecbdata->diff_words);
695-
699+
diff_words_flush(ecbdata);
696700
free (ecbdata->diff_words->minus.text.ptr);
697701
free (ecbdata->diff_words->minus.orig);
698702
free (ecbdata->diff_words->plus.text.ptr);
@@ -772,6 +776,8 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
772776
}
773777

774778
if (line[0] == '@') {
779+
if (ecbdata->diff_words)
780+
diff_words_flush(ecbdata);
775781
len = sane_truncate_line(ecbdata, line, len);
776782
find_lno(line, ecbdata);
777783
emit_line(ecbdata->file,
@@ -797,9 +803,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
797803
&ecbdata->diff_words->plus);
798804
return;
799805
}
800-
if (ecbdata->diff_words->minus.text.size ||
801-
ecbdata->diff_words->plus.text.size)
802-
diff_words_show(ecbdata->diff_words);
806+
diff_words_flush(ecbdata);
803807
line++;
804808
len--;
805809
emit_line(ecbdata->file, plain, reset, line, len);

t/t4034-diff-words.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,26 @@ test_expect_success 'word diff with runs of whitespace' '
6363
6464
'
6565

66+
cat > expect <<\EOF
67+
<WHITE>diff --git a/pre b/post<RESET>
68+
<WHITE>index 330b04f..5ed8eff 100644<RESET>
69+
<WHITE>--- a/pre<RESET>
70+
<WHITE>+++ b/post<RESET>
71+
<BROWN>@@ -1 +1 @@<RESET>
72+
<RED>h(4)<RESET><GREEN>h(4),hh[44]<RESET>
73+
<BROWN>@@ -3,0 +4,4 @@ a = b + c<RESET>
74+
75+
<GREEN>aa = a<RESET>
76+
77+
<GREEN>aeff = aeff * ( aaa )<RESET>
78+
EOF
79+
80+
test_expect_success 'word diff without context' '
81+
82+
word_diff --color-words --unified=0
83+
84+
'
85+
6686
cat > expect <<\EOF
6787
<WHITE>diff --git a/pre b/post<RESET>
6888
<WHITE>index 330b04f..5ed8eff 100644<RESET>

0 commit comments

Comments
 (0)