Skip to content

Commit a41cfb3

Browse files
pcloudsgitster
authored andcommitted
diff-parseopt: convert -S|-G
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bffee74 commit a41cfb3

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

diff.c

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5056,6 +5056,28 @@ static int diff_opt_patience(const struct option *opt,
50565056
return 0;
50575057
}
50585058

5059+
static int diff_opt_pickaxe_regex(const struct option *opt,
5060+
const char *arg, int unset)
5061+
{
5062+
struct diff_options *options = opt->value;
5063+
5064+
BUG_ON_OPT_NEG(unset);
5065+
options->pickaxe = arg;
5066+
options->pickaxe_opts |= DIFF_PICKAXE_KIND_G;
5067+
return 0;
5068+
}
5069+
5070+
static int diff_opt_pickaxe_string(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+
options->pickaxe = arg;
5077+
options->pickaxe_opts |= DIFF_PICKAXE_KIND_S;
5078+
return 0;
5079+
}
5080+
50595081
static int diff_opt_relative(const struct option *opt,
50605082
const char *arg, int unset)
50615083
{
@@ -5363,6 +5385,12 @@ static void prep_parse_options(struct diff_options *options)
53635385
OPT_SET_INT_F(0, "ita-visible-in-index", &options->ita_invisible_in_index,
53645386
N_("treat 'git add -N' entries as real in the index"),
53655387
0, PARSE_OPT_NONEG),
5388+
OPT_CALLBACK_F('S', NULL, options, N_("<string>"),
5389+
N_("look for differences that change the number of occurrences of the specified string"),
5390+
0, diff_opt_pickaxe_string),
5391+
OPT_CALLBACK_F('G', NULL, options, N_("<regex>"),
5392+
N_("look for differences that change the number of occurrences of the specified regex"),
5393+
0, diff_opt_pickaxe_regex),
53665394
{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
53675395
N_("Output to a specific file"),
53685396
PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5415,15 +5443,6 @@ int diff_opt_parse(struct diff_options *options,
54155443
}
54165444

54175445
/* misc options */
5418-
else if ((argcount = short_opt('S', av, &optarg))) {
5419-
options->pickaxe = optarg;
5420-
options->pickaxe_opts |= DIFF_PICKAXE_KIND_S;
5421-
return argcount;
5422-
} else if ((argcount = short_opt('G', av, &optarg))) {
5423-
options->pickaxe = optarg;
5424-
options->pickaxe_opts |= DIFF_PICKAXE_KIND_G;
5425-
return argcount;
5426-
}
54275446
else if (!strcmp(arg, "--pickaxe-all"))
54285447
options->pickaxe_opts |= DIFF_PICKAXE_ALL;
54295448
else if (!strcmp(arg, "--pickaxe-regex"))

0 commit comments

Comments
 (0)