Skip to content

Commit 7f81463

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 828ea97 commit 7f81463

File tree

69 files changed

+168
-118
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+168
-118
lines changed

Documentation/gitcore-tutorial.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ Updating from ae3a2da... to a80b4aa....
10041004
Fast-forward (no commit created; -m option ignored)
10051005
example | 1 +
10061006
hello | 1 +
1007-
2 files changed, 2 insertions(+), 0 deletions(-)
1007+
2 files changed, 2 insertions(+)
10081008
----------------
10091009

10101010
Because your branch did not contain anything more than what had

Documentation/gittutorial-2.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ $ echo 'hello world' > file.txt
3434
$ git add .
3535
$ git commit -a -m "initial commit"
3636
[master (root-commit) 54196cc] initial commit
37-
1 files changed, 1 insertions(+), 0 deletions(-)
37+
1 file changed, 1 insertion(+)
3838
create mode 100644 file.txt
3939
$ echo 'hello world!' >file.txt
4040
$ git commit -a -m "add emphasis"
4141
[master c4d59f3] add emphasis
42-
1 files changed, 1 insertions(+), 1 deletions(-)
42+
1 file changed, 1 insertion(+), 1 deletion(-)
4343
------------------------------------------------
4444

4545
What are the 7 digits of hex that git responded to the commit with?

builtin/apply.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "builtin.h"
1515
#include "string-list.h"
1616
#include "dir.h"
17+
#include "diff.h"
1718
#include "parse-options.h"
1819

1920
/*
@@ -3241,7 +3242,7 @@ static void stat_patch_list(struct patch *patch)
32413242
show_stats(patch);
32423243
}
32433244

3244-
printf(" %d files changed, %d insertions(+), %d deletions(-)\n", files, adds, dels);
3245+
print_stat_summary(stdout, files, adds, dels);
32453246
}
32463247

32473248
static void numstat_patch_list(struct patch *patch)

diff.c

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,55 @@ static void fill_print_name(struct diffstat_file *file)
13221322
file->print_name = pname;
13231323
}
13241324

1325+
int print_stat_summary(FILE *fp, int files, int insertions, int deletions)
1326+
{
1327+
struct strbuf sb = STRBUF_INIT;
1328+
int ret;
1329+
1330+
if (!files) {
1331+
assert(insertions == 0 && deletions == 0);
1332+
return fputs(_(" 0 files changed\n"), fp);
1333+
}
1334+
1335+
strbuf_addf(&sb,
1336+
Q_(" %d file changed", " %d files changed", files),
1337+
files);
1338+
1339+
/*
1340+
* For binary diff, the caller may want to print "x files
1341+
* changed" with insertions == 0 && deletions == 0.
1342+
*
1343+
* Not omitting "0 insertions(+), 0 deletions(-)" in this case
1344+
* is probably less confusing (i.e skip over "2 files changed
1345+
* but nothing about added/removed lines? Is this a bug in Git?").
1346+
*/
1347+
if (insertions || deletions == 0) {
1348+
/*
1349+
* TRANSLATORS: "+" in (+) is a line addition marker;
1350+
* do not translate it.
1351+
*/
1352+
strbuf_addf(&sb,
1353+
Q_(", %d insertion(+)", ", %d insertions(+)",
1354+
insertions),
1355+
insertions);
1356+
}
1357+
1358+
if (deletions || insertions == 0) {
1359+
/*
1360+
* TRANSLATORS: "-" in (-) is a line removal marker;
1361+
* do not translate it.
1362+
*/
1363+
strbuf_addf(&sb,
1364+
Q_(", %d deletion(-)", ", %d deletions(-)",
1365+
deletions),
1366+
deletions);
1367+
}
1368+
strbuf_addch(&sb, '\n');
1369+
ret = fputs(sb.buf, fp);
1370+
strbuf_release(&sb);
1371+
return ret;
1372+
}
1373+
13251374
static void show_stats(struct diffstat_t *data, struct diff_options *options)
13261375
{
13271376
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)
14751524
extra_shown = 1;
14761525
}
14771526
fprintf(options->file, "%s", line_prefix);
1478-
fprintf(options->file,
1479-
" %d files changed, %d insertions(+), %d deletions(-)\n",
1480-
total_files, adds, dels);
1527+
print_stat_summary(options->file, total_files, adds, dels);
14811528
}
14821529

14831530
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
15071554
options->output_prefix_data);
15081555
fprintf(options->file, "%s", msg->buf);
15091556
}
1510-
fprintf(options->file, " %d files changed, %d insertions(+), %d deletions(-)\n",
1511-
total_files, adds, dels);
1557+
print_stat_summary(options->file, total_files, adds, dels);
15121558
}
15131559

15141560
static void show_numstat(struct diffstat_t *data, struct diff_options *options)

diff.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,4 +324,7 @@ extern struct userdiff_driver *get_textconv(struct diff_filespec *one);
324324

325325
extern int parse_rename_score(const char **cp_p);
326326

327+
extern int print_stat_summary(FILE *fp, int files,
328+
int insertions, int deletions);
329+
327330
#endif /* DIFF_H */

t/t1200-tutorial.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Updating VARIABLE..VARIABLE
156156
FASTFORWARD (no commit created; -m option ignored)
157157
example | 1 +
158158
hello | 1 +
159-
2 files changed, 2 insertions(+), 0 deletions(-)
159+
2 files changed, 2 insertions(+)
160160
EOF
161161

162162
test_expect_success 'git resolve' '

t/t3300-funny-names.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ test_expect_success TABS_IN_FILENAMES 'git diff-tree delete with-funny' \
167167
test_expect_success TABS_IN_FILENAMES 'setup expect' '
168168
cat >expected <<\EOF
169169
"tabs\t,\" (dq) and spaces"
170-
1 files changed, 0 insertions(+), 0 deletions(-)
170+
1 file changed, 0 insertions(+), 0 deletions(-)
171171
EOF
172172
'
173173

t/t3508-cherry-pick-many-commits.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ test_expect_success 'cherry-pick first..fourth works' '
3838
cat <<-\EOF >expected &&
3939
[master OBJID] second
4040
Author: A U Thor <[email protected]>
41-
1 files changed, 1 insertions(+), 0 deletions(-)
41+
1 file changed, 1 insertion(+)
4242
[master OBJID] third
4343
Author: A U Thor <[email protected]>
44-
1 files changed, 1 insertions(+), 0 deletions(-)
44+
1 file changed, 1 insertion(+)
4545
[master OBJID] fourth
4646
Author: A U Thor <[email protected]>
47-
1 files changed, 1 insertions(+), 0 deletions(-)
47+
1 file changed, 1 insertion(+)
4848
EOF
4949
5050
git checkout -f master &&
@@ -64,15 +64,15 @@ test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
6464
Trying simple merge.
6565
[master OBJID] second
6666
Author: A U Thor <[email protected]>
67-
1 files changed, 1 insertions(+), 0 deletions(-)
67+
1 file changed, 1 insertion(+)
6868
Trying simple merge.
6969
[master OBJID] third
7070
Author: A U Thor <[email protected]>
71-
1 files changed, 1 insertions(+), 0 deletions(-)
71+
1 file changed, 1 insertion(+)
7272
Trying simple merge.
7373
[master OBJID] fourth
7474
Author: A U Thor <[email protected]>
75-
1 files changed, 1 insertions(+), 0 deletions(-)
75+
1 file changed, 1 insertion(+)
7676
EOF
7777
7878
git checkout -f master &&

t/t3903-stash.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ test_expect_success 'stash show - stashes on stack, stash-like argument' '
444444
git reset --hard &&
445445
cat >expected <<-EOF &&
446446
file | 1 +
447-
1 files changed, 1 insertions(+), 0 deletions(-)
447+
1 file changed, 1 insertion(+)
448448
EOF
449449
git stash show ${STASH_ID} >actual &&
450450
test_cmp expected actual
@@ -482,7 +482,7 @@ test_expect_success 'stash show - no stashes on stack, stash-like argument' '
482482
git reset --hard &&
483483
cat >expected <<-EOF &&
484484
file | 1 +
485-
1 files changed, 1 insertions(+), 0 deletions(-)
485+
1 file changed, 1 insertion(+)
486486
EOF
487487
git stash show ${STASH_ID} >actual &&
488488
test_cmp expected actual

t/t4013/diff.diff-tree_--cc_--patch-with-stat_--summary_master

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ $ git diff-tree --cc --patch-with-stat --summary master
22
59d314ad6f356dd08601a4cd5e530381da3e3c64
33
dir/sub | 2 ++
44
file0 | 3 +++
5-
2 files changed, 5 insertions(+), 0 deletions(-)
5+
2 files changed, 5 insertions(+)
66

77
diff --cc dir/sub
88
index cead32e,7289e35..992913c

0 commit comments

Comments
 (0)