Skip to content

Commit 7fa7011

Browse files
peffgitster
authored andcommitted
merge: simplify parsing of "-n" option
The "-n" option is implemented by an option callback, as it is really a "reverse bool". If given, it sets show_diffstat to 0. In theory, when negated, it would set the same flag to 1. But it's not possible to trigger that, since short options cannot be negated. So in practice this is really just a SET_INT to 0. Let's use that instead, which shortens the code. Note that negation here would do the wrong thing (as with any SET_INT with a value of "0"). We could specify PARSE_OPT_NONEG to future-proof ourselves against somebody adding a long option name (which would make it possible to negate). But there's not much point: 1. Nobody is going to do that, because the negated form already exists, and is called "--stat" (which is defined separately so that "--no-stat" works). 2. If they did, the BUG() check added by 3284b93 (parse-options: disallow negating OPTION_SET_INT 0, 2023-08-08) will catch it (and that check is smart enough to realize that our short-only option is OK). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dee02da commit 7fa7011

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

builtin/merge.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,18 +241,9 @@ static int option_parse_strategy(const struct option *opt,
241241
return 0;
242242
}
243243

244-
static int option_parse_n(const struct option *opt,
245-
const char *arg, int unset)
246-
{
247-
BUG_ON_OPT_ARG(arg);
248-
show_diffstat = unset;
249-
return 0;
250-
}
251-
252244
static struct option builtin_merge_options[] = {
253-
OPT_CALLBACK_F('n', NULL, NULL, NULL,
254-
N_("do not show a diffstat at the end of the merge"),
255-
PARSE_OPT_NOARG, option_parse_n),
245+
OPT_SET_INT('n', NULL, &show_diffstat,
246+
N_("do not show a diffstat at the end of the merge"), 0),
256247
OPT_BOOL(0, "stat", &show_diffstat,
257248
N_("show a diffstat at the end of the merge")),
258249
OPT_BOOL(0, "summary", &show_diffstat, N_("(synonym to --stat)")),

0 commit comments

Comments
 (0)