Skip to content

Commit 4afbcab

Browse files
committed
diff.c: fix emit_line() again not to add extra line
Signed-off-by: Junio C Hamano <[email protected]>
1 parent 06ff64a commit 4afbcab

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

diff.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,15 @@ const char *diff_get_color(int diff_use_color, enum color_diff ix)
514514

515515
static void emit_line(FILE *file, const char *set, const char *reset, const char *line, int len)
516516
{
517-
if (len > 0 && line[len-1] == '\n')
517+
int has_trailing_newline = (len > 0 && line[len-1] == '\n');
518+
if (has_trailing_newline)
518519
len--;
519520

520521
fputs(set, file);
521522
fwrite(line, len, 1, file);
522523
fputs(reset, file);
523-
fputc('\n', file);
524+
if (has_trailing_newline)
525+
fputc('\n', file);
524526
}
525527

526528
static void emit_add_line(const char *reset, struct emit_callback *ecbdata, const char *line, int len)

0 commit comments

Comments
 (0)