From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: Git List <git@vger.kernel.org>
Subject: Re: [PATCH] parse-options: disallow negating OPTION_SET_INT 0
Date: Tue, 08 Aug 2023 16:52:41 -0700 [thread overview]
Message-ID: <xmqqh6p96qie.fsf@gitster.g> (raw)
In-Reply-To: <c4cd1591-3a83-920a-6a80-19ffbfe3089d@web.de> ("René Scharfe"'s message of "Tue, 8 Aug 2023 22:05:57 +0200")
René Scharfe <l.s.r@web.de> writes:
> An option of type OPTION_SET_INT can be defined to set its variable to
> zero. It's negated variant will do the same, though, which is
> confusing. Several such options were fixed by disabling negation,
> changing the value to set or using a different option type:
>
> 991c552916 (ls-tree: fix --no-full-name, 2023-07-18)
> e12cb98e1e (branch: reject "--no-all" and "--no-remotes" early, 2023-07-18)
> 68cbb20e73 (show-branch: reject --[no-](topo|date)-order, 2023-07-19)
> 3821eb6c3d (reset: reject --no-(mixed|soft|hard|merge|keep) option, 2023-07-19)
> 36f76d2a25 (pack-objects: fix --no-quiet, 2023-07-21)
> 3a5f308741 (pack-objects: fix --no-keep-true-parents, 2023-07-21)
> c95ae3ff9c (describe: fix --no-exact-match, 2023-07-21)
> d089a06421 (bundle: use OPT_PASSTHRU_ARGV, 2023-07-29)
>
> Check for such options that allow negation in parse_options_check() and
> report them to find future cases quicker.
That does make quite a lot of sense, and parse_options_check() is
the perfect place to do so.
Thanks.
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
> parse-options.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/parse-options.c b/parse-options.c
> index 87c9fae634..60224cf8d0 100644
> --- a/parse-options.c
> +++ b/parse-options.c
> @@ -480,6 +480,9 @@ static void parse_options_check(const struct option *opts)
> opts->long_name))
> optbug(opts, "uses feature "
> "not supported for dashless options");
> + if (opts->type == OPTION_SET_INT && !opts->defval &&
> + opts->long_name && !(opts->flags & PARSE_OPT_NONEG))
> + optbug(opts, "OPTION_SET_INT 0 should not be negatable");
> switch (opts->type) {
> case OPTION_COUNTUP:
> case OPTION_BIT:
> --
> 2.41.0
prev parent reply other threads:[~2023-08-08 23:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-08 20:05 [PATCH] parse-options: disallow negating OPTION_SET_INT 0 René Scharfe
2023-08-08 23:52 ` Junio C Hamano [this message]
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=xmqqh6p96qie.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=l.s.r@web.de \
/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).