assert PARSE_OPT_NONEG in parse-options callbacks
In the spirit of 517fe807d6 (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 517fe807d6, 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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Sep 30, 2020 at 08:29 UTC
8d2aa8dfac4048c964453a8983f1dc12ecdfe1c3
4 files changed
+8
builtin/am.c
+2
@@ -2180,6 +2180,8 @@ static int parse_opt_show_current_patch(const struct option *opt, const char *ar
2180
};
2181
int new_value = SHOW_PATCH_RAW;
2182
2183
+ BUG_ON_OPT_NEG(unset);
2184
+
2185
if (arg) {
2186
for (new_value = 0; new_value < ARRAY_SIZE(valid_modes); new_value++) {
2187
if (!strcmp(arg, valid_modes[new_value]))
builtin/commit-graph.c
+2
@@ -128,6 +128,8 @@ static int write_option_parse_split(const struct option *opt, const char *arg,
128
{
129
enum commit_graph_split_flags *flags = opt->value;
130
131
+ BUG_ON_OPT_NEG(unset);
132
+
133
opts.split = 1;
134
if (!arg)
135
return 0;
builtin/env--helper.c
+2
@@ -17,6 +17,8 @@ static int option_parse_type(const struct option *opt, const char *arg,
17
{
18
enum cmdmode *cmdmode = opt->value;
19
20
+ BUG_ON_OPT_NEG(unset);
21
+
22
if (!strcmp(arg, "bool"))
23
*cmdmode = ENV_HELPER_TYPE_BOOL;
24
else if (!strcmp(arg, "ulong"))
parse-options-cb.c
+2
@@ -105,6 +105,8 @@ int parse_opt_commit(const struct option *opt, const char *arg, int unset)
105
struct commit *commit;
106
struct commit **target = opt->value;
107
108
+ BUG_ON_OPT_NEG(unset);
109
+
110
if (!arg)
111
return -1;
112
if (get_oid(arg, &oid))