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

Re: [PATCH 0/6] Standardize early option scanning to fix argument parsing bugs

From
Christian Couder <christian.couder@gmail.com>
Date
Sep 23, 2026, 08:10 UTC
Message-ID
<CAP8UFD3qUpjUayhkMumZ41iMut=1=Pcmzx1YYcEV9NMG18OPsw@mail.gmail.com>
In-Reply-To
<xmqqpkyviizc.fsf@gitster.g>
On Wed, Sep 2, 2026 at 8:52 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Christian Couder <christian.couder@gmail.com> writes:
Show 13 quoted lines
> > To allow these commands to safely skip option values during their
> > early scans, this series introduces a new "early-scan" sub-API into
> > the existing "parse-options" API.
>
> Yay.
>
> > This is deliberately implemented as a new simple and fast scan, which
> > has some limitations, instead of a full refactor and reuse of the
> > parse_options() code,
>
> Sigh.  In other words, we hate these ad-hoc prescan that are buggy
> badly enough to replace them all with yet another ad-hoc prescan
> that is know to behave differently from the real thing?

Yes, because the limitations of the new scan are not very significant in practice while refactoring the real thing (so that it can perform an early scan without side effects) would be much more complex.

Show 11 quoted lines
> >  - `git bisect start --term-good -- <not-a-rev>` mistook the term name
> >    `--` for the revision/path separator, so <not-a-rev> was rejected
> >    as an invalid revision instead of being treated as a path.
>
> Sorry, I fail to see much practical value in this.
>
> >  - `git rev-parse --default -- <not-a-rev>` did the same, reporting
> >    "bad revision <notarev>" while any other default value gives the
> >    usual more helpful "ambiguous argument" error.
>
> Neither in this one.
I have removed those from the series in the v2 I just sent.
Show 8 quoted lines
> >  - `git fast-import --depth 5 --allow-unsafe-features` silently
> >    ignored `--allow-unsafe-features`, refusing unsafe features from
> >    the stream.
>
> On the other hand, this may be a very good thing.
>
> Is the reason why the ad-hoc pre-scan failed to see it was because
> it did not realize 5 is a value to the --depth option?
Yes.
Show 18 quoted lines
> > All of these commands call parse_options(), but for `git bisect` and
> > `git rev-parse`, the specific functions doing the early scan
> > (bisect_start() and cmd_rev_parse()'s main loop) parse their own
> > options by hand after the early scan and have no `struct option` array
> > for those options.
> >
> > If bisect_start() and cmd_rev_parse() were converted to use
> > `struct option`, they could use early_scan_options_from_options() and
> > would not be affected by limitations 1), 2) and 3) above, as both use
> > the early scan only to locate `--`.
>
> I imagine that in the long term we would rather see a properly
> refactored parse-options machinery perform the prescan (perhaps with
> some kind of "dry-run" option given to the machinery) than yet
> another ad-hoc parser like this topic introduces.  It would be very
> good if this interim solution at least took the same 'options[]'
> array so that when we have the real thing in the future we do not
> have to redo the conversion effort.

This is what is implemented in the v2 I just sent. So yeah, when a refactored parse-options machinery will be able to perform the prescan, we will be able to use it to replace the early-scan parser without changing or converting the callers.

Show 5 quoted lines
> By the way, how does this interact with your other topic that has
> been stalled for quite some time?  Would moving this one forward
> help the other, or do they not have much relevance to each other?  I
> would rather not see two topics of non-trivial size stalled on a
> single author at the same time, so ...

They are separate topics and I alternate between them. I was recently busy with travelling to the Git Merge and was a bit sick before that, but hopefully I should be able to spend more time on them in the next weeks. Also it seems to me that both topics have advanced to a point where not a lot of big changes are needed. So they should move forward quite fast now.

Previous: Junio C HamanoNext: Christian Couder
Message 16 of 21 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. 3/3 fast-import: use early_scan_options() for --allow-unsafe-featuresChristian Couder, Sep 23, 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.