emit_line(): don't emit an empty <SET><RESET> 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 <SET><RESET> followed by a newline. Stop the wastefulness. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Nov 27, 2009 at 22:04 UTC
06a4755270b86a2af20a5c1f0d785311472b5223
2 files changed
+11
-10
diff.c
+7
-6
@@ -295,12 +295,13 @@ static void emit_line_0(FILE *file, const char *set, const char *reset,
295
nofirst = 0;
296
}
297
298
- fputs(set, file);
299
-
300
- if (!nofirst)
301
- fputc(first, file);
302
- fwrite(line, len, 1, file);
303
- fputs(reset, file);
298
+ if (len || !nofirst) {
299
+ fputs(set, file);
300
+ if (!nofirst)
301
+ fputc(first, file);
302
+ fwrite(line, len, 1, file);
303
+ fputs(reset, file);
304
+ }
305
if (has_trailing_carriage_return)
306
fputc('\r', file);
307
if (has_trailing_newline)
t/t4034-diff-words.sh
+4
-4
@@ -49,7 +49,7 @@ cat > expect <<\EOF
49
<WHITE>+++ b/post<RESET>
50
<BROWN>@@ -1,3 +1,7 @@<RESET>
51
<RED>h(4)<RESET><GREEN>h(4),hh[44]<RESET>
52
-<RESET>
52
+
53
a = b + c<RESET>
54
55
<GREEN>aa = a<RESET>
@@ -90,7 +90,7 @@ cat > expect <<\EOF
90
<WHITE>+++ b/post<RESET>
91
<BROWN>@@ -1,3 +1,7 @@<RESET>
92
h(4),<GREEN>hh<RESET>[44]
93
-<RESET>
93
+
94
a = b + c<RESET>
95
96
<GREEN>aa = a<RESET>
@@ -126,7 +126,7 @@ cat > expect <<\EOF
126
<WHITE>+++ b/post<RESET>
127
<BROWN>@@ -1,3 +1,7 @@<RESET>
128
h(4)<GREEN>,hh[44]<RESET>
129
-<RESET>
129
+
130
a = b + c<RESET>
131
132
<GREEN>aa = a<RESET>
@@ -168,7 +168,7 @@ cat > expect <<\EOF
168
<WHITE>+++ b/post<RESET>
169
<BROWN>@@ -1,3 +1,7 @@<RESET>
170
h(4),<GREEN>hh[44<RESET>]
171
-<RESET>
171
+
172
a = b + c<RESET>
173
174
<GREEN>aa = a<RESET>