git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: goooguo <erwangg@fortemedia.com.cn>
To: git@vger.kernel.org
Subject: Re: question: how to ignore extral CR when diff dos format files with 'color=auto'
Date: Wed, 27 Aug 2008 18:39:15 -0700 (PDT)	[thread overview]
Message-ID: <1219887555724-788498.post@n2.nabble.com> (raw)
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.

  parent reply	other threads:[~2008-08-28  1:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-26  5:32 question: how to ignore extral CR when diff dos format files with 'color=auto' goooguo
2008-08-27  4:27 ` goooguo
2008-08-27  4:54 ` Junio C Hamano
2008-08-28  1:39 ` goooguo [this message]
2008-08-28  2:32   ` Junio C Hamano
2008-08-28  2:47     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1219887555724-788498.post@n2.nabble.com \
    --to=erwangg@fortemedia.com.cn \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).