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
This commit is contained in:
commit
d404a3e1a5
16
diff.c
16
diff.c
@ -685,14 +685,18 @@ static void diff_words_show(struct diff_words_data *diff_words)
|
|||||||
diff_words->minus.text.size = diff_words->plus.text.size = 0;
|
diff_words->minus.text.size = diff_words->plus.text.size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_diff_words_data(struct emit_callback *ecbdata)
|
/* In "color-words" mode, show word-diff of words accumulated in the buffer */
|
||||||
|
static void diff_words_flush(struct emit_callback *ecbdata)
|
||||||
{
|
{
|
||||||
if (ecbdata->diff_words) {
|
|
||||||
/* flush buffers */
|
|
||||||
if (ecbdata->diff_words->minus.text.size ||
|
if (ecbdata->diff_words->minus.text.size ||
|
||||||
ecbdata->diff_words->plus.text.size)
|
ecbdata->diff_words->plus.text.size)
|
||||||
diff_words_show(ecbdata->diff_words);
|
diff_words_show(ecbdata->diff_words);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void free_diff_words_data(struct emit_callback *ecbdata)
|
||||||
|
{
|
||||||
|
if (ecbdata->diff_words) {
|
||||||
|
diff_words_flush(ecbdata);
|
||||||
free (ecbdata->diff_words->minus.text.ptr);
|
free (ecbdata->diff_words->minus.text.ptr);
|
||||||
free (ecbdata->diff_words->minus.orig);
|
free (ecbdata->diff_words->minus.orig);
|
||||||
free (ecbdata->diff_words->plus.text.ptr);
|
free (ecbdata->diff_words->plus.text.ptr);
|
||||||
@ -772,6 +776,8 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (line[0] == '@') {
|
if (line[0] == '@') {
|
||||||
|
if (ecbdata->diff_words)
|
||||||
|
diff_words_flush(ecbdata);
|
||||||
len = sane_truncate_line(ecbdata, line, len);
|
len = sane_truncate_line(ecbdata, line, len);
|
||||||
find_lno(line, ecbdata);
|
find_lno(line, ecbdata);
|
||||||
emit_line(ecbdata->file,
|
emit_line(ecbdata->file,
|
||||||
@ -797,9 +803,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
|
|||||||
&ecbdata->diff_words->plus);
|
&ecbdata->diff_words->plus);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ecbdata->diff_words->minus.text.size ||
|
diff_words_flush(ecbdata);
|
||||||
ecbdata->diff_words->plus.text.size)
|
|
||||||
diff_words_show(ecbdata->diff_words);
|
|
||||||
line++;
|
line++;
|
||||||
len--;
|
len--;
|
||||||
emit_line(ecbdata->file, plain, reset, line, len);
|
emit_line(ecbdata->file, plain, reset, line, len);
|
||||||
|
@ -63,6 +63,26 @@ test_expect_success 'word diff with runs of whitespace' '
|
|||||||
|
|
||||||
'
|
'
|
||||||
|
|
||||||
|
cat > expect <<\EOF
|
||||||
|
<WHITE>diff --git a/pre b/post<RESET>
|
||||||
|
<WHITE>index 330b04f..5ed8eff 100644<RESET>
|
||||||
|
<WHITE>--- a/pre<RESET>
|
||||||
|
<WHITE>+++ b/post<RESET>
|
||||||
|
<BROWN>@@ -1 +1 @@<RESET>
|
||||||
|
<RED>h(4)<RESET><GREEN>h(4),hh[44]<RESET>
|
||||||
|
<BROWN>@@ -3,0 +4,4 @@ a = b + c<RESET>
|
||||||
|
|
||||||
|
<GREEN>aa = a<RESET>
|
||||||
|
|
||||||
|
<GREEN>aeff = aeff * ( aaa )<RESET>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_expect_success 'word diff without context' '
|
||||||
|
|
||||||
|
word_diff --color-words --unified=0
|
||||||
|
|
||||||
|
'
|
||||||
|
|
||||||
cat > expect <<\EOF
|
cat > expect <<\EOF
|
||||||
<WHITE>diff --git a/pre b/post<RESET>
|
<WHITE>diff --git a/pre b/post<RESET>
|
||||||
<WHITE>index 330b04f..5ed8eff 100644<RESET>
|
<WHITE>index 330b04f..5ed8eff 100644<RESET>
|
||||||
|
Loading…
Reference in New Issue
Block a user