diff options
| author | Junio C Hamano <gitster@pobox.com> | 2012-02-12 22:43:19 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2012-02-12 22:43:19 -0800 |
| commit | 2ef80c2d8998593852be2fb0546c8e4a518a6bf1 (patch) | |
| tree | 0907edcc74ec5fb9e1672aa3be963292778edd60 /diff.c | |
| parent | dd5253b4bd440d2472ac01bd3821ac96c2d26ff0 (diff) | |
| parent | 7f814632f5d4d7af9f4225ece6039dbc44e03079 (diff) | |
| download | git-2ef80c2d8998593852be2fb0546c8e4a518a6bf1.tar.xz | |
Merge branch 'nd/diffstat-gramnum'
* 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) |
