diff options
author | Junio C Hamano <gitster@pobox.com> | 2012-02-21 14:56:39 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-02-21 14:56:39 -0800 |
commit | 093b194cc5570c825173a90538a4c212bc64bc7f (patch) | |
tree | b6557708089548b930b8009e9639a0e4f98c9efa /diff.c | |
parent | f3ccea8dd4ba03c8ed1971c317a14c1c34b61705 (diff) | |
parent | 7f814632f5d4d7af9f4225ece6039dbc44e03079 (diff) | |
download | git-093b194cc5570c825173a90538a4c212bc64bc7f.tar.gz git-093b194cc5570c825173a90538a4c212bc64bc7f.tar.xz |
Merge branch 'nd/diffstat-gramnum' into maint
* nd/diffstat-gramnum:
Use correct grammar in diffstat summary line
Diffstat (limited to 'diff.c')
-rw-r--r-- | diff.c | 56 |
1 files changed, 51 insertions, 5 deletions
@@ -1322,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; @@ -1475,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) @@ -1507,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) |