git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] diff --color-words -U0: fix the location of hunk headers

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Oct 29, 2009, 10:45 UTC
Message-ID
<alpine.DEB.1.00.0910291144170.3687@felix-maschine>
In-Reply-To
<1256732672-11817-4-git-send-email-markus.heidelberg@web.de>

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 <johannes.schindelin@gmx.de>
---
	I would strongly prefer this fix instead of your 2/3 and 3/3.
 diff.c                |    6 ++++++
 t/t4034-diff-words.sh |    2 +-
 2 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/diff.c b/diff.c
index 51b5dbb..4eafaf5 100644
--- a/diff.c
+++ b/diff.c
@@ -656,6 +656,12 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
 	for (i = 0; i < len && line[i] == '@'; i++)
 		;
 	if (2 <= i && i < len && line[i] == ' ') {
+		/* flush --color-words even for --unified=0 */
+		if (ecbdata->diff_words &&
+		    (ecbdata->diff_words->minus.text.size ||
+		     ecbdata->diff_words->plus.text.size))
+			diff_words_show(ecbdata->diff_words);
+
 		ecbdata->nparents = i - 1;
 		len = sane_truncate_line(ecbdata, line, len);
 		emit_line(ecbdata->file,
diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
index 82240cf..21db6e9 100755
--- a/t/t4034-diff-words.sh
+++ b/t/t4034-diff-words.sh
@@ -77,7 +77,7 @@ cat > expect <<\EOF
 <GREEN>aeff = aeff * ( aaa )<RESET>
 EOF
 
-test_expect_failure 'word diff without context' '
+test_expect_success 'word diff without context' '
 
 	word_diff --color-words --unified=0
 
-- 
1.6.4.GIT
Previous: Markus HeidelbergNext: Markus Heidelberg
Message 5 of 14 in “fix "git diff --color-words -U0"”
  1. 0/3 fix "git diff --color-words -U0"Markus Heidelberg, Oct 28, 2009
  2. 1/3 t4034-diff-words: add a test for word diff without contextMarkus Heidelberg, Oct 28, 2009
  3. 2/3 diff: move the handling of the hunk header after the changed linesMarkus Heidelberg, Oct 28, 2009
  4. 3/3 diff: fix the location of hunk headers for "git diff --color-words -U0"Markus Heidelberg, Oct 28, 2009
  5. diff --color-words -U0: fix the location of hunk headersJohannes Schindelin, Oct 29, 2009
  6. Markus HeidelbergOct 29, 2009
  7. Johannes SchindelinOct 29, 2009
  8. Markus HeidelbergOct 29, 2009
  9. Junio C HamanoOct 30, 2009
  10. Johannes SchindelinOct 30, 2009
  11. Junio C HamanoOct 30, 2009
  12. Johannes SchindelinOct 31, 2009
  13. Junio C HamanoOct 28, 2009
  14. Markus HeidelbergOct 28, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.