From: Junio C Hamano Date: Sat, 28 Nov 2009 06:04:10 +0000 (-0800) Subject: emit_line(): don't emit an empty followed by a newline X-Git-Tag: v1.6.6-rc1~19^2~1 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=06a4755270b86a2af20a5c1f0d785311472b5223;p=git.git emit_line(): don't emit an empty followed by a newline When emit_line() is called with an empty line (but non-zero length, as we send line terminating LF or CRLF to the function), it used to emit followed by a newline. Stop the wastefulness. Signed-off-by: Junio C Hamano --- diff --git a/diff.c b/diff.c index 0d7f5ea4a..108c7d764 100644 --- a/diff.c +++ b/diff.c @@ -295,12 +295,13 @@ static void emit_line_0(FILE *file, const char *set, const char *reset, nofirst = 0; } - fputs(set, file); - - if (!nofirst) - fputc(first, file); - fwrite(line, len, 1, file); - fputs(reset, file); + if (len || !nofirst) { + fputs(set, file); + if (!nofirst) + fputc(first, file); + fwrite(line, len, 1, file); + fputs(reset, file); + } if (has_trailing_carriage_return) fputc('\r', file); if (has_trailing_newline) diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh index 21db6e95c..2d24fbeda 100755 --- a/t/t4034-diff-words.sh +++ b/t/t4034-diff-words.sh @@ -49,7 +49,7 @@ cat > expect <<\EOF +++ b/post @@ -1,3 +1,7 @@ h(4)h(4),hh[44] - + a = b + c aa = a @@ -90,7 +90,7 @@ cat > expect <<\EOF +++ b/post @@ -1,3 +1,7 @@ h(4),hh[44] - + a = b + c aa = a @@ -126,7 +126,7 @@ cat > expect <<\EOF +++ b/post @@ -1,3 +1,7 @@ h(4),hh[44] - + a = b + c aa = a @@ -168,7 +168,7 @@ cat > expect <<\EOF +++ b/post @@ -1,3 +1,7 @@ h(4),hh[44] - + a = b + c aa = a