@@ -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+
13251374static 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
14831530static 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
15141560static void show_numstat (struct diffstat_t * data , struct diff_options * options )
0 commit comments