From: Jeff King <peff@peff.net> To: git@vger.kernel.org Subject: [PATCH 04/10] assert PARSE_OPT_NONEG in parse-options callbacks Date: Wed, 30 Sep 2020 08:29:02 -0400 [thread overview] Message-ID: <20200930122902.GD1901279@coredump.intra.peff.net> (raw) In-Reply-To: <20200930122732.GA1901036@coredump.intra.peff.net> 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> --- builtin/am.c | 2 ++ builtin/commit-graph.c | 2 ++ builtin/env--helper.c | 2 ++ parse-options-cb.c | 2 ++ 4 files changed, 8 insertions(+) diff --git a/builtin/am.c b/builtin/am.c index 7259186408..2c7673f74e 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -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])) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 988445abdf..78fa08f43a 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -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; diff --git a/builtin/env--helper.c b/builtin/env--helper.c index 3aa4282114..27349098b0 100644 --- a/builtin/env--helper.c +++ b/builtin/env--helper.c @@ -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")) diff --git a/parse-options-cb.c b/parse-options-cb.c index d9d3b0819f..4542d4d3f9 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -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)) -- 2.28.0.1173.gad90222cf0
next prev parent reply other threads:[~2020-09-30 12:29 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-09-30 12:27 [PATCH 0/10] dropping more unused parameters Jeff King 2020-09-30 12:27 ` [PATCH 01/10] convert: drop unused crlf_action from check_global_conv_flags_eol() Jeff King 2020-09-30 12:28 ` [PATCH 02/10] drop unused argc parameters Jeff King 2020-09-30 12:28 ` [PATCH 03/10] env--helper: write to opt->value in parseopt helper Jeff King 2020-09-30 12:29 ` Jeff King [this message] 2020-09-30 12:29 ` [PATCH 05/10] push: drop unused repo argument to do_push() Jeff King 2020-09-30 12:29 ` [PATCH 06/10] sequencer: drop repository argument from run_git_commit() Jeff King 2020-09-30 12:30 ` [PATCH 07/10] sparse-checkout: fill in some options boilerplate Jeff King 2020-09-30 12:30 ` [PATCH 08/10] test-advise: check argument count with argc instead of argv Jeff King 2020-09-30 12:34 ` [PATCH 09/10] sequencer: handle ignore_footer when parsing trailers Jeff King 2020-09-30 12:35 ` [PATCH 10/10] dir.c: drop unused "untracked" from treat_path_fast() Jeff King
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200930122902.GD1901279@coredump.intra.peff.net \ --to=peff@peff.net \ --cc=git@vger.kernel.org \ --subject='Re: [PATCH 04/10] assert PARSE_OPT_NONEG in parse-options callbacks' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).