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

Re: question: how to ignore extral CR when diff dos format files with 'color=auto'

From
Ggoooguo <erwangg@fortemedia.com.cn>
Date
Aug 28, 2008, 01:39 UTC
Message-ID
<1219887555724-788498.post@n2.nabble.com>
In-Reply-To
<1219728743111-783231.post@n2.nabble.com>

git v1.6.0 still didn't work, neither v1.5.6.4. (however,v1.5.5 works on mingwin)

I checked the source code of v1.6.0, and I found emit_line didn't check whether there is a cr at eol.

I have fixed it.
>From dae20e25960c73bd7ccc0939fe096bb68a009fb5 Mon Sep 17 00:00:00 2001
From: erwangg <erwangg@fortemedia.com.cn>
Date: Wed, 27 Aug 2008 12:22:43 +0800
Subject: [PATCH] ingore cr at eol when diff with color=auto
---
 diff.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/diff.c b/diff.c
index 18fa7a7..846a9af 100644
--- a/diff.c
+++ b/diff.c
@@ -517,9 +517,16 @@ static void emit_line(FILE *file, const char *set,
const char *reset, const char
 	if (has_trailing_newline)
 		len--;
 
+	int has_trailing_return = (len > 0 && line[len-1] == '\r');
+	if (has_trailing_return)
+        len--;
+
 	fputs(set, file);
 	fwrite(line, len, 1, file);
 	fputs(reset, file);
+
+    if (has_trailing_return)
+        fputc('\r', file);
 	if (has_trailing_newline)
 		fputc('\n', file);
 }
@@ -535,7 +542,7 @@ static void emit_add_line(const char *reset, struct
emit_callback *ecbdata, cons
 		/* Emit just the prefix, then the rest. */
 		emit_line(ecbdata->file, set, reset, line, ecbdata->nparents);
 		ws_check_emit(line + ecbdata->nparents,
-			      len - ecbdata->nparents, ecbdata->ws_rule,
+			      len - ecbdata->nparents, ecbdata->ws_rule|WS_CR_AT_EOL,
 			      ecbdata->file, set, reset, ws);
 	}
 }
-- 
1.6.0.GIT




-- 
View this message in context: http://n2.nabble.com/question%3A-how-to-ignore-extral-CR-when-diff-dos-format-files-with-%27color%3Dauto%27-tp783231p788498.html
Sent from the git mailing list archive at Nabble.com.
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 6 in “question: how to ignore extral CR when diff dos format files with 'color=auto'”
  1. goooguoAug 26, 2008
  2. goooguoAug 27, 2008
  3. Junio C HamanoAug 27, 2008
  4. goooguoAug 28, 2008
  5. Junio C HamanoAug 28, 2008
  6. Junio C HamanoAug 28, 2008

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.