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

Re: [PATCH 4/4] parse-options: clarify PARSE_OPT_NONEG does not reject negative numbers

From
Michael Montalbo <mmontalbo@gmail.com>
Date
May 10, 2026, 02:41 UTC
Message-ID
<CAC2QwmLH19+LHNaP=13c9Ov8x1zXvyDmEhN69_RpbOY+OqEVZA@mail.gmail.com>
In-Reply-To
<xmqq8q9sb5uc.fsf@gitster.g>
On Sat, May 9, 2026 at 3:01 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 17 quoted lines
>
> "Michael Montalbo via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > From: Michael Montalbo <mmontalbo@gmail.com>
> >
> > The name "NONEG" can be misread as "no negative [values]" when it
> > actually means "no [boolean] negation" (the --no-* form).
> >
> > When --inter-hunk-context and -U/--unified were converted from a
> > custom parser to OPT_INTEGER_F with PARSE_OPT_NONEG in d473e2e0e8
> > and 16ed6c97cc, the implicit rejection of negative values (via
> > isdigit() in the old opt_arg() parser) was silently lost. The
> > previous commits in this series fix the resulting bugs.
>
> I do not think _NONEG has anything to do with the bug.  It was
> purely to reject --no-unified and --no-inter-hunk-context.
>
You are right this was a mistaken assumption on my part.
> And there was no change to remove PARSE_OPT_NONEG from anywhere and
> use OPT_UNSIGNED instead to fix any of the bugs fixed in this
> series, ...
>

Right, PARSE_OPT_NONEG is still enabled implicitly by OPT_UNSIGNED so PARSE_OPT_NONEG really has no part in the story.

Show 26 quoted lines
> >
> > Add a clarifying note to the flag documentation.
> >
> > Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
> > ---
> >  parse-options.h | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/parse-options.h b/parse-options.h
> > index 706de9729f..c0a3a3dcae 100644
> > --- a/parse-options.h
> > +++ b/parse-options.h
> > @@ -116,7 +116,10 @@ typedef int parse_opt_subcommand_fn(int argc, const char **argv,
> >   *   mask of parse_opt_option_flags.
> >   *   PARSE_OPT_OPTARG: says that the argument is optional (not for BOOLEANs)
> >   *   PARSE_OPT_NOARG: says that this option does not take an argument
> > - *   PARSE_OPT_NONEG: says that this option cannot be negated
> > + *   PARSE_OPT_NONEG: says that this option cannot be negated (i.e.
> > + *                   prevents --no-<option> boolean form). Does not reject
> > + *                   negative numeric values like --option=-1. Use
> > + *                   OPT_UNSIGNED for options that must be non-negative.
>
> ... I do not think the two additional sentences are warranted.  Stop
> at clarifying what negated _means_ (i.e., rejects "--no-<option>"),
> without adding what negated does _not_ mean.
>
Ok, will remove the latter portion of the change in a follow-up.
>
> >   *   PARSE_OPT_HIDDEN: this option is skipped in the default usage, and
> >   *                     shown only in the full usage.
> >   *   PARSE_OPT_LASTARG_DEFAULT: says that this option will take the default
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 15 in “diff: reject negative context values”
  1. 0/4 diff: reject negative context valuesMichael Montalbo via GitGitGadget, May 5, 2026
  2. 1/4 diff: reject negative values for --inter-hunk-contextMichael Montalbo via GitGitGadget, May 5, 2026
  3. 2/4 diff: reject negative values for -U/--unifiedMichael Montalbo via GitGitGadget, May 5, 2026
  4. 3/4 xdiff: guard against negative context lengthsMichael Montalbo via GitGitGadget, May 5, 2026
  5. 4/4 parse-options: clarify PARSE_OPT_NONEG does not reject negative numbersMichael Montalbo via GitGitGadget, May 5, 2026
  6. Junio C HamanoMay 9, 2026
  7. Michael MontalboMay 10, 2026
  8. Junio C HamanoMay 10, 2026
  9. Michael MontalboMay 10, 2026
  10. 0/4 diff: reject negative context valuesMichael Montalbo via GitGitGadget, May 12, 2026
  11. 1/4 diff: reject negative values for --inter-hunk-contextMichael Montalbo via GitGitGadget, May 12, 2026
  12. 2/4 diff: reject negative values for -U/--unifiedMichael Montalbo via GitGitGadget, May 12, 2026
  13. 3/4 xdiff: guard against negative context lengthsMichael Montalbo via GitGitGadget, May 12, 2026
  14. 4/4 parse-options: clarify what "negated" means for PARSE_OPT_NONEGMichael Montalbo via GitGitGadget, May 12, 2026
  15. Junio C HamanoMay 13, 2026

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.