diff-parseopt: convert --no-prefix
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 24, 2019 at 15:20 UTC
11c659d89089ca236c65a1b824e85a27d9f09bcd
1 file changed
+15
-2
diff.c
+15
-2
@@ -5022,6 +5022,18 @@ static int diff_opt_line_prefix(const struct option *opt,
5022
return 0;
5023
}
5024
5025
+static int diff_opt_no_prefix(const struct option *opt,
5026
+ const char *optarg, int unset)
5027
+{
5028
+ struct diff_options *options = opt->value;
5029
+
5030
+ BUG_ON_OPT_NEG(unset);
5031
+ BUG_ON_OPT_ARG(optarg);
5032
+ options->a_prefix = "";
5033
+ options->b_prefix = "";
5034
+ return 0;
5035
+}
5036
+
5037
static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,
5038
const struct option *opt,
5039
const char *arg, int unset)
@@ -5276,6 +5288,9 @@ static void prep_parse_options(struct diff_options *options)
5288
OPT_CALLBACK_F(0, "line-prefix", options, N_("<prefix>"),
5289
N_("prepend an additional prefix to every line of output"),
5290
PARSE_OPT_NONEG, diff_opt_line_prefix),
5291
+ OPT_CALLBACK_F(0, "no-prefix", options, NULL,
5292
+ N_("do not show any source or destination prefix"),
5293
+ PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_no_prefix),
5294
OPT_CALLBACK_F(0, "output-indicator-new",
5295
&options->output_indicators[OUTPUT_INDICATOR_NEW],
5296
N_("<char>"),
@@ -5468,8 +5483,6 @@ int diff_opt_parse(struct diff_options *options,
5483
}
5484
5485
/* misc options */
5471
- else if (!strcmp(arg, "--no-prefix"))
5472
- options->a_prefix = options->b_prefix = "";
5486
else if (opt_arg(arg, '\0', "inter-hunk-context",
5487
&options->interhunkcontext))
5488
;