From: Brandon Richardson <brandon1024.br@gmail.com>
To: Jeff King <peff@peff.net>
Cc: Duy Nguyen <pclouds@gmail.com>, Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH] commit-tree: utilize parse-options api
Date: Wed, 27 Feb 2019 22:46:49 -0400 [thread overview]
Message-ID: <CAETBDP42djjmSXeLig6mcRJVR0YMPnDUfCJT4z8SU==Ei62N4w@mail.gmail.com> (raw)
In-Reply-To: <20190227163522.GA25188@sigill.intra.peff.net>
Hi Jeff,
> One of the reasons I did not bother with that condition when I added the
> OPT_NEG() and OPT_ARG() variants is that you can only get an unexpected
> NULL argument if you explicitly give the NOARG or OPTARG flags. So it's
> very easy to _forget_ to give such a flag, because you simply aren't
> thinking about that case, and your callback is buggy by default.
>
> But it's rare to actually think to give one of those flags, but then
> forget to handle it in your callback.
>
> So I'm not entirely opposed, but it does feel weird to add such a macro
> without then using it in the 99% of callbacks which expect arg to be
> non-NULL.
I'd like to agree with you here, especially given that commit-tree is a rather
small part of project source. Experimenting with it a bit, I found using
BUG_ON_OPT_NOARG() to be a big clunky. Like you said, we could
end up with some less-than-ideal usage. If I were to use this in commit-tree,
it would look something like this, which isn't very appealing:
static int callback(const struct option *opt, const char *arg, int unset)
{
...
BUG_ON_OPT_NEG(unset);
BUG_ON_OPT_NO_ARG(arg);
...
However, I do still see a use case for a new macro for options that cannot
be unset and arguments that must not be NULL.
> If we are going to go this route, I think you might actually want macros
> that take both "unset" and "args" and make sure that we're not in a
> situation the callback doesn't expect (e.g., "!unset && !arg"). That
> lets us continue to declare those at the top of the callback.
In doing a quick search, I found a fair number instances of this:
...
BUG_ON_OPT_NEG(unset);
if (!arg)
return -1;
...
So a macro like this could be useful. I've also found a few instances of this:
BUG_ON_OPT_NEG(unset);
BUG_ON_OPT_ARG(arg);
Perhaps two new macros BUG_ON_OPT_NEG_NO_ARG() ("!unset || !arg")
and BUG_ON_OPT_NEG_ARG() ("!unset || arg")? I'm not a big fan of those
names though.
Brandon
next prev parent reply other threads:[~2019-02-28 2:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-26 20:09 [PATCH] commit-tree: utilize parse-options api Brandon
2019-02-26 22:38 ` Andrei Rybak
2019-02-26 23:42 ` Brandon Richardson
2019-02-27 11:13 ` Duy Nguyen
2019-02-27 11:07 ` Duy Nguyen
2019-02-27 11:37 ` SZEDER Gábor
2019-02-27 11:49 ` Duy Nguyen
2019-02-27 12:36 ` SZEDER Gábor
2019-02-28 7:21 ` Duy Nguyen
2019-02-27 15:24 ` Brandon Richardson
2019-02-28 7:26 ` Duy Nguyen
2019-02-27 16:35 ` Jeff King
2019-02-28 2:46 ` Brandon Richardson [this message]
2019-02-28 20:56 ` 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='CAETBDP42djjmSXeLig6mcRJVR0YMPnDUfCJT4z8SU==Ei62N4w@mail.gmail.com' \
--to=brandon1024.br@gmail.com \
--cc=git@vger.kernel.org \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).