Skip to content

Commit 4ce7aab

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent e567362 commit 4ce7aab

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

Documentation/diff-options.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ These parameters can also be set individually with `--stat-width=<width>`,
148148
number of modified files, as well as number of added and deleted
149149
lines.
150150

151+
-X[<param1,param2,...>]::
151152
--dirstat[=<param1,param2,...>]::
152153
Output the distribution of relative amount of changes for each
153154
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,
192193
and accumulating child directory counts in the parent directories:
193194
`--dirstat=files,10,cumulative`.
194195

196+
--cumulative::
197+
Synonym for --dirstat=cumulative
198+
199+
--dirstat-by-file[=<param1,param2>...]::
200+
Synonym for --dirstat=files,param1,param2...
201+
195202
--summary::
196203
Output a condensed summary of extended header information
197204
such as creations, renames and mode changes.

diff.c

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
48704886
static 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

Comments
 (0)