From: Junio C Hamano Date: Tue, 17 Jun 2008 00:37:21 +0000 (-0700) Subject: diff.c: fix emit_line() again not to add extra line X-Git-Tag: v1.5.6~12^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4afbcab9898ce63ad641dd0de6e9b69deda44330;p=git.git diff.c: fix emit_line() again not to add extra line Signed-off-by: Junio C Hamano --- diff --git a/diff.c b/diff.c index c0284775d..20135cbe7 100644 --- a/diff.c +++ b/diff.c @@ -514,13 +514,15 @@ 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') + int has_trailing_newline = (len > 0 && line[len-1] == '\n'); + if (has_trailing_newline) len--; fputs(set, file); fwrite(line, len, 1, file); fputs(reset, file); - fputc('\n', file); + if (has_trailing_newline) + fputc('\n', file); } static void emit_add_line(const char *reset, struct emit_callback *ecbdata, const char *line, int len)