diff-parseopt: convert --line-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
2f81cf9895fedb864477f9fb318c9ec7dc0a17ab
1 file changed
+15
-8
diff.c
+15
-8
@@ -5010,6 +5010,18 @@ static int diff_opt_ignore_submodules(const struct option *opt,
5010
return 0;
5011
}
5012
5013
+static int diff_opt_line_prefix(const struct option *opt,
5014
+ const char *optarg, int unset)
5015
+{
5016
+ struct diff_options *options = opt->value;
5017
+
5018
+ BUG_ON_OPT_NEG(unset);
5019
+ options->line_prefix = optarg;
5020
+ options->line_prefix_length = strlen(options->line_prefix);
5021
+ graph_setup_line_prefix(options);
5022
+ return 0;
5023
+}
5024
+
5025
static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,
5026
const struct option *opt,
5027
const char *arg, int unset)
@@ -5261,6 +5273,9 @@ static void prep_parse_options(struct diff_options *options)
5273
OPT_STRING_F(0, "dst-prefix", &options->b_prefix, N_("<prefix>"),
5274
N_("show the given source prefix instead of \"b/\""),
5275
PARSE_OPT_NONEG),
5276
+ OPT_CALLBACK_F(0, "line-prefix", options, N_("<prefix>"),
5277
+ N_("prepend an additional prefix to every line of output"),
5278
+ PARSE_OPT_NONEG, diff_opt_line_prefix),
5279
OPT_CALLBACK_F(0, "output-indicator-new",
5280
&options->output_indicators[OUTPUT_INDICATOR_NEW],
5281
N_("<char>"),
@@ -5418,8 +5433,6 @@ int diff_opt_parse(struct diff_options *options,
5433
const char **av, int ac, const char *prefix)
5434
{
5435
const char *arg = av[0];
5421
- const char *optarg;
5422
- int argcount;
5436
5437
if (!prefix)
5438
prefix = "";
@@ -5455,12 +5468,6 @@ int diff_opt_parse(struct diff_options *options,
5468
}
5469
5470
/* misc options */
5458
- else if ((argcount = parse_long_opt("line-prefix", av, &optarg))) {
5459
- options->line_prefix = optarg;
5460
- options->line_prefix_length = strlen(options->line_prefix);
5461
- graph_setup_line_prefix(options);
5462
- return argcount;
5463
- }
5471
else if (!strcmp(arg, "--no-prefix"))
5472
options->a_prefix = options->b_prefix = "";
5473
else if (opt_arg(arg, '\0', "inter-hunk-context",