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>
This commit is contained in:
parent
11c659d890
commit
16ed6c97cc
50
diff.c
50
diff.c
@ -4573,50 +4573,6 @@ void diff_setup_done(struct diff_options *options)
|
||||
FREE_AND_NULL(options->parseopts);
|
||||
}
|
||||
|
||||
static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *val)
|
||||
{
|
||||
char c, *eq;
|
||||
int len;
|
||||
|
||||
if (*arg != '-')
|
||||
return 0;
|
||||
c = *++arg;
|
||||
if (!c)
|
||||
return 0;
|
||||
if (c == arg_short) {
|
||||
c = *++arg;
|
||||
if (!c)
|
||||
return 1;
|
||||
if (val && isdigit(c)) {
|
||||
char *end;
|
||||
int n = strtoul(arg, &end, 10);
|
||||
if (*end)
|
||||
return 0;
|
||||
*val = n;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (c != '-')
|
||||
return 0;
|
||||
arg++;
|
||||
eq = strchrnul(arg, '=');
|
||||
len = eq - arg;
|
||||
if (!len || strncmp(arg, arg_long, len))
|
||||
return 0;
|
||||
if (*eq) {
|
||||
int n;
|
||||
char *end;
|
||||
if (!isdigit(*++eq))
|
||||
return 0;
|
||||
n = strtoul(eq, &end, 10);
|
||||
if (*end)
|
||||
return 0;
|
||||
*val = n;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int parse_long_opt(const char *opt, const char **argv,
|
||||
const char **optarg)
|
||||
{
|
||||
@ -5291,6 +5247,9 @@ static void prep_parse_options(struct diff_options *options)
|
||||
OPT_CALLBACK_F(0, "no-prefix", options, NULL,
|
||||
N_("do not show any source or destination prefix"),
|
||||
PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_no_prefix),
|
||||
OPT_INTEGER_F(0, "inter-hunk-context", &options->interhunkcontext,
|
||||
N_("show context between diff hunks up to the specified number of lines"),
|
||||
PARSE_OPT_NONEG),
|
||||
OPT_CALLBACK_F(0, "output-indicator-new",
|
||||
&options->output_indicators[OUTPUT_INDICATOR_NEW],
|
||||
N_("<char>"),
|
||||
@ -5483,9 +5442,6 @@ int diff_opt_parse(struct diff_options *options,
|
||||
}
|
||||
|
||||
/* misc options */
|
||||
else if (opt_arg(arg, '\0', "inter-hunk-context",
|
||||
&options->interhunkcontext))
|
||||
;
|
||||
else
|
||||
return 0;
|
||||
return 1;
|
||||
|
@ -137,6 +137,7 @@ struct option {
|
||||
#define OPT_CALLBACK_F(s, l, v, a, h, f, cb) \
|
||||
{ OPTION_CALLBACK, (s), (l), (v), (a), (h), (f), (cb) }
|
||||
#define OPT_STRING_F(s, l, v, a, h, f) { OPTION_STRING, (s), (l), (v), (a), (h), (f) }
|
||||
#define OPT_INTEGER_F(s, l, v, h, f) { OPTION_INTEGER, (s), (l), (v), N_("n"), (h), (f) }
|
||||
|
||||
#define OPT_END() { OPTION_END }
|
||||
#define OPT_ARGUMENT(l, h) { OPTION_ARGUMENT, 0, (l), NULL, NULL, \
|
||||
@ -155,7 +156,7 @@ struct option {
|
||||
(h), PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1}
|
||||
#define OPT_CMDMODE(s, l, v, h, i) { OPTION_CMDMODE, (s), (l), (v), NULL, \
|
||||
(h), PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, (i) }
|
||||
#define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), N_("n"), (h) }
|
||||
#define OPT_INTEGER(s, l, v, h) OPT_INTEGER_F(s, l, v, h, 0)
|
||||
#define OPT_MAGNITUDE(s, l, v, h) { OPTION_MAGNITUDE, (s), (l), (v), \
|
||||
N_("n"), (h), PARSE_OPT_NONEG }
|
||||
#define OPT_STRING(s, l, v, a, h) OPT_STRING_F(s, l, v, a, h, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user