Code

branch --merged/--no-merged: allow specifying arbitrary commit
[git.git] / diff.c
diff --git a/diff.c b/diff.c
index f23657bd347a62729d2211e8c64536279a5ea910..44e8790690ebdfa45ff7d6c89ede85e8f4f9e857 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -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)
@@ -926,7 +928,8 @@ static void show_stats(struct diffstat_t* data, struct diff_options *options)
                        total = add + del;
                }
                show_name(options->file, prefix, name, len, reset, set);
-               fprintf(options->file, "%5d ", added + deleted);
+               fprintf(options->file, "%5d%s", added + deleted,
+                               added + deleted ? " " : "");
                show_graph(options->file, '+', add, add_c, reset);
                show_graph(options->file, '-', del, del_c, reset);
                fprintf(options->file, "\n");