diff-parseopt: convert --textconv
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
8ab76977ad22cc9236f3b541f4933c0fcdc234d5
1 file changed
+19
-6
diff.c
+19
-6
@@ -5062,6 +5062,21 @@ static int diff_opt_relative(const struct option *opt,
5062
return 0;
5063
}
5064
5065
+static int diff_opt_textconv(const struct option *opt,
5066
+ const char *arg, int unset)
5067
+{
5068
+ struct diff_options *options = opt->value;
5069
+
5070
+ BUG_ON_OPT_ARG(arg);
5071
+ if (unset) {
5072
+ options->flags.allow_textconv = 0;
5073
+ } else {
5074
+ options->flags.allow_textconv = 1;
5075
+ options->flags.textconv_set_via_cmdline = 1;
5076
+ }
5077
+ return 0;
5078
+}
5079
+
5080
static int diff_opt_unified(const struct option *opt,
5081
const char *arg, int unset)
5082
{
@@ -5303,6 +5318,9 @@ static void prep_parse_options(struct diff_options *options)
5318
N_("disable all output of the program")),
5319
OPT_BOOL(0, "ext-diff", &options->flags.allow_external,
5320
N_("allow an external diff helper to be executed")),
5321
+ OPT_CALLBACK_F(0, "textconv", options, NULL,
5322
+ N_("run external text conversion filters when comparing binary files"),
5323
+ PARSE_OPT_NOARG, diff_opt_textconv),
5324
{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
5325
N_("Output to a specific file"),
5326
PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5352,12 +5370,7 @@ int diff_opt_parse(struct diff_options *options,
5370
if (cm & COLOR_MOVED_WS_ERROR)
5371
return -1;
5372
options->color_moved_ws_handling = cm;
5355
- } else if (!strcmp(arg, "--textconv")) {
5356
- options->flags.allow_textconv = 1;
5357
- options->flags.textconv_set_via_cmdline = 1;
5358
- } else if (!strcmp(arg, "--no-textconv"))
5359
- options->flags.allow_textconv = 0;
5360
- else if (skip_to_optional_arg_default(arg, "--ignore-submodules", &arg, "all")) {
5373
+ } else if (skip_to_optional_arg_default(arg, "--ignore-submodules", &arg, "all")) {
5374
options->flags.override_submodule_config = 1;
5375
handle_ignore_submodules_arg(options, arg);
5376
} else if (skip_to_optional_arg_default(arg, "--submodule", &arg, "log"))