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>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2019-02-21 18:16:03 +07:00 committed by Junio C Hamano
parent e56736203e
commit 4ce7aab5a5
2 changed files with 36 additions and 10 deletions

View 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.

39
diff.c
View file

@ -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;