diff-parseopt: convert --dirstat and friends
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Feb 21, 2019 at 18:16 UTC
4ce7aab5a56394914bd05b9e5fa4ca66404ec5f5
2 files changed
+36
-10
Documentation/diff-options.txt
+7
@@ -148,6 +148,7 @@ These parameters can also be set individually with `--stat-width=<width>`,
148
number of modified files, as well as number of added and deleted
149
lines.
150
151
+-X[<param1,param2,...>]::
152
--dirstat[=<param1,param2,...>]::
153
Output the distribution of relative amount of changes for each
154
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,
193
and accumulating child directory counts in the parent directories:
194
`--dirstat=files,10,cumulative`.
195
196
+--cumulative::
197
+ Synonym for --dirstat=cumulative
198
+
199
+--dirstat-by-file[=<param1,param2>...]::
200
+ Synonym for --dirstat=files,param1,param2...
201
+
202
--summary::
203
Output a condensed summary of extended header information
204
such as creations, renames and mode changes.
diff.c
+29
-10
@@ -4867,6 +4867,22 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)
4867
return 1;
4868
}
4869
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
+
4886
static int diff_opt_unified(const struct option *opt,
4887
const char *arg, int unset)
4888
{
@@ -4911,6 +4927,18 @@ static void prep_parse_options(struct diff_options *options)
4927
OPT_BIT_F(0, "shortstat", &options->output_format,
4928
N_("output only the last line of --stat"),
4929
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),
4942
OPT_END()
4943
};
4944
@@ -4939,16 +4967,7 @@ int diff_opt_parse(struct diff_options *options,
4967
return ac;
4968
4969
/* 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"))
4971
options->output_format |= DIFF_FORMAT_CHECKDIFF;
4972
else if (!strcmp(arg, "--summary"))
4973
options->output_format |= DIFF_FORMAT_SUMMARY;