diff-parseopt: convert --dirstat and friends
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Thu, 21 Feb 2019 11:16:03 +0000 (18:16 +0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 Feb 2019 23:16:58 +0000 (15:16 -0800)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/diff-options.txt
diff.c
index 0711734b125f92d441debeea9849e0f3512790c2..7b81b852cab8aa5601b669c1c54ca8fac920ae55 100644 (file)
@@ -148,6 +148,7 @@ These parameters can also be set individually with `--stat-width=<width>`,
        number of modified files, as well as number of added and deleted
        lines.
 
+-X[<param1,param2,...>]::
 --dirstat[=<param1,param2,...>]::
        Output the distribution of relative amount of changes for each
        sub-directory. The behavior of `--dirstat` can be customized by
@@ -192,6 +193,12 @@ directories with less than 10% of the total amount of changed files,
 and accumulating child directory counts in the parent directories:
 `--dirstat=files,10,cumulative`.
 
+--cumulative::
+       Synonym for --dirstat=cumulative
+
+--dirstat-by-file[=<param1,param2>...]::
+       Synonym for --dirstat=files,param1,param2...
+
 --summary::
        Output a condensed summary of extended header information
        such as creations, renames and mode changes.
diff --git a/diff.c b/diff.c
index 419b6ac4aea84eca8652446cf367ab4c83483f5d..1cdbe8e6884eb2d329330c78ea0a9bdf53a4ec4f 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -4867,6 +4867,22 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)
        return 1;
 }
 
+static int diff_opt_dirstat(const struct option *opt,
+                           const char *arg, int unset)
+{
+       struct diff_options *options = opt->value;
+
+       BUG_ON_OPT_NEG(unset);
+       if (!strcmp(opt->long_name, "cumulative")) {
+               if (arg)
+                       BUG("how come --cumulative take a value?");
+               arg = "cumulative";
+       } else if (!strcmp(opt->long_name, "dirstat-by-file"))
+               parse_dirstat_opt(options, "files");
+       parse_dirstat_opt(options, arg ? arg : "");
+       return 0;
+}
+
 static int diff_opt_unified(const struct option *opt,
                            const char *arg, int unset)
 {
@@ -4911,6 +4927,18 @@ static void prep_parse_options(struct diff_options *options)
                OPT_BIT_F(0, "shortstat", &options->output_format,
                          N_("output only the last line of --stat"),
                          DIFF_FORMAT_SHORTSTAT, PARSE_OPT_NONEG),
+               OPT_CALLBACK_F('X', "dirstat", options, N_("<param1,param2>..."),
+                              N_("output the distribution of relative amount of changes for each sub-directory"),
+                              PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
+                              diff_opt_dirstat),
+               OPT_CALLBACK_F(0, "cumulative", options, NULL,
+                              N_("synonym for --dirstat=cumulative"),
+                              PARSE_OPT_NONEG | PARSE_OPT_NOARG,
+                              diff_opt_dirstat),
+               OPT_CALLBACK_F(0, "dirstat-by-file", options, N_("<param1,param2>..."),
+                              N_("synonym for --dirstat=files,param1,param2..."),
+                              PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
+                              diff_opt_dirstat),
                OPT_END()
        };
 
@@ -4939,16 +4967,7 @@ int diff_opt_parse(struct diff_options *options,
                return ac;
 
        /* Output format options */
-       if (skip_prefix(arg, "-X", &arg) ||
-                skip_to_optional_arg(arg, "--dirstat", &arg))
-               return parse_dirstat_opt(options, arg);
-       else if (!strcmp(arg, "--cumulative"))
-               return parse_dirstat_opt(options, "cumulative");
-       else if (skip_to_optional_arg(arg, "--dirstat-by-file", &arg)) {
-               parse_dirstat_opt(options, "files");
-               return parse_dirstat_opt(options, arg);
-       }
-       else if (!strcmp(arg, "--check"))
+       if (!strcmp(arg, "--check"))
                options->output_format |= DIFF_FORMAT_CHECKDIFF;
        else if (!strcmp(arg, "--summary"))
                options->output_format |= DIFF_FORMAT_SUMMARY;