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

Re: [PATCH v3 3/4] parse-options: add early_scan_options()

From
Christian Couder <christian.couder@gmail.com>
Date
Nov 2, 2026, 15:25 UTC
Message-ID
<CAP8UFD1P1=HhuiKEDjBKdjauKUbeBYG6gT2_WZfq0qh93MN-LQ@mail.gmail.com>
In-Reply-To
<6782fa63-1e46-4ae9-b129-a157986c2556@gmail.com>

On Fri, Oct 30, 2026 at 10:27 PM Kaartic Sivaraam <kaartic.sivaraam@gmail.com> wrote:

>
> On 10/12/26 13:14, Christian Couder wrote:
Show 13 quoted lines
> > @@ -763,6 +765,8 @@ static void parse_options_check(const struct option *opts)
> >               case OPTION_SUBCOMMAND:
> >                       if (!opts->value || !opts->subcommand_fn)
> >                               optbug(opts, "OPTION_SUBCOMMAND needs a value and a subcommand function");
> > +                     if (opts->flags & PARSE_OPT_EARLY)
> > +                             optbug(opts, "OPTION_SUBCOMMAND does not support PARSE_OPT_EARLY");
> >                       if (!subcommand_value)
> >                               subcommand_value = opts->value;
> >                       else if (subcommand_value != opts->value)
>
> Would it make sense to also have these validations within
> early_scan_options() just in case it is called before
> parse_options_start() is invoked?

Yeah, I think it's cheap and simple enough to just call parse_options_check() from early_scan_options(), so I have added that call in the v4 I just sent.

Show 9 quoted lines
> > +/*
> > + * Called by early_scan_options() for each argument matching a
> > + * `struct option` with PARSE_OPT_EARLY set.
> > + *
> > + * - `option` is the matching option,
>
> Would it be helpful to also convey here that the caller is not expected
> to retain the pointer as the memory pointing to it would be freed once
> the scan completes?
Yeah, it looks like this in v4:
 * - `option` is the matching option, (may point into a temporary
 *   copy of the options, so must not be used after the scan,)
Thanks.
Previous: Kaartic SivaraamNext: Christian Couder
Message 30 of 41 in “Standardize early option scanning to fix argument parsing bugs”
  1. 0/6 Standardize early option scanning to fix argument parsing bugsChristian Couder, Sep 2, 2026
  2. 1/6 parse-options: add early_scan_options()Christian Couder, Sep 2, 2026
  3. Junio C HamanoSep 2, 2026
  4. Christian CouderSep 23, 2026
  5. Junio C HamanoSep 23, 2026
  6. 2/6 bisect: fix "--" detection when a term name is "--"Christian Couder, Sep 2, 2026
  7. Junio C HamanoSep 2, 2026
  8. Christian CouderSep 23, 2026
  9. Junio C HamanoSep 23, 2026
  10. 3/6 rev-parse: fix "--" detection when it is an option valueChristian Couder, Sep 2, 2026
  11. 4/6 parse-options: add parse_options_takes_argument()Christian Couder, Sep 2, 2026
  12. 5/6 parse-options: build early scan options from a struct option arrayChristian Couder, Sep 2, 2026
  13. 6/6 fast-import: use early_scan_options() for --allow-unsafe-featuresChristian Couder, Sep 2, 2026
  14. Junio C HamanoSep 4, 2026
  15. Junio C HamanoSep 2, 2026
  16. Christian CouderSep 23, 2026
  17. 0/3 Standardize early option scanningChristian Couder, Sep 23, 2026
  18. 1/3 parse-options: add parse_options_takes_argument()Christian Couder, Sep 23, 2026
  19. 2/3 parse-options: add early_scan_options()Christian Couder, Sep 23, 2026
  20. Kaartic SivaraamSep 30, 2026
  21. Christian CouderOct 12, 2026
  22. 3/3 fast-import: use early_scan_options() for --allow-unsafe-featuresChristian Couder, Sep 23, 2026
  23. 0/4 Standardize early option scanningChristian Couder, Oct 12, 2026
  24. 1/4 parse-options: add parse_options_takes_argument()Christian Couder, Oct 12, 2026
  25. 2/4 parse-options: extract lookup_long_opt() from parse_long_opt()Christian Couder, Oct 12, 2026
  26. Kaartic SivaraamOct 30, 2026
  27. Christian CouderNov 2, 2026
  28. 3/4 parse-options: add early_scan_options()Christian Couder, Oct 12, 2026
  29. Kaartic SivaraamOct 30, 2026
  30. Christian CouderNov 2, 2026
  31. 4/4 fast-import: use early_scan_options() for --allow-unsafe-featuresChristian Couder, Oct 12, 2026
  32. Cynthia UcheOct 31, 2026
  33. Christian CouderNov 2, 2026
  34. Kaartic SivaraamOct 30, 2026
  35. 0/4 Standardize early option scanningChristian Couder, Nov 2, 2026
  36. 1/4 parse-options: add parse_options_takes_argument()Christian Couder, Nov 2, 2026
  37. 2/4 parse-options: extract lookup_long_opt() from parse_long_opt()Christian Couder, Nov 2, 2026
  38. 3/4 parse-options: add early_scan_options()Christian Couder, Nov 2, 2026
  39. 4/4 fast-import: use early_scan_options() for --allow-unsafe-featuresChristian Couder, Nov 2, 2026
  40. Kaartic SivaraamNov 3, 2026
  41. Junio C HamanoNov 3, 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.