@@ -1316,9 +1316,10 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
13161316 int i , len , add , del , adds = 0 , dels = 0 ;
13171317 uintmax_t max_change = 0 , max_len = 0 ;
13181318 int total_files = data -> nr ;
1319- int width , name_width ;
1319+ int width , name_width , count ;
13201320 const char * reset , * add_c , * del_c ;
13211321 const char * line_prefix = "" ;
1322+ int extra_shown = 0 ;
13221323 struct strbuf * msg = NULL ;
13231324
13241325 if (data -> nr == 0 )
@@ -1331,6 +1332,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
13311332
13321333 width = options -> stat_width ? options -> stat_width : 80 ;
13331334 name_width = options -> stat_name_width ? options -> stat_name_width : 50 ;
1335+ count = options -> stat_count ? options -> stat_count : data -> nr ;
13341336
13351337 /* Sanity: give at least 5 columns to the graph,
13361338 * but leave at least 10 columns for the name.
@@ -1347,9 +1349,14 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
13471349 add_c = diff_get_color_opt (options , DIFF_FILE_NEW );
13481350 del_c = diff_get_color_opt (options , DIFF_FILE_OLD );
13491351
1350- for (i = 0 ; i < data -> nr ; i ++ ) {
1352+ for (i = 0 ; ( i < count ) && ( i < data -> nr ) ; i ++ ) {
13511353 struct diffstat_file * file = data -> files [i ];
13521354 uintmax_t change = file -> added + file -> deleted ;
1355+ if (!data -> files [i ]-> is_renamed &&
1356+ (change == 0 )) {
1357+ count ++ ; /* not shown == room for one more */
1358+ continue ;
1359+ }
13531360 fill_print_name (file );
13541361 len = strlen (file -> print_name );
13551362 if (max_len < len )
@@ -1360,6 +1367,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
13601367 if (max_change < change )
13611368 max_change = change ;
13621369 }
1370+ count = i ; /* min(count, data->nr) */
13631371
13641372 /* Compute the width of the graph part;
13651373 * 10 is for one blank at the beginning of the line plus
@@ -1374,13 +1382,18 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
13741382 else
13751383 width = max_change ;
13761384
1377- for (i = 0 ; i < data -> nr ; i ++ ) {
1385+ for (i = 0 ; i < count ; i ++ ) {
13781386 const char * prefix = "" ;
13791387 char * name = data -> files [i ]-> print_name ;
13801388 uintmax_t added = data -> files [i ]-> added ;
13811389 uintmax_t deleted = data -> files [i ]-> deleted ;
13821390 int name_len ;
13831391
1392+ if (!data -> files [i ]-> is_renamed &&
1393+ (added + deleted == 0 )) {
1394+ total_files -- ;
1395+ continue ;
1396+ }
13841397 /*
13851398 * "scale" the filename
13861399 */
@@ -1415,11 +1428,6 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
14151428 fprintf (options -> file , " Unmerged\n" );
14161429 continue ;
14171430 }
1418- else if (!data -> files [i ]-> is_renamed &&
1419- (added + deleted == 0 )) {
1420- total_files -- ;
1421- continue ;
1422- }
14231431
14241432 /*
14251433 * scale the add/delete
@@ -1441,6 +1449,20 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
14411449 show_graph (options -> file , '-' , del , del_c , reset );
14421450 fprintf (options -> file , "\n" );
14431451 }
1452+ for (i = count ; i < data -> nr ; i ++ ) {
1453+ uintmax_t added = data -> files [i ]-> added ;
1454+ uintmax_t deleted = data -> files [i ]-> deleted ;
1455+ if (!data -> files [i ]-> is_renamed &&
1456+ (added + deleted == 0 )) {
1457+ total_files -- ;
1458+ continue ;
1459+ }
1460+ adds += added ;
1461+ dels += deleted ;
1462+ if (!extra_shown )
1463+ fprintf (options -> file , "%s ...\n" , line_prefix );
1464+ extra_shown = 1 ;
1465+ }
14441466 fprintf (options -> file , "%s" , line_prefix );
14451467 fprintf (options -> file ,
14461468 " %d files changed, %d insertions(+), %d deletions(-)\n" ,
@@ -3208,6 +3230,7 @@ static int stat_opt(struct diff_options *options, const char **av)
32083230 char * end ;
32093231 int width = options -> stat_width ;
32103232 int name_width = options -> stat_name_width ;
3233+ int count = options -> stat_count ;
32113234 int argcount = 1 ;
32123235
32133236 arg += strlen ("--stat" );
@@ -3235,12 +3258,24 @@ static int stat_opt(struct diff_options *options, const char **av)
32353258 name_width = strtoul (av [1 ], & end , 10 );
32363259 argcount = 2 ;
32373260 }
3261+ } else if (!prefixcmp (arg , "-count" )) {
3262+ arg += strlen ("-count" );
3263+ if (* arg == '=' )
3264+ count = strtoul (arg + 1 , & end , 10 );
3265+ else if (!* arg && !av [1 ])
3266+ die ("Option '--stat-count' requires a value" );
3267+ else if (!* arg ) {
3268+ count = strtoul (av [1 ], & end , 10 );
3269+ argcount = 2 ;
3270+ }
32383271 }
32393272 break ;
32403273 case '=' :
32413274 width = strtoul (arg + 1 , & end , 10 );
32423275 if (* end == ',' )
32433276 name_width = strtoul (end + 1 , & end , 10 );
3277+ if (* end == ',' )
3278+ count = strtoul (end + 1 , & end , 10 );
32443279 }
32453280
32463281 /* Important! This checks all the error cases! */
@@ -3249,6 +3284,7 @@ static int stat_opt(struct diff_options *options, const char **av)
32493284 options -> output_format |= DIFF_FORMAT_DIFFSTAT ;
32503285 options -> stat_name_width = name_width ;
32513286 options -> stat_width = width ;
3287+ options -> stat_count = count ;
32523288 return argcount ;
32533289}
32543290
@@ -3313,7 +3349,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
33133349 else if (!strcmp (arg , "-s" ))
33143350 options -> output_format |= DIFF_FORMAT_NO_OUTPUT ;
33153351 else if (!prefixcmp (arg , "--stat" ))
3316- /* --stat, --stat-width, or --stat-name-width */
3352+ /* --stat, --stat-width, --stat-name-width, or --stat-count */
33173353 return stat_opt (options , av );
33183354
33193355 /* renames options */
0 commit comments