diff-parseopt: convert -S|-G
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:19 UTC
a41cfb3203843fe47d902622dcf33db2209a0d1c
1 file changed
+28
-9
diff.c
+28
-9
@@ -5056,6 +5056,28 @@ static int diff_opt_patience(const struct option *opt,
5056
return 0;
5057
}
5058
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
+
5081
static int diff_opt_relative(const struct option *opt,
5082
const char *arg, int unset)
5083
{
@@ -5363,6 +5385,12 @@ static void prep_parse_options(struct diff_options *options)
5385
OPT_SET_INT_F(0, "ita-visible-in-index", &options->ita_invisible_in_index,
5386
N_("treat 'git add -N' entries as real in the index"),
5387
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),
5394
{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
5395
N_("Output to a specific file"),
5396
PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
@@ -5415,15 +5443,6 @@ int diff_opt_parse(struct diff_options *options,
5443
}
5444
5445
/* 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
- }
5446
else if (!strcmp(arg, "--pickaxe-all"))
5447
options->pickaxe_opts |= DIFF_PICKAXE_ALL;
5448
else if (!strcmp(arg, "--pickaxe-regex"))