Skip to content

Commit 2f81cf9

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent 31fba9d commit 2f81cf9

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

diff.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5010,6 +5010,18 @@ static int diff_opt_ignore_submodules(const struct option *opt,
50105010
return 0;
50115011
}
50125012

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+
50135025
static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,
50145026
const struct option *opt,
50155027
const char *arg, int unset)
@@ -5261,6 +5273,9 @@ static void prep_parse_options(struct diff_options *options)
52615273
OPT_STRING_F(0, "dst-prefix", &options->b_prefix, N_("<prefix>"),
52625274
N_("show the given source prefix instead of \"b/\""),
52635275
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),
52645279
OPT_CALLBACK_F(0, "output-indicator-new",
52655280
&options->output_indicators[OUTPUT_INDICATOR_NEW],
52665281
N_("<char>"),
@@ -5418,8 +5433,6 @@ int diff_opt_parse(struct diff_options *options,
54185433
const char **av, int ac, const char *prefix)
54195434
{
54205435
const char *arg = av[0];
5421-
const char *optarg;
5422-
int argcount;
54235436

54245437
if (!prefix)
54255438
prefix = "";
@@ -5455,12 +5468,6 @@ int diff_opt_parse(struct diff_options *options,
54555468
}
54565469

54575470
/* 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-
}
54645471
else if (!strcmp(arg, "--no-prefix"))
54655472
options->a_prefix = options->b_prefix = "";
54665473
else if (opt_arg(arg, '\0', "inter-hunk-context",

0 commit comments

Comments
 (0)