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

Re: Showing whitespace on minus lines of diff ouput

From
Jay Soffian <jaysoffian@gmail.com>
Date
Feb 5, 2010, 02:54 UTC
Message-ID
<76718491002041854t445f0a33rf4ffe5158b9f7214@mail.gmail.com>
In-Reply-To
<76718491002041808r6fcbf88egd1e9ce4927eb36c0@mail.gmail.com>
On Thu, Feb 4, 2010 at 9:08 PM, Jay Soffian <jaysoffian@gmail.com> wrote:
> Ah, got it. I think. Patch shortly. :-)

Bah, still need help. Here's what I tried (apologizes for the gmail munging of long lines):

diff --git a/diff.c b/diff.c
index 381cc8d..17133cd 100644
--- a/diff.c
+++ b/diff.c
@@ -331,6 +331,23 @@ static int new_blank_line_at_eof(struct
emit_callback *ecbdata, const char *line
 	return ws_blank_line(line, len, ecbdata->ws_rule);
 }

+static void emit_sub_line(const char *reset,
+			  struct emit_callback *ecbdata,
+			  const char *line, int len)
+{
+	const char *ws = diff_get_color(ecbdata->color_diff, DIFF_WHITESPACE);
+	const char *set = diff_get_color(ecbdata->color_diff, DIFF_FILE_OLD);
+
+	if (!*ws)
+		emit_line_0(ecbdata->file, set, reset, '-', line, len);
+	else {
+		/* Emit just the prefix, then the rest. */
+		emit_line_0(ecbdata->file, set, reset, '-', "", 0);
+		ws_check_emit(line, len, ecbdata->ws_rule,
+			      ecbdata->file, set, reset, ws);
+	}
+}
+
 static void emit_add_line(const char *reset,
 			  struct emit_callback *ecbdata,
 			  const char *line, int len)
@@ -434,7 +451,6 @@ static void emit_rewrite_lines(struct emit_callback *ecb,
 {
 	const char *endp = NULL;
 	static const char *nneof = " No newline at end of file\n";
-	const char *old = diff_get_color(ecb->color_diff, DIFF_FILE_OLD);
 	const char *reset = diff_get_color(ecb->color_diff, DIFF_RESET);

 	while (0 < size) {
@@ -444,8 +460,7 @@ static void emit_rewrite_lines(struct emit_callback *ecb,
 		len = endp ? (endp - data + 1) : size;
 		if (prefix != '+') {
 			ecb->lno_in_preimage++;
-			emit_line_0(ecb->file, old, reset, '-',
-				    data, len);
+			emit_sub_line(reset, ecb, data, len);
 		} else {
 			ecb->lno_in_postimage++;
 			emit_add_line(reset, ecb, data, len);
@@ -862,9 +877,12 @@ static void fn_out_consume(void *priv, char
*line, unsigned long len)
 			diff_get_color(ecbdata->color_diff,
 				       line[0] == '-' ? DIFF_FILE_OLD : DIFF_PLAIN);
 		ecbdata->lno_in_preimage++;
-		if (line[0] == ' ')
+		if (line[0] == ' ') {
 			ecbdata->lno_in_postimage++;
-		emit_line(ecbdata->file, color, reset, line, len);
+			emit_line(ecbdata->file, color, reset, line, len);
+		} else {
+			emit_sub_line(reset, ecbdata, line + 1, len - 1);
+		}
 	} else {
 		ecbdata->lno_in_postimage++;
 		emit_add_line(reset, ecbdata, line + 1, len - 1);


But for reasons I don't understand this screws up some of the diff
test cases. It's emitting "index" lines where it shouldn't, and "- No
newline at end of file" instead of "\ No newline at end of file".

I guess something is post-processing the output of the emit functions
and doesn't like the change?

Help appreciated. :-)

j.
Previous: Jay SoffianNext: Junio C Hamano
Message 3 of 7 in “Showing whitespace on minus lines of diff ouput”
  1. Jay SoffianFeb 5, 2010
  2. Jay SoffianFeb 5, 2010
  3. Jay SoffianFeb 5, 2010
  4. Junio C HamanoFeb 5, 2010
  5. Jay SoffianFeb 5, 2010
  6. Junio C HamanoFeb 5, 2010
  7. Jay SoffianFeb 5, 2010

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.