Skip to content

Commit

Permalink
diff.c: fix emit_line() again not to add extra line
Browse files Browse the repository at this point in the history
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Jun 17, 2008
1 parent 06ff64a commit 4afbcab
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4afbcab

Please sign in to comment.