diff-parseopt: convert --submodule
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
Mar 5, 2019 at 19:30 UTC
125dcea96338c99312cfbf4ff338a3b06dc434aa
1 file changed
+19
-11
diff.c
+19
-11
@@ -4721,14 +4721,6 @@ static int parse_dirstat_opt(struct diff_options *options, const char *params)
4721
return 1;
4722
}
4723
4724
-static int parse_submodule_opt(struct diff_options *options, const char *value)
4725
-{
4726
- if (parse_submodule_params(options, value))
4727
- die(_("Failed to parse --submodule option parameter: '%s'"),
4728
- value);
4729
- return 1;
4730
-}
4731
-
4724
static const char diff_status_letters[] = {
4725
DIFF_STATUS_ADDED,
4726
DIFF_STATUS_COPIED,
@@ -5075,6 +5067,20 @@ static int diff_opt_relative(const struct option *opt,
5067
return 0;
5068
}
5069
5070
+static int diff_opt_submodule(const struct option *opt,
5071
+ const char *arg, int unset)
5072
+{
5073
+ struct diff_options *options = opt->value;
5074
+
5075
+ BUG_ON_OPT_NEG(unset);
5076
+ if (!arg)
5077
+ arg = "log";
5078
+ if (parse_submodule_params(options, arg))
5079
+ return error(_("failed to parse --submodule option parameter: '%s'"),
5080
+ arg);
5081
+ return 0;
5082
+}
5083
+
5084
static int diff_opt_textconv(const struct option *opt,
5085
const char *arg, int unset)
5086
{
@@ -5338,6 +5344,10 @@ static void prep_parse_options(struct diff_options *options)
5344
N_("ignore changes to submodules in the diff generation"),
5345
PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
5346
diff_opt_ignore_submodules),
5347
+ OPT_CALLBACK_F(0, "submodule", options, N_("<format>"),
5348
+ N_("specify how differences in submodules are shown"),
5349
+ PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
5350
+ diff_opt_submodule),
5351
{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
5352
N_("Output to a specific file"),
5353
PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5387,9 +5397,7 @@ int diff_opt_parse(struct diff_options *options,
5397
if (cm & COLOR_MOVED_WS_ERROR)
5398
return -1;
5399
options->color_moved_ws_handling = cm;
5390
- } else if (skip_to_optional_arg_default(arg, "--submodule", &arg, "log"))
5391
- return parse_submodule_opt(options, arg);
5392
- else if (skip_prefix(arg, "--ws-error-highlight=", &arg))
5400
+ } else if (skip_prefix(arg, "--ws-error-highlight=", &arg))
5401
return parse_ws_error_highlight_opt(options, arg);
5402
else if (!strcmp(arg, "--ita-invisible-in-index"))
5403
options->ita_invisible_in_index = 1;