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

[PATCH 2/3] diff: move the handling of the hunk header after the changed lines

From
Markus Heidelberg <markus.heidelberg@web.de>
Date
Oct 28, 2009, 12:24 UTC
Message-ID
<1256732672-11817-3-git-send-email-markus.heidelberg@web.de>
In-Reply-To
<1256732672-11817-1-git-send-email-markus.heidelberg@web.de>

In preparation for a special case handling of colored word diff without context.

Signed-off-by: Markus Heidelberg <markus.heidelberg@web.de>
---
 diff.c |   41 +++++++++++++++++++++--------------------
 1 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/diff.c b/diff.c
index b0c7e61..067e5a0 100644
--- a/diff.c
+++ b/diff.c
@@ -771,17 +771,6 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
 		len = 1;
 	}
 
-	if (line[0] == '@') {
-		len = sane_truncate_line(ecbdata, line, len);
-		find_lno(line, ecbdata);
-		emit_line(ecbdata->file,
-			  diff_get_color(ecbdata->color_diff, DIFF_FRAGINFO),
-			  reset, line, len);
-		if (line[len-1] != '\n')
-			putc('\n', ecbdata->file);
-		return;
-	}
-
 	if (len < 1) {
 		emit_line(ecbdata->file, reset, reset, line, len);
 		return;
@@ -796,17 +785,18 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
 			diff_words_append(line, len,
 					  &ecbdata->diff_words->plus);
 			return;
+		} else if (line[0] == ' ') {
+			if (ecbdata->diff_words->minus.text.size ||
+			    ecbdata->diff_words->plus.text.size)
+				diff_words_show(ecbdata->diff_words);
+			line++;
+			len--;
+			emit_line(ecbdata->file, plain, reset, line, len);
+			return;
 		}
-		if (ecbdata->diff_words->minus.text.size ||
-		    ecbdata->diff_words->plus.text.size)
-			diff_words_show(ecbdata->diff_words);
-		line++;
-		len--;
-		emit_line(ecbdata->file, plain, reset, line, len);
-		return;
 	}
 
-	if (line[0] != '+') {
+	if (line[0] == ' ' || line[0] == '-') {
 		const char *color =
 			diff_get_color(ecbdata->color_diff,
 				       line[0] == '-' ? DIFF_FILE_OLD : DIFF_PLAIN);
@@ -814,10 +804,21 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
 		if (line[0] == ' ')
 			ecbdata->lno_in_postimage++;
 		emit_line(ecbdata->file, color, reset, line, len);
-	} else {
+		return;
+	} else if (line[0] == '+') {
 		ecbdata->lno_in_postimage++;
 		emit_add_line(reset, ecbdata, line + 1, len - 1);
+		return;
 	}
+
+	/* line[0] == '@' */
+	len = sane_truncate_line(ecbdata, line, len);
+	find_lno(line, ecbdata);
+	emit_line(ecbdata->file,
+		  diff_get_color(ecbdata->color_diff, DIFF_FRAGINFO),
+		  reset, line, len);
+	if (line[len-1] != '\n')
+		putc('\n', ecbdata->file);
 }
 
 static char *pprint_rename(const char *a, const char *b)
-- 
1.6.5.2.86.g61663
Previous: Markus HeidelbergNext: Markus Heidelberg
Message 3 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.