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