Skip to content

Commit 16ed6c9

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent 11c659d commit 16ed6c9

File tree

2 files changed

+5
-48
lines changed

2 files changed

+5
-48
lines changed

diff.c

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4573,50 +4573,6 @@ void diff_setup_done(struct diff_options *options)
45734573
FREE_AND_NULL(options->parseopts);
45744574
}
45754575

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-
46204576
int parse_long_opt(const char *opt, const char **argv,
46214577
const char **optarg)
46224578
{
@@ -5291,6 +5247,9 @@ static void prep_parse_options(struct diff_options *options)
52915247
OPT_CALLBACK_F(0, "no-prefix", options, NULL,
52925248
N_("do not show any source or destination prefix"),
52935249
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),
52945253
OPT_CALLBACK_F(0, "output-indicator-new",
52955254
&options->output_indicators[OUTPUT_INDICATOR_NEW],
52965255
N_("<char>"),
@@ -5483,9 +5442,6 @@ int diff_opt_parse(struct diff_options *options,
54835442
}
54845443

54855444
/* misc options */
5486-
else if (opt_arg(arg, '\0', "inter-hunk-context",
5487-
&options->interhunkcontext))
5488-
;
54895445
else
54905446
return 0;
54915447
return 1;

parse-options.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ struct option {
137137
#define OPT_CALLBACK_F(s, l, v, a, h, f, cb) \
138138
{ OPTION_CALLBACK, (s), (l), (v), (a), (h), (f), (cb) }
139139
#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) }
140141

141142
#define OPT_END() { OPTION_END }
142143
#define OPT_ARGUMENT(l, h) { OPTION_ARGUMENT, 0, (l), NULL, NULL, \
@@ -155,7 +156,7 @@ struct option {
155156
(h), PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1}
156157
#define OPT_CMDMODE(s, l, v, h, i) { OPTION_CMDMODE, (s), (l), (v), NULL, \
157158
(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)
159160
#define OPT_MAGNITUDE(s, l, v, h) { OPTION_MAGNITUDE, (s), (l), (v), \
160161
N_("n"), (h), PARSE_OPT_NONEG }
161162
#define OPT_STRING(s, l, v, a, h) OPT_STRING_F(s, l, v, a, h, 0)

0 commit comments

Comments
 (0)