git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: goooguo <erwangg@fortemedia.com.cn>
Cc: 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 19:47:31 -0700	[thread overview]
Message-ID: <7v7ia1kg8s.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <7vbpzdkgy9.fsf@gitster.siamese.dyndns.org> (Junio C. Hamano's message of "Wed, 27 Aug 2008 19:32:14 -0700")

Junio C Hamano <gitster@pobox.com> writes:

> ...  I suspect
> that combined-diff output routines have the same issue that you need to
> fix the same way, but I didn't look.

Now I looked.  The combine-diff part should look like this, I think.

diff --git i/combine-diff.c w/combine-diff.c
index 534be38..de83c69 100644
--- i/combine-diff.c
+++ w/combine-diff.c
@@ -496,6 +496,18 @@ static int hunk_comment_line(const char *bol)
 	return (isalpha(ch) || ch == '_' || ch == '$');
 }
 
+static void show_line_to_eol(const char *line, int len, const char *reset)
+{
+	int saw_cr_at_eol = 0;
+	if (len < 0)
+		len = strlen(line);
+	saw_cr_at_eol = (len && line[len-1] == '\r');
+
+	printf("%.*s%s%s\n", len - saw_cr_at_eol, line,
+	       reset,
+	       saw_cr_at_eol ? "\r" : "");
+}
+
 static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
 		       int use_color)
 {
@@ -589,7 +601,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
 					else
 						putchar(' ');
 				}
-				printf("%s%s\n", ll->line, c_reset);
+				show_line_to_eol(ll->line, -1, c_reset);
 				ll = ll->next;
 			}
 			if (cnt < lno)
@@ -613,7 +625,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
 					putchar(' ');
 				p_mask <<= 1;
 			}
-			printf("%.*s%s\n", sl->len, sl->bol, c_reset);
+			show_line_to_eol(sl->bol, sl->len, c_reset);
 		}
 	}
 }

      reply	other threads:[~2008-08-28  2:48 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
2008-08-28  2:32   ` Junio C Hamano
2008-08-28  2:47     ` Junio C Hamano [this message]

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=7v7ia1kg8s.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=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).