git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] commit-tree: utilize parse-options api

From
Brandon Richardson <brandon1024.br@gmail.com>
Date
Mar 2, 2019, 03:29 UTC
Message-ID
<CAETBDP6oX=NtiOux=5_5t3cj8Vb2QFyfTPmj1h4dOW2oa-hurA@mail.gmail.com>
In-Reply-To
<20190301190954.GG30847@sigill.intra.peff.net>
On Fri, Mar 1, 2019 at 2:09 PM Jeff King <peff@peff.net> wrote:
Show 25 quoted lines
> I think you want an "OR". Or even separate conditions, since really this
> is just implying OPT_NEG(). In fact, you could implement and explain it
> like this:
>
> diff --git a/parse-options.h b/parse-options.h
> index 14fe32428e..d46f89305c 100644
> --- a/parse-options.h
> +++ b/parse-options.h
> @@ -202,6 +202,18 @@ const char *optname(const struct option *opt, int flags);
>                 BUG("option callback does not expect an argument"); \
>  } while (0)
>
> +/*
> + * Similar to the assertions above, but checks that "arg" is always non-NULL.
> + * I.e., that we expect the NOARG and OPTARG flags _not_ to be set. Since
> + * negation is the other common cause of a NULL arg, this also implies
> + * BUG_ON_OPT_NEG(), letting you declare both assertions in a single line.
> + */
> +#define BUG_ON_OPT_NOARG(unset, arg) do { \
> +       BUG_ON_OPT_NEG(unset); \
> +       if (!(arg)) \
> +               BUG("option callback require an argument"); \
> +} while (0)
> +
>  /*----- incremental advanced APIs -----*/

Ahh yes. I had originally used ((!unset) || (!arg)), and second guessed myself before I submitted v2. However, I much prefer your solution which reuses BUG_ON_OPT_NEG(). I'll switch to that :-)

Brandon
Previous: Brandon Richardson
Message 5 of 5 in “commit-tree: utilize parse-options api”
  1. commit-tree: utilize parse-options apiBrandon Richardson, Mar 1, 2019
  2. Jeff KingMar 1, 2019
  3. Eric SunshineMar 1, 2019
  4. Brandon RichardsonMar 2, 2019
  5. Brandon RichardsonMar 2, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.