X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=diff.c;h=84780fd5e641d9f1042f82863d1290f7ad8d92b5;hb=1e2545c6878665f2092940eab1aaeb20703f7d14;hp=374ecf3b486e218c52f94ba14481a715c19b80db;hpb=52b9d2cf7fbde061bf0d3336e3a89d7333d5b23d;p=git.git diff --git a/diff.c b/diff.c index 374ecf3b4..84780fd5e 100644 --- a/diff.c +++ b/diff.c @@ -1113,6 +1113,15 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) diff_words_append(line, len, &ecbdata->diff_words->plus); return; + } else if (!prefixcmp(line, "\\ ")) { + /* + * Eat the "no newline at eof" marker as if we + * saw a "+" or "-" line with nothing on it, + * and return without diff_words_flush() to + * defer processing. If this is the end of + * preimage, more "+" lines may come after it. + */ + return; } diff_words_flush(ecbdata); if (ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN) { @@ -1313,6 +1322,55 @@ static void fill_print_name(struct diffstat_file *file) file->print_name = pname; } +int print_stat_summary(FILE *fp, int files, int insertions, int deletions) +{ + struct strbuf sb = STRBUF_INIT; + int ret; + + if (!files) { + assert(insertions == 0 && deletions == 0); + return fputs(_(" 0 files changed\n"), fp); + } + + strbuf_addf(&sb, + Q_(" %d file changed", " %d files changed", files), + files); + + /* + * For binary diff, the caller may want to print "x files + * changed" with insertions == 0 && deletions == 0. + * + * Not omitting "0 insertions(+), 0 deletions(-)" in this case + * is probably less confusing (i.e skip over "2 files changed + * but nothing about added/removed lines? Is this a bug in Git?"). + */ + if (insertions || deletions == 0) { + /* + * TRANSLATORS: "+" in (+) is a line addition marker; + * do not translate it. + */ + strbuf_addf(&sb, + Q_(", %d insertion(+)", ", %d insertions(+)", + insertions), + insertions); + } + + if (deletions || insertions == 0) { + /* + * TRANSLATORS: "-" in (-) is a line removal marker; + * do not translate it. + */ + strbuf_addf(&sb, + Q_(", %d deletion(-)", ", %d deletions(-)", + deletions), + deletions); + } + strbuf_addch(&sb, '\n'); + ret = fputs(sb.buf, fp); + strbuf_release(&sb); + return ret; +} + static void show_stats(struct diffstat_t *data, struct diff_options *options) { int i, len, add, del, adds = 0, dels = 0; @@ -1466,9 +1524,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options) extra_shown = 1; } fprintf(options->file, "%s", line_prefix); - fprintf(options->file, - " %d files changed, %d insertions(+), %d deletions(-)\n", - total_files, adds, dels); + print_stat_summary(options->file, total_files, adds, dels); } static void show_shortstats(struct diffstat_t *data, struct diff_options *options) @@ -1498,8 +1554,7 @@ static void show_shortstats(struct diffstat_t *data, struct diff_options *option options->output_prefix_data); fprintf(options->file, "%s", msg->buf); } - fprintf(options->file, " %d files changed, %d insertions(+), %d deletions(-)\n", - total_files, adds, dels); + print_stat_summary(options->file, total_files, adds, dels); } static void show_numstat(struct diffstat_t *data, struct diff_options *options)