Re: [PATCH v4] rev-list: handle arguments in early option scan
- From
- Azuama Odinaka Maximus <azuama69@gmail.com>
- Date
- Nov 6, 2026, 13:25 UTC
- Message-ID
- <CAPki72HBWEP8t9mu1zuKBA33SU1Oj-4bL4SQTqrn0G-H0P+g=g@mail.gmail.com>
- In-Reply-To
- <xmqqwlqqokxr.fsf@gitster.g>
I've investigated the relevant parsing paths further:
1. Revision options are handled by handle_revision_opt() in revision.c. It already determines argument consumption through helpers such as parse_long_opt(), which returns whether an option uses an attached or separate argument. However, the function also applies the option's effects to struct rev_info, so calling it again purely to determine argument consumption would be unsafe.
2. Revision pseudo-options are handled separately by handle_revision_pseudo_opt().
3. Diff-merge options are handled by diff_merges_parse_opts() in diff-merges.c.
4. Diff options are defined through add_diff_options() in diff.c, which provides an existing struct option table. This includes options such as --src-prefix and --dst-prefix.
This suggests that the early scan needs to obtain argument-consumption information from the same option definitions or recognition logic used by normal parsing, rather than maintaining another list of option names.
One direction I'm considering is separating option recognition and argument consumption from option application, so that the early scan and normal parser can share the recognition logic without executing parsing side effects twice.
I have not settled on the implementation yet, particularly how best to accommodate the hand-written revision and diff-merge parsers alongside the diff option table.
Would you consider this a reasonable direction? Or do you see an existing Git parser interface or abstraction that would be preferable to extend for this purpose?
Thanks again for the guidance.
On Fri, 6 Nov 2026 at 01:36, Junio C Hamano <gitster@pobox.com> wrote:
Show 68 quoted lines
>
> Azuama Odinaka Maximus <azuama69@gmail.com> writes:
>
> > The early option scan in cmd_rev_list() looks for options that
> > affect missing-object handling before setup_revisions() parses the
> > command line. It must not interpret an option's separate argument
> > as another option.
> >
> > Use parse_long_opt() to recognize revision options that take
> > separate arguments, and skip those arguments. Handle -n and
> > --default as well. Stop scanning at --, where subsequent arguments
> > are pathspecs.
> >
> > Add tests to ensure that --grep and --author arguments beginning
> > with -- are not mistaken for options during the early scan.
>
> The commit log message explains the motivation well, and the attempt
> to address the feedback from the previous round by handling all 19
> options from revision.c is appreciated.
>
> But the approach of hardcoding an array of option strings that take
> arguments is inherently fragile and scales poorly. By duplicating
> parser knowledge into the early scan, this patch falls into the
> exact trap described by the NEEDSWORK comment just below it.
>
> > diff --git a/builtin/rev-list.c b/builtin/rev-list.c
> > index 071a0e3cb5..4dd646050a 100644
> > --- a/builtin/rev-list.c
> > +++ b/builtin/rev-list.c
> > @@ -744,6 +744,47 @@ static void prepare_maximal_independent(struct rev_info *revs)
> > revs->no_walk = 1;
> > }
> >
> > +static int rev_list_option_takes_argument(const char **argv)
> > +{
> > + static const char * const options[] = {
> > + "max-count",
> > + "max-count-oldest",
> > + "skip",
> > + "max-age",
> > + "since",
> > + "since-as-filter",
> > + "after",
> > + "min-age",
> > + "before",
> > + "until",
> > + "date",
> > + "author",
> > + "committer",
> > + "grep-reflog",
> > + "grep",
> > + "encoding",
> > + "glob",
> > + "exclude",
> > + "exclude-hidden",
> > + };
>
> Is this hardcoded list complete? It misses options parsed via
> diff_merges_parse_opts() in diff-merges.c (e.g., --diff-merges), as
> well as options handled in diff.c (e.g., --src-prefix and
> --dst-prefix), which also take separate arguments and are accepted
> by git rev-list. Would
>
> $ git rev-list --src-prefix --missing-only HEAD
>
> take --missing-only as an extra option or a prefix?
>
> Thanks.