From: "SZEDER Gábor" <szeder@ira.uka.de>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "SZEDER Gábor" <szeder@ira.uka.de>
Subject: [PATCH] diff: reset color before printing newline
Date: Tue, 17 Jun 2008 00:00:02 +0200 [thread overview]
Message-ID: <1213653602-31307-1-git-send-email-szeder@ira.uka.de> (raw)
It worked that way since commit 50f575fc (Tweak diff colors,
2006-06-22), but commit c1795bb0 (Unify whitespace checking, 2007-12-13)
changed it. This patch restores the old behaviour.
Besides Linus' arguments in the log message of 50f575fc, resetting color
before printing newline is also important to keep 'git add --patch'
happy. If the last line(s) of a file are removed, then that hunk will
end with a colored line. However, if the newline comes before the color
reset, then the diff output will have an additional line at the end
containing only the reset sequence. This causes trouble in
git-add--interactive.perl's parse_diff function, because @colored will
have one more element than @diff, and that last element will contain the
color reset. The elements of these arrays will then be copied to @hunk,
but only as many as the number of elements in @diff. As a result the
last color reset is lost and all subsequent terminal output will be
printed in color.
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
I'm not sure about putting a newline unconditionally at the end of the
line, but this was the status quo before c1795bb0.
diff.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/diff.c b/diff.c
index 62fdc54..f23657b 100644
--- a/diff.c
+++ b/diff.c
@@ -514,9 +514,13 @@ const char *diff_get_color(int diff_use_color, enum color_diff ix)
static void emit_line(FILE *file, const char *set, const char *reset, const char *line, int len)
{
+ if (len > 0 && line[len-1] == '\n')
+ len--;
+
fputs(set, file);
fwrite(line, len, 1, file);
fputs(reset, file);
+ fputc('\n', file);
}
static void emit_add_line(const char *reset, struct emit_callback *ecbdata, const char *line, int len)
--
1.5.6.rc2.55.g9b8c
next reply other threads:[~2008-06-16 22:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-16 22:00 SZEDER Gábor [this message]
2008-06-16 23:23 ` [PATCH] diff: reset color before printing newline Junio C Hamano
2008-06-17 0:22 ` SZEDER Gábor
2008-06-17 0:59 ` 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=1213653602-31307-1-git-send-email-szeder@ira.uka.de \
--to=szeder@ira.uka.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).