]> git.ipfire.org Git - thirdparty/git.git/commitdiff
assert PARSE_OPT_NONEG in parse-options callbacks
authorJeff King <peff@peff.net>
Wed, 30 Sep 2020 12:29:02 +0000 (08:29 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 30 Sep 2020 19:53:47 +0000 (12:53 -0700)
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>
builtin/am.c
builtin/commit-graph.c
builtin/env--helper.c
parse-options-cb.c

index 72591864088f5ddd8253aa2ea66503591c183f59..2c7673f74e22761337b67515632d547000049979 100644 (file)
@@ -2180,6 +2180,8 @@ static int parse_opt_show_current_patch(const struct option *opt, const char *ar
        };
        int new_value = SHOW_PATCH_RAW;
 
+       BUG_ON_OPT_NEG(unset);
+
        if (arg) {
                for (new_value = 0; new_value < ARRAY_SIZE(valid_modes); new_value++) {
                        if (!strcmp(arg, valid_modes[new_value]))
index 988445abdfafb6f1c23b146e93f8cf74b46a38e4..78fa08f43af5aaccc05965131ba0b4026c7f7bab 100644 (file)
@@ -128,6 +128,8 @@ static int write_option_parse_split(const struct option *opt, const char *arg,
 {
        enum commit_graph_split_flags *flags = opt->value;
 
+       BUG_ON_OPT_NEG(unset);
+
        opts.split = 1;
        if (!arg)
                return 0;
index 3aa4282114933316d6dae588321ae1816de42bb5..27349098b074f9c3118114ee16f3653f3d61baa2 100644 (file)
@@ -17,6 +17,8 @@ static int option_parse_type(const struct option *opt, const char *arg,
 {
        enum cmdmode *cmdmode = opt->value;
 
+       BUG_ON_OPT_NEG(unset);
+
        if (!strcmp(arg, "bool"))
                *cmdmode = ENV_HELPER_TYPE_BOOL;
        else if (!strcmp(arg, "ulong"))
index d9d3b0819f711ea0db1cfa115832f3b2f616c142..4542d4d3f929f51ce242e6463362307df3ec8d2d 100644 (file)
@@ -105,6 +105,8 @@ int parse_opt_commit(const struct option *opt, const char *arg, int unset)
        struct commit *commit;
        struct commit **target = opt->value;
 
+       BUG_ON_OPT_NEG(unset);
+
        if (!arg)
                return -1;
        if (get_oid(arg, &oid))