Commits

Anonymous committed 4afbcab

diff.c: fix emit_line() again not to add extra line

Signed-off-by: Junio C Hamano <gitster@pobox.com>

Comments (0)

Files changed (1)

 
 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)