diff-parseopt: convert --inter-hunk-context

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 16ed6c97cc6cc3de2637e9df8bb057e1254667c9
2 files changed +5 -48
diff.c
+3 -47
@@ -4573,50 +4573,6 @@ void diff_setup_done(struct diff_options *options)
4573 FREE_AND_NULL(options->parseopts);
4574 }
4575
4576 -static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *val)
4577 -{
4578 - char c, *eq;
4579 - int len;
4580 -
4581 - if (*arg != '-')
4582 - return 0;
4583 - c = *++arg;
4584 - if (!c)
4585 - return 0;
4586 - if (c == arg_short) {
4587 - c = *++arg;
4588 - if (!c)
4589 - return 1;
4590 - if (val && isdigit(c)) {
4591 - char *end;
4592 - int n = strtoul(arg, &end, 10);
4593 - if (*end)
4594 - return 0;
4595 - *val = n;
4596 - return 1;
4597 - }
4598 - return 0;
4599 - }
4600 - if (c != '-')
4601 - return 0;
4602 - arg++;
4603 - eq = strchrnul(arg, '=');
4604 - len = eq - arg;
4605 - if (!len || strncmp(arg, arg_long, len))
4606 - return 0;
4607 - if (*eq) {
4608 - int n;
4609 - char *end;
4610 - if (!isdigit(*++eq))
4611 - return 0;
4612 - n = strtoul(eq, &end, 10);
4613 - if (*end)
4614 - return 0;
4615 - *val = n;
4616 - }
4617 - return 1;
4618 -}
4619 -
4576 int parse_long_opt(const char *opt, const char **argv,
4577 const char **optarg)
4578 {
@@ -5291,6 +5247,9 @@ static void prep_parse_options(struct diff_options *options)
5247 OPT_CALLBACK_F(0, "no-prefix", options, NULL,
5248 N_("do not show any source or destination prefix"),
5249 PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_no_prefix),
5250 + OPT_INTEGER_F(0, "inter-hunk-context", &options->interhunkcontext,
5251 + N_("show context between diff hunks up to the specified number of lines"),
5252 + PARSE_OPT_NONEG),
5253 OPT_CALLBACK_F(0, "output-indicator-new",
5254 &options->output_indicators[OUTPUT_INDICATOR_NEW],
5255 N_("<char>"),
@@ -5483,9 +5442,6 @@ int diff_opt_parse(struct diff_options *options,
5442 }
5443
5444 /* misc options */
5486 - else if (opt_arg(arg, '\0', "inter-hunk-context",
5487 - &options->interhunkcontext))
5488 - ;
5445 else
5446 return 0;
5447 return 1;
parse-options.h
+2 -1
@@ -137,6 +137,7 @@ struct option {
137 #define OPT_CALLBACK_F(s, l, v, a, h, f, cb) \
138 { OPTION_CALLBACK, (s), (l), (v), (a), (h), (f), (cb) }
139 #define OPT_STRING_F(s, l, v, a, h, f) { OPTION_STRING, (s), (l), (v), (a), (h), (f) }
140 +#define OPT_INTEGER_F(s, l, v, h, f) { OPTION_INTEGER, (s), (l), (v), N_("n"), (h), (f) }
141
142 #define OPT_END() { OPTION_END }
143 #define OPT_ARGUMENT(l, h) { OPTION_ARGUMENT, 0, (l), NULL, NULL, \
@@ -155,7 +156,7 @@ struct option {
156 (h), PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1}
157 #define OPT_CMDMODE(s, l, v, h, i) { OPTION_CMDMODE, (s), (l), (v), NULL, \
158 (h), PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, (i) }
158 -#define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), N_("n"), (h) }
159 +#define OPT_INTEGER(s, l, v, h) OPT_INTEGER_F(s, l, v, h, 0)
160 #define OPT_MAGNITUDE(s, l, v, h) { OPTION_MAGNITUDE, (s), (l), (v), \
161 N_("n"), (h), PARSE_OPT_NONEG }
162 #define OPT_STRING(s, l, v, a, h) OPT_STRING_F(s, l, v, a, h, 0)