Skip to content

Commit 8d2aa8d

Browse files
peffgitster
authored andcommitted
assert PARSE_OPT_NONEG in parse-options callbacks
In the spirit of 517fe80 (assert NOARG/NONEG behavior of parse-options callbacks, 2018-11-05), let's cover some parse-options callbacks which expect to be used with PARSE_OPT_NONEG but don't explicitly assert that this is the case. These callbacks are all used correctly in the current code, but this will help document their expectations and future-proof the code. As a bonus, it also silences -Wunused-parameters (these were added since the initial sweep of 517fe80, and we can't yet turn on -Wunused-parameters to remind people because it has too many existing false positives). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 424e28f commit 8d2aa8d

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

builtin/am.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,6 +2180,8 @@ static int parse_opt_show_current_patch(const struct option *opt, const char *ar
21802180
};
21812181
int new_value = SHOW_PATCH_RAW;
21822182

2183+
BUG_ON_OPT_NEG(unset);
2184+
21832185
if (arg) {
21842186
for (new_value = 0; new_value < ARRAY_SIZE(valid_modes); new_value++) {
21852187
if (!strcmp(arg, valid_modes[new_value]))

builtin/commit-graph.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ static int write_option_parse_split(const struct option *opt, const char *arg,
128128
{
129129
enum commit_graph_split_flags *flags = opt->value;
130130

131+
BUG_ON_OPT_NEG(unset);
132+
131133
opts.split = 1;
132134
if (!arg)
133135
return 0;

builtin/env--helper.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ static int option_parse_type(const struct option *opt, const char *arg,
1717
{
1818
enum cmdmode *cmdmode = opt->value;
1919

20+
BUG_ON_OPT_NEG(unset);
21+
2022
if (!strcmp(arg, "bool"))
2123
*cmdmode = ENV_HELPER_TYPE_BOOL;
2224
else if (!strcmp(arg, "ulong"))

parse-options-cb.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ int parse_opt_commit(const struct option *opt, const char *arg, int unset)
105105
struct commit *commit;
106106
struct commit **target = opt->value;
107107

108+
BUG_ON_OPT_NEG(unset);
109+
108110
if (!arg)
109111
return -1;
110112
if (get_oid(arg, &oid))

0 commit comments

Comments
 (0)