summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorLibravatar SZEDER Gábor <szeder@ira.uka.de>2008-06-17 00:00:02 +0200
committerLibravatar Junio C Hamano <gitster@pobox.com>2008-06-16 15:22:09 -0700
commit06ff64ae3d8c1d446ff61cff78a8faa3a07bfe24 (patch)
tree07007934d69652bf32883645499a664878a3e245 /diff.c
parentfix typo in tutorial (diff)
downloadtgif-06ff64ae3d8c1d446ff61cff78a8faa3a07bfe24.tar.xz
diff: reset color before printing newline
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/diff.c b/diff.c
index 8022e678d1..c0284775d3 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)