@@ -1244,7 +1244,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
12441244 int i , len , add , del , adds = 0 , dels = 0 ;
12451245 uintmax_t max_change = 0 , max_len = 0 ;
12461246 int total_files = data -> nr ;
1247- int width , name_width ;
1247+ int width , name_width , count ;
12481248 const char * reset , * add_c , * del_c ;
12491249 const char * line_prefix = "" ;
12501250 struct strbuf * msg = NULL ;
@@ -1259,6 +1259,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
12591259
12601260 width = options -> stat_width ? options -> stat_width : 80 ;
12611261 name_width = options -> stat_name_width ? options -> stat_name_width : 50 ;
1262+ count = options -> stat_count ? options -> stat_count : data -> nr ;
12621263
12631264 /* Sanity: give at least 5 columns to the graph,
12641265 * but leave at least 10 columns for the name.
@@ -1275,11 +1276,12 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
12751276 add_c = diff_get_color_opt (options , DIFF_FILE_NEW );
12761277 del_c = diff_get_color_opt (options , DIFF_FILE_OLD );
12771278
1278- for (i = 0 ; i < data -> nr ; i ++ ) {
1279+ for (i = 0 ; ( i < count ) && ( i < data -> nr ) ; i ++ ) {
12791280 struct diffstat_file * file = data -> files [i ];
12801281 uintmax_t change = file -> added + file -> deleted ;
12811282 if (!data -> files [i ]-> is_renamed &&
12821283 (change == 0 )) {
1284+ count ++ ; /* not shown == room for one more */
12831285 continue ;
12841286 }
12851287 fill_print_name (file );
@@ -1292,6 +1294,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
12921294 if (max_change < change )
12931295 max_change = change ;
12941296 }
1297+ count = i ; /* min(count, data->nr) */
12951298
12961299 /* Compute the width of the graph part;
12971300 * 10 is for one blank at the beginning of the line plus
@@ -1306,7 +1309,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
13061309 else
13071310 width = max_change ;
13081311
1309- for (i = 0 ; i < data -> nr ; i ++ ) {
1312+ for (i = 0 ; i < count ; i ++ ) {
13101313 const char * prefix = "" ;
13111314 char * name = data -> files [i ]-> print_name ;
13121315 uintmax_t added = data -> files [i ]-> added ;
@@ -1373,6 +1376,19 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
13731376 show_graph (options -> file , '-' , del , del_c , reset );
13741377 fprintf (options -> file , "\n" );
13751378 }
1379+ if (count < data -> nr )
1380+ fprintf (options -> file , "%s ...\n" , line_prefix );
1381+ for (i = count ; i < data -> nr ; i ++ ) {
1382+ uintmax_t added = data -> files [i ]-> added ;
1383+ uintmax_t deleted = data -> files [i ]-> deleted ;
1384+ if (!data -> files [i ]-> is_renamed &&
1385+ (added + deleted == 0 )) {
1386+ total_files -- ;
1387+ continue ;
1388+ }
1389+ adds += added ;
1390+ dels += deleted ;
1391+ }
13761392 fprintf (options -> file , "%s" , line_prefix );
13771393 fprintf (options -> file ,
13781394 " %d files changed, %d insertions(+), %d deletions(-)\n" ,
@@ -3109,6 +3125,7 @@ static int stat_opt(struct diff_options *options, const char **av)
31093125 char * end ;
31103126 int width = options -> stat_width ;
31113127 int name_width = options -> stat_name_width ;
3128+ int count = options -> stat_count ;
31123129 int argcount = 1 ;
31133130
31143131 arg += strlen ("--stat" );
@@ -3136,12 +3153,24 @@ static int stat_opt(struct diff_options *options, const char **av)
31363153 name_width = strtoul (av [1 ], & end , 10 );
31373154 argcount = 2 ;
31383155 }
3156+ } else if (!prefixcmp (arg , "-count" )) {
3157+ arg += strlen ("-count" );
3158+ if (* arg == '=' )
3159+ count = strtoul (arg + 1 , & end , 10 );
3160+ else if (!* arg && !av [1 ])
3161+ die ("Option '--stat-count' requires a value" );
3162+ else if (!* arg ) {
3163+ count = strtoul (av [1 ], & end , 10 );
3164+ argcount = 2 ;
3165+ }
31393166 }
31403167 break ;
31413168 case '=' :
31423169 width = strtoul (arg + 1 , & end , 10 );
31433170 if (* end == ',' )
31443171 name_width = strtoul (end + 1 , & end , 10 );
3172+ if (* end == ',' )
3173+ count = strtoul (end + 1 , & end , 10 );
31453174 }
31463175
31473176 /* Important! This checks all the error cases! */
@@ -3150,6 +3179,7 @@ static int stat_opt(struct diff_options *options, const char **av)
31503179 options -> output_format |= DIFF_FORMAT_DIFFSTAT ;
31513180 options -> stat_name_width = name_width ;
31523181 options -> stat_width = width ;
3182+ options -> stat_count = count ;
31533183 return argcount ;
31543184}
31553185
@@ -3195,7 +3225,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
31953225 else if (!strcmp (arg , "-s" ))
31963226 options -> output_format |= DIFF_FORMAT_NO_OUTPUT ;
31973227 else if (!prefixcmp (arg , "--stat" ))
3198- /* --stat, --stat-width, or --stat-name-width */
3228+ /* --stat, --stat-width, --stat-name-width, or --stat-count */
31993229 return stat_opt (options , av );
32003230
32013231 /* renames options */
0 commit comments