Use correct grammar in diffstat summary line

"git diff --stat" and "git apply --stat" now learn to print the line
"%d files changed, %d insertions(+), %d deletions(-)" in singular form
whenever applicable. "0 insertions" and "0 deletions" are also omitted
unless they are both zero.

This matches how versions of "diffstat" that are not prehistoric produced
their output, and also makes this line translatable.

[jc: with help from Thomas Dickey in archaeology of "diffstat"]
[jc: squashed Jonathan's updates to illustrations in tutorials and a test]

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy
2012-02-01 19:55:07 +07:00
committed by Junio C Hamano
parent 828ea97de4
commit 7f814632f5
69 changed files with 168 additions and 118 deletions

56
diff.c
View File

@ -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)