@@ -4867,6 +4867,22 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)
48674867 return 1 ;
48684868}
48694869
4870+ static int diff_opt_dirstat (const struct option * opt ,
4871+ const char * arg , int unset )
4872+ {
4873+ struct diff_options * options = opt -> value ;
4874+
4875+ BUG_ON_OPT_NEG (unset );
4876+ if (!strcmp (opt -> long_name , "cumulative" )) {
4877+ if (arg )
4878+ BUG ("how come --cumulative take a value?" );
4879+ arg = "cumulative" ;
4880+ } else if (!strcmp (opt -> long_name , "dirstat-by-file" ))
4881+ parse_dirstat_opt (options , "files" );
4882+ parse_dirstat_opt (options , arg ? arg : "" );
4883+ return 0 ;
4884+ }
4885+
48704886static int diff_opt_unified (const struct option * opt ,
48714887 const char * arg , int unset )
48724888{
@@ -4911,6 +4927,18 @@ static void prep_parse_options(struct diff_options *options)
49114927 OPT_BIT_F (0 , "shortstat" , & options -> output_format ,
49124928 N_ ("output only the last line of --stat" ),
49134929 DIFF_FORMAT_SHORTSTAT , PARSE_OPT_NONEG ),
4930+ OPT_CALLBACK_F ('X' , "dirstat" , options , N_ ("<param1,param2>..." ),
4931+ N_ ("output the distribution of relative amount of changes for each sub-directory" ),
4932+ PARSE_OPT_NONEG | PARSE_OPT_OPTARG ,
4933+ diff_opt_dirstat ),
4934+ OPT_CALLBACK_F (0 , "cumulative" , options , NULL ,
4935+ N_ ("synonym for --dirstat=cumulative" ),
4936+ PARSE_OPT_NONEG | PARSE_OPT_NOARG ,
4937+ diff_opt_dirstat ),
4938+ OPT_CALLBACK_F (0 , "dirstat-by-file" , options , N_ ("<param1,param2>..." ),
4939+ N_ ("synonym for --dirstat=files,param1,param2..." ),
4940+ PARSE_OPT_NONEG | PARSE_OPT_OPTARG ,
4941+ diff_opt_dirstat ),
49144942 OPT_END ()
49154943 };
49164944
@@ -4939,16 +4967,7 @@ int diff_opt_parse(struct diff_options *options,
49394967 return ac ;
49404968
49414969 /* Output format options */
4942- if (skip_prefix (arg , "-X" , & arg ) ||
4943- skip_to_optional_arg (arg , "--dirstat" , & arg ))
4944- return parse_dirstat_opt (options , arg );
4945- else if (!strcmp (arg , "--cumulative" ))
4946- return parse_dirstat_opt (options , "cumulative" );
4947- else if (skip_to_optional_arg (arg , "--dirstat-by-file" , & arg )) {
4948- parse_dirstat_opt (options , "files" );
4949- return parse_dirstat_opt (options , arg );
4950- }
4951- else if (!strcmp (arg , "--check" ))
4970+ if (!strcmp (arg , "--check" ))
49524971 options -> output_format |= DIFF_FORMAT_CHECKDIFF ;
49534972 else if (!strcmp (arg , "--summary" ))
49544973 options -> output_format |= DIFF_FORMAT_SUMMARY ;
0 commit comments