{"thread":{"id":"66622","subject":"[PATCH] rev-list: skip --grep argument in early scan","startedAt":"2026-10-21T15:12:53Z","lastAt":"2026-11-06T18:18:59Z","messageCount":11,"participants":["Azuama Odinaka Maximus","Pushkar Singh","Junio C Hamano","Tanga Joris"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"555746","messageId":"20261021151253.3689-1-azuama69@gmail.com","threadId":"66622","inReplyTo":null,"subject":"[PATCH] rev-list: skip --grep argument in early scan","fromName":"Azuama Odinaka Maximus","fromEmail":"azuama69@gmail.com","sentAt":"2026-10-21T15:12:53Z","receivedAt":"2026-10-21T15:12:53Z","isPatch":true,"sender":{"key":"azuama69@gmail.com","avatar":null},"body":"Signed-off-by: Azuama Odinaka Maximus <azuama69@gmail.com>\n---\n builtin/rev-list.c          | 2 ++\n t/t6022-rev-list-missing.sh | 6 ++++++\n 2 files changed, 8 insertions(+)\n\ndiff --git a/builtin/rev-list.c b/builtin/rev-list.c\nindex 0faa833fac..453d82d25c 100644\n--- a/builtin/rev-list.c\n+++ b/builtin/rev-list.c\n@@ -771,6 +771,8 @@ int cmd_rev_list(int argc,\n \t\t\trevs.exclude_promisor_objects = 1;\n \t\t} else if (skip_prefix(arg, \"--missing=\", &arg)) {\n \t\t\tparse_missing_action_value(repo, arg);\n+\t\t} else if (!strcmp(arg, \"--grep\")) {\n+\t\t\ti++;\n \t\t} else if (!strcmp(arg, \"--missing-only\")) {\n \t\t\targ_missing_only = 1;\n \t\t} else if (!strcmp(arg, \"-z\")) {\ndiff --git a/t/t6022-rev-list-missing.sh b/t/t6022-rev-list-missing.sh\nindex 1bd2c3bc4f..e87678e468 100755\n--- a/t/t6022-rev-list-missing.sh\n+++ b/t/t6022-rev-list-missing.sh\n@@ -215,6 +215,12 @@ do\n \t'\n done\n \n+test_expect_success \"--grep accepts a pattern beginning with --\" '\n+\tgit rev-list --grep=--missing-only --max-count=1 HEAD >expect &&\n+\tgit rev-list --grep --missing-only --max-count=1 HEAD >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success \"--missing-only requires --missing=print or --missing=print-info\" '\n \ttest_must_fail git rev-list --missing-only --objects HEAD 2>err &&\n \ttest_grep \"requires --missing=print\" err\n-- \n2.53.0\n\n\n"},{"id":"555749","messageId":"CALE2CrT=D8P6SksOyBudiF1En+mshxw=vdVU6KLApT0AY_ExsA@mail.gmail.com","threadId":"66622","inReplyTo":"20261021151253.3689-1-azuama69@gmail.com","subject":"Re: [PATCH] rev-list: skip --grep argument in early scan","fromName":"Pushkar Singh","fromEmail":"pushkarkumarsingh1970@gmail.com","sentAt":"2026-10-21T15:42:37Z","receivedAt":"2026-10-21T15:42:37Z","isPatch":true,"sender":{"key":"pushkarkumarsingh1970@gmail.com","avatar":"https://avatars.githubusercontent.com/u/173247767?v=4"},"body":"Hi,\n\nThanks for the patch!\n\nOne thing I noticed is that the commit message doesn't have a description.\nCould you add a bit of context about the issue you're fixing and why this\nchange is needed? It'll make it easier for others to understand the reason\nbehind the patch.\n\n> +               } else if (!strcmp(arg, \"--grep\")) {\n> +                       i++;\n\nAlso, could you check if the first scan needs similar handling? With --grep\n--exclude-promisor-objects, the first scan might treat\n--exclude-promisor-objects\nas an option instead of the pattern argument to --grep. A test for this case\nwould help confirm whether the fix covers both scans.\n\nThanks!\n\n- Pushkar\n\n"},{"id":"555760","messageId":"20261021172458.6373-1-azuama69@gmail.com","threadId":"66622","inReplyTo":"20261021151253.3689-1-azuama69@gmail.com","subject":"[PATCH v2] rev-list: skip --grep argument in early scan","fromName":"Azuama Odinaka Maximus","fromEmail":"azuama69@gmail.com","sentAt":"2026-10-21T17:24:57Z","receivedAt":"2026-10-21T17:24:57Z","isPatch":true,"sender":{"key":"azuama69@gmail.com","avatar":null},"body":"The early option scan in rev-list does not account for options\nthat take a separate argument. As a result, a pattern passed to\n--grep can be mistaken for another option.\n\nSkip the argument to --grep so that it is not interpreted as an\noption during the early scan.\n---\n builtin/rev-list.c          |  2 ++\n t/t6022-rev-list-missing.sh | 11 +++++++++++\n 2 files changed, 13 insertions(+)\n\ndiff --git a/builtin/rev-list.c b/builtin/rev-list.c\nindex 0faa833fac..453d82d25c 100644\n--- a/builtin/rev-list.c\n+++ b/builtin/rev-list.c\n@@ -771,6 +771,8 @@ int cmd_rev_list(int argc,\n \t\t\trevs.exclude_promisor_objects = 1;\n \t\t} else if (skip_prefix(arg, \"--missing=\", &arg)) {\n \t\t\tparse_missing_action_value(repo, arg);\n+\t\t} else if (!strcmp(arg, \"--grep\")) {\n+\t\t\ti++;\n \t\t} else if (!strcmp(arg, \"--missing-only\")) {\n \t\t\targ_missing_only = 1;\n \t\t} else if (!strcmp(arg, \"-z\")) {\ndiff --git a/t/t6022-rev-list-missing.sh b/t/t6022-rev-list-missing.sh\nindex 1bd2c3bc4f..180e6ac766 100755\n--- a/t/t6022-rev-list-missing.sh\n+++ b/t/t6022-rev-list-missing.sh\n@@ -215,6 +215,17 @@ do\n \t'\n done\n \n+test_expect_success \"--grep accepts a pattern beginning with --\" '\n+\tgit rev-list --grep=--missing-only --max-count=1 HEAD >expect &&\n+\tgit rev-list --grep --missing-only --max-count=1 HEAD >actual &&\n+\ttest_cmp expect actual\n+'\n+test_expect_success \"--grep does not trigger --exclude-promisor-objects in early scan\" '\n+    git rev-list --grep=--exclude-promisor-objects --missing=print HEAD >expect &&\n+    git rev-list --grep --exclude-promisor-objects --missing=print HEAD >actual &&\n+    test_cmp expect actual\n+'\n+\n test_expect_success \"--missing-only requires --missing=print or --missing=print-info\" '\n \ttest_must_fail git rev-list --missing-only --objects HEAD 2>err &&\n \ttest_grep \"requires --missing=print\" err\n-- \n2.53.0\n\n\n"},{"id":"555868","messageId":"CALE2CrQuHhP6_p+9iG2SdZn8=V-Oy9oTtBu8xKd7FUyig4zBFg@mail.gmail.com","threadId":"66622","inReplyTo":"20261021172458.6373-1-azuama69@gmail.com","subject":"Re: [PATCH v2] rev-list: skip --grep argument in early scan","fromName":"Pushkar Singh","fromEmail":"pushkarkumarsingh1970@gmail.com","sentAt":"2026-10-22T13:45:38Z","receivedAt":"2026-10-22T13:45:38Z","isPatch":true,"sender":{"key":"pushkarkumarsingh1970@gmail.com","avatar":"https://avatars.githubusercontent.com/u/173247767?v=4"},"body":"Hi Azuma,\n\n>\n> Skip the argument to --grep so that it is not interpreted as an\n> option during the early scan.\n> ---\n\nCan you add a \"Changes in v2\" section after the --- here, summarizing\nwhat changed from the previous version?\nAlso, I noticed the \"Signed-off-by\" line is missing in v2. Could you\nadd it back?\n\nOther than that, it looks good to me.\n\n- Pushkar\n\n"},{"id":"556093","messageId":"xmqqzew45loc.fsf@gitster.g","threadId":"66622","inReplyTo":"20261021172458.6373-1-azuama69@gmail.com","subject":"Re: [PATCH v2] rev-list: skip --grep argument in early scan","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-23T18:14:27Z","receivedAt":"2026-10-23T18:14:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Azuama Odinaka Maximus <azuama69@gmail.com> writes:\n\n> +test_expect_success \"--grep accepts a pattern beginning with --\" '\n> +\tgit rev-list --grep=--missing-only --max-count=1 HEAD >expect &&\n> +\tgit rev-list --grep --missing-only --max-count=1 HEAD >actual &&\n> +\ttest_cmp expect actual\n> +'\n> +test_expect_success \"--grep does not trigger --exclude-promisor-objects in early scan\" '\n> +    git rev-list --grep=--exclude-promisor-objects --missing=print HEAD >expect &&\n> +    git rev-list --grep --exclude-promisor-objects --missing=print HEAD >actual &&\n> +    test_cmp expect actual\n> +'\n\nHave a blank line between tests.\n\nDo these tests truly verify anything beyond \"the command line parser\nis not broken by my commit\"?  There is nothing in the history that\nwould trigger '--missing-only'; there is no positive indication that\nthe pattern starting with \"--\" was used by '--grep' at all.  The only\nclue that '--missing-only' was not taken as a command line option is\nthat the command did not fail due to a lack of '--missing=<how>'.\n\nThe same issue exists in the second added test.\n\nThanks.\n\n"},{"id":"556274","messageId":"20261026083055.18873-1-azuama69@gmail.com","threadId":"66622","inReplyTo":"20261021172458.6373-1-azuama69@gmail.com","subject":"[PATCH v3] rev-list: skip --grep argument in early scan","fromName":"Azuama Odinaka Maximus","fromEmail":"azuama69@gmail.com","sentAt":"2026-10-26T08:30:54Z","receivedAt":"2026-10-26T08:30:54Z","isPatch":true,"sender":{"key":"azuama69@gmail.com","avatar":null},"body":"The early option scan in rev-list does not account for options\nthat take a separate argument. As a result, a pattern passed to\n--grep can be mistaken for another option.\n\nSkip the argument to --grep so that it is not interpreted as an\noption during the early scan.\n\nThe tests check that patterns beginning with \"--\" are actually\nmatched by --grep, including when the pattern resembles an option\nthat the early scan handles specially.\n\nSigned-off-by: Azuama Odinaka Maximus <azuama69@gmail.com>\n---\nChanges in v3:\n- Improve both regression tests to verify that --grep matches the\n  expected commit when its pattern begins with \"--\".\n- Add a blank line between the tests.\n\n builtin/rev-list.c          |  2 ++\n t/t6022-rev-list-missing.sh | 20 ++++++++++++++++++++\n 2 files changed, 22 insertions(+)\n\ndiff --git a/builtin/rev-list.c b/builtin/rev-list.c\nindex 0faa833fac..453d82d25c 100644\n--- a/builtin/rev-list.c\n+++ b/builtin/rev-list.c\n@@ -771,6 +771,8 @@ int cmd_rev_list(int argc,\n \t\t\trevs.exclude_promisor_objects = 1;\n \t\t} else if (skip_prefix(arg, \"--missing=\", &arg)) {\n \t\t\tparse_missing_action_value(repo, arg);\n+\t\t} else if (!strcmp(arg, \"--grep\")) {\n+\t\t\ti++;\n \t\t} else if (!strcmp(arg, \"--missing-only\")) {\n \t\t\targ_missing_only = 1;\n \t\t} else if (!strcmp(arg, \"-z\")) {\ndiff --git a/t/t6022-rev-list-missing.sh b/t/t6022-rev-list-missing.sh\nindex 1bd2c3bc4f..3757bde708 100755\n--- a/t/t6022-rev-list-missing.sh\n+++ b/t/t6022-rev-list-missing.sh\n@@ -215,6 +215,26 @@ do\n \t'\n done\n \n+test_expect_success \"--grep accepts a pattern beginning with --\" '\n+        test_commit --no-tag --missing-only &&\n+        commit=$(git rev-parse HEAD) &&\n+        echo \"$commit\" >expect &&\n+        git rev-list --grep=--missing-only HEAD >actual &&\n+        test_cmp expect actual &&\n+        git rev-list --grep --missing-only HEAD >actual &&\n+        test_cmp expect actual\n+'\n+\n+test_expect_success \"--grep does not trigger --exclude-promisor-objects in early scan\" '\n+        test_commit --no-tag --exclude-promisor-objects &&\n+        commit=$(git rev-parse HEAD) &&\n+        echo \"$commit\" >expect &&\n+        git rev-list --grep=--exclude-promisor-objects --missing=print HEAD >actual &&\n+        test_cmp expect actual &&\n+        git rev-list --grep --exclude-promisor-objects --missing=print HEAD >actual &&\n+        test_cmp expect actual\n+'\n+\n test_expect_success \"--missing-only requires --missing=print or --missing=print-info\" '\n \ttest_must_fail git rev-list --missing-only --objects HEAD 2>err &&\n \ttest_grep \"requires --missing=print\" err\n-- \n2.53.0\n\n\n"},{"id":"557534","messageId":"CAKrRMNrnd2+HxTxadKaha+K9ASWi_oN4h7gdjVYAGmyODwmi=w@mail.gmail.com","threadId":"66622","inReplyTo":"20261026083055.18873-1-azuama69@gmail.com","subject":"Re: [PATCH v3] rev-list: skip --grep argument in early scan","fromName":"Tanga Joris","fromEmail":"tangajoris@gmail.com","sentAt":"2026-11-05T07:53:54Z","receivedAt":"2026-11-05T07:53:54Z","isPatch":true,"sender":{"key":"tangajoris@gmail.com","avatar":null},"body":"Hello Azuama,\n\nThanks for working on this.\n\nI applied v3 on top of master (0ffa3e35c7) with \"git am -3\", because\nbuiltin/rev-list.c has changed since you sent it, so running \"git am\"\nfails. Rebasing on master would help. I built it with NO_RUST=1.\nt6022 passes, and both new tests fail when I revert only the change\nin builtin/rev-list.c, so they do catch the problem.\n\nOn Mon, 26 Oct 2026 at 11:30, Azuama Odinaka Maximus <azuama69@gmail.com> wrote:\n> +test_expect_success \"--grep accepts a pattern beginning with --\" '\n> +        test_commit --no-tag --missing-only &&\n> +        commit=$(git rev-parse HEAD) &&\n\nThese lines are indented with spaces instead of a tab. \"git diff\n--check\" reports \"indent with spaces\" for all the new test lines.\n\n> +             } else if (!strcmp(arg, \"--grep\")) {\n> +                     i++;\n\nThis fixes --grep, but other options that take a separate value\nstill have the same problem. In a repository whose only commit has\n\"--missing-only\" as both its subject and its author name, with this\npatch:\n\n  $ git rev-list --grep --missing-only HEAD\n  <the commit>\n  $ git rev-list --author --missing-only HEAD\n  fatal: --missing-only requires --missing=print or --missing=print-info\n\n--committer and --grep-reflog fail the same way. In revision.c, 19\noptions are parsed with parse_long_opt(), which accepts the value as\na separate argument (--author, --committer, --since, --until, --skip,\n--exclude and others). Should the early scan skip the value of all\nof them, or is there a reason to handle only --grep? If this only fixes\n--grep for now, the commit message could say so, because its first\nparagraph describes the general problem.\n\nAlso, the NEEDSWORK comment just above this loop uses \"--grep\n--exclude-promisor-objects\" as its example of what the loop gets\nwrong. With this patch that example works, so the comment needs a\nnew example (--author would do), or it simply becomes misleading.\n\nThanks,\nTanga\n\n"},{"id":"557539","messageId":"20261105120937.10269-1-azuama69@gmail.com","threadId":"66622","inReplyTo":"CAKrRMNrnd2+HxTxadKaha+K9ASWi_oN4h7gdjVYAGmyODwmi=w@mail.gmail.com","subject":"[PATCH v4] rev-list: handle arguments in early option scan","fromName":"Azuama Odinaka Maximus","fromEmail":"azuama69@gmail.com","sentAt":"2026-11-05T12:09:36Z","receivedAt":"2026-11-05T12:09:36Z","isPatch":true,"sender":{"key":"azuama69@gmail.com","avatar":null},"body":"The early option scan in cmd_rev_list() looks for options that\naffect missing-object handling before setup_revisions() parses the\ncommand line. It must not interpret an option's separate argument\nas another option.\n\nUse parse_long_opt() to recognize revision options that take\nseparate arguments, and skip those arguments. Handle -n and\n--default as well. Stop scanning at --, where subsequent arguments\nare pathspecs.\n\nAdd tests to ensure that --grep and --author arguments beginning\nwith -- are not mistaken for options during the early scan.\n\nSigned-off-by: Azuama Odinaka Maximus <azuama69@gmail.com>\n---\n builtin/rev-list.c          | 55 +++++++++++++++++++++++++++++++++++--\n t/t6022-rev-list-missing.sh | 26 ++++++++++++++++++\n 2 files changed, 78 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/rev-list.c b/builtin/rev-list.c\nindex 071a0e3cb5..4dd646050a 100644\n--- a/builtin/rev-list.c\n+++ b/builtin/rev-list.c\n@@ -744,6 +744,47 @@ static void prepare_maximal_independent(struct rev_info *revs)\n \trevs->no_walk = 1;\n }\n \n+static int rev_list_option_takes_argument(const char **argv)\n+{\n+\tstatic const char * const options[] = {\n+\t\t\"max-count\",\n+\t\t\"max-count-oldest\",\n+\t\t\"skip\",\n+\t\t\"max-age\",\n+\t\t\"since\",\n+\t\t\"since-as-filter\",\n+\t\t\"after\",\n+\t\t\"min-age\",\n+\t\t\"before\",\n+\t\t\"until\",\n+\t\t\"date\",\n+\t\t\"author\",\n+\t\t\"committer\",\n+\t\t\"grep-reflog\",\n+\t\t\"grep\",\n+\t\t\"encoding\",\n+\t\t\"glob\",\n+\t\t\"exclude\",\n+\t\t\"exclude-hidden\",\n+\t};\n+\tconst char *optarg;\n+\tsize_t i;\n+\n+\tif (!argv[1])\n+\t\treturn 0;\n+\n+\tif (!strcmp(argv[0], \"-n\") ||\n+\t    !strcmp(argv[0], \"--default\"))\n+\t\treturn 1;\n+\n+\tfor (i = 0; i < ARRAY_SIZE(options); i++) {\n+\t\tif (parse_long_opt(options[i], argv, &optarg) == 2)\n+\t\t\treturn 1;\n+\t}\n+\n+\treturn 0;\n+}\n+\n int cmd_rev_list(int argc,\n \t\t const char **argv,\n \t\t const char *prefix,\n@@ -789,9 +830,8 @@ int cmd_rev_list(int argc,\n \t * NEEDSWORK: The next loop is utterly broken.  It tries to\n \t * notice an option is used, but without understanding if each\n \t * option takes an argument, which fundamentally would not\n-\t * work.  It would not know \"--grep\n-\t * --exclude-promisor-objects\" is not triggering\n-\t * \"--exclude-promisor-objects\" option, for example.\n+\t * work.  It would not know that \"--author --missing-only\" is not\n+\t * triggering \"--missing-only\" option, for example.\n \t *\n \t * We really need setup_revisions() to have a mechanism to\n \t * allow and disallow some sets of options for different\n@@ -802,6 +842,15 @@ int cmd_rev_list(int argc,\n \t */\n \tfor (i = 1; i < argc; i++) {\n \t\tconst char *arg = argv[i];\n+\n+\t\tif (!strcmp(arg, \"--\"))\n+\t\t\tbreak;\n+\n+\t\tif (rev_list_option_takes_argument(&argv[i])) {\n+\t\t\ti++;\n+\t\t\tcontinue;\n+\t\t}\n+\n \t\tif (!strcmp(arg, \"--exclude-promisor-objects\")) {\n \t\t\trepo->fetch_if_missing = 0;\n \t\t\trevs.exclude_promisor_objects = 1;\ndiff --git a/t/t6022-rev-list-missing.sh b/t/t6022-rev-list-missing.sh\nindex 1bd2c3bc4f..9f995968fd 100755\n--- a/t/t6022-rev-list-missing.sh\n+++ b/t/t6022-rev-list-missing.sh\n@@ -215,6 +215,32 @@ do\n \t'\n done\n \n+test_expect_success \"--grep accepts a pattern beginning with --\" '\n+\ttest_commit --no-tag --missing-only &&\n+\tcommit=$(git rev-parse HEAD) &&\n+\techo \"$commit\" >expect &&\n+\tgit rev-list --grep=--missing-only HEAD >actual &&\n+\ttest_cmp expect actual &&\n+\tgit rev-list --grep --missing-only HEAD >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success \"--grep does not trigger --exclude-promisor-objects in early scan\" '\n+\ttest_commit --no-tag --exclude-promisor-objects &&\n+\tcommit=$(git rev-parse HEAD) &&\n+\techo \"$commit\" >expect &&\n+\tgit rev-list --grep=--exclude-promisor-objects --missing=print HEAD >actual &&\n+\ttest_cmp expect actual &&\n+\tgit rev-list --grep --exclude-promisor-objects --missing=print HEAD >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success \"--author argument is not treated as an option in early scan\" '\n+\ttest_commit --no-tag author-test &&\n+\tgit rev-list --author --missing-only HEAD >actual &&\n+\ttest_must_be_empty actual\n+'\n+\n test_expect_success \"--missing-only requires --missing=print or --missing=print-info\" '\n \ttest_must_fail git rev-list --missing-only --objects HEAD 2>err &&\n \ttest_grep \"requires --missing=print\" err\n-- \n2.56.0.386.g979eb7e29a\n\n\n"},{"id":"557640","messageId":"xmqqwlqqokxr.fsf@gitster.g","threadId":"66622","inReplyTo":"20261105120937.10269-1-azuama69@gmail.com","subject":"Re: [PATCH v4] rev-list: handle arguments in early option scan","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-06T00:36:16Z","receivedAt":"2026-11-06T00:36:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Azuama Odinaka Maximus <azuama69@gmail.com> writes:\n\n> The early option scan in cmd_rev_list() looks for options that\n> affect missing-object handling before setup_revisions() parses the\n> command line. It must not interpret an option's separate argument\n> as another option.\n>\n> Use parse_long_opt() to recognize revision options that take\n> separate arguments, and skip those arguments. Handle -n and\n> --default as well. Stop scanning at --, where subsequent arguments\n> are pathspecs.\n>\n> Add tests to ensure that --grep and --author arguments beginning\n> with -- are not mistaken for options during the early scan.\n\nThe commit log message explains the motivation well, and the attempt\nto address the feedback from the previous round by handling all 19\noptions from revision.c is appreciated.\n\nBut the approach of hardcoding an array of option strings that take\narguments is inherently fragile and scales poorly.  By duplicating\nparser knowledge into the early scan, this patch falls into the\nexact trap described by the NEEDSWORK comment just below it.\n\n> diff --git a/builtin/rev-list.c b/builtin/rev-list.c\n> index 071a0e3cb5..4dd646050a 100644\n> --- a/builtin/rev-list.c\n> +++ b/builtin/rev-list.c\n> @@ -744,6 +744,47 @@ static void prepare_maximal_independent(struct rev_info *revs)\n>  \trevs->no_walk = 1;\n>  }\n>  \n> +static int rev_list_option_takes_argument(const char **argv)\n> +{\n> +\tstatic const char * const options[] = {\n> +\t\t\"max-count\",\n> +\t\t\"max-count-oldest\",\n> +\t\t\"skip\",\n> +\t\t\"max-age\",\n> +\t\t\"since\",\n> +\t\t\"since-as-filter\",\n> +\t\t\"after\",\n> +\t\t\"min-age\",\n> +\t\t\"before\",\n> +\t\t\"until\",\n> +\t\t\"date\",\n> +\t\t\"author\",\n> +\t\t\"committer\",\n> +\t\t\"grep-reflog\",\n> +\t\t\"grep\",\n> +\t\t\"encoding\",\n> +\t\t\"glob\",\n> +\t\t\"exclude\",\n> +\t\t\"exclude-hidden\",\n> +\t};\n\nIs this hardcoded list complete?  It misses options parsed via\ndiff_merges_parse_opts() in diff-merges.c (e.g., --diff-merges), as\nwell as options handled in diff.c (e.g., --src-prefix and\n--dst-prefix), which also take separate arguments and are accepted\nby git rev-list.  Would\n\n    $ git rev-list --src-prefix --missing-only HEAD\n\ntake --missing-only as an extra option or a prefix?\n\nThanks.\n\n"},{"id":"557675","messageId":"CAPki72HBWEP8t9mu1zuKBA33SU1Oj-4bL4SQTqrn0G-H0P+g=g@mail.gmail.com","threadId":"66622","inReplyTo":"xmqqwlqqokxr.fsf@gitster.g","subject":"Re: [PATCH v4] rev-list: handle arguments in early option scan","fromName":"Azuama Odinaka Maximus","fromEmail":"azuama69@gmail.com","sentAt":"2026-11-06T13:25:56Z","receivedAt":"2026-11-06T13:25:56Z","isPatch":true,"sender":{"key":"azuama69@gmail.com","avatar":null},"body":"I've investigated the relevant parsing paths further:\n\n1. Revision options are handled by handle_revision_opt() in\nrevision.c. It already determines argument consumption through helpers\nsuch as parse_long_opt(), which returns whether an option uses an\nattached or separate argument. However, the function also applies the\noption's effects to struct rev_info, so calling it again purely to\ndetermine argument consumption would be unsafe.\n\n2. Revision pseudo-options are handled separately by\nhandle_revision_pseudo_opt().\n\n3. Diff-merge options are handled by diff_merges_parse_opts() in diff-merges.c.\n\n4. Diff options are defined through add_diff_options() in diff.c,\nwhich provides an existing struct option table. This includes options\nsuch as --src-prefix and --dst-prefix.\n\nThis suggests that the early scan needs to obtain argument-consumption\ninformation from the same option definitions or recognition logic used\nby normal parsing, rather than maintaining another list of option\nnames.\n\nOne direction I'm considering is separating option recognition and\nargument consumption from option application, so that the early scan\nand normal parser can share the recognition logic without executing\nparsing side effects twice.\n\nI have not settled on the implementation yet, particularly how best to\naccommodate the hand-written revision and diff-merge parsers alongside\nthe diff option table.\n\nWould you consider this a reasonable direction? Or do you see an\nexisting Git parser interface or abstraction that would be preferable\nto extend for this purpose?\n\nThanks again for the guidance.\n\nOn Fri, 6 Nov 2026 at 01:36, Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Azuama Odinaka Maximus <azuama69@gmail.com> writes:\n>\n> > The early option scan in cmd_rev_list() looks for options that\n> > affect missing-object handling before setup_revisions() parses the\n> > command line. It must not interpret an option's separate argument\n> > as another option.\n> >\n> > Use parse_long_opt() to recognize revision options that take\n> > separate arguments, and skip those arguments. Handle -n and\n> > --default as well. Stop scanning at --, where subsequent arguments\n> > are pathspecs.\n> >\n> > Add tests to ensure that --grep and --author arguments beginning\n> > with -- are not mistaken for options during the early scan.\n>\n> The commit log message explains the motivation well, and the attempt\n> to address the feedback from the previous round by handling all 19\n> options from revision.c is appreciated.\n>\n> But the approach of hardcoding an array of option strings that take\n> arguments is inherently fragile and scales poorly.  By duplicating\n> parser knowledge into the early scan, this patch falls into the\n> exact trap described by the NEEDSWORK comment just below it.\n>\n> > diff --git a/builtin/rev-list.c b/builtin/rev-list.c\n> > index 071a0e3cb5..4dd646050a 100644\n> > --- a/builtin/rev-list.c\n> > +++ b/builtin/rev-list.c\n> > @@ -744,6 +744,47 @@ static void prepare_maximal_independent(struct rev_info *revs)\n> >       revs->no_walk = 1;\n> >  }\n> >\n> > +static int rev_list_option_takes_argument(const char **argv)\n> > +{\n> > +     static const char * const options[] = {\n> > +             \"max-count\",\n> > +             \"max-count-oldest\",\n> > +             \"skip\",\n> > +             \"max-age\",\n> > +             \"since\",\n> > +             \"since-as-filter\",\n> > +             \"after\",\n> > +             \"min-age\",\n> > +             \"before\",\n> > +             \"until\",\n> > +             \"date\",\n> > +             \"author\",\n> > +             \"committer\",\n> > +             \"grep-reflog\",\n> > +             \"grep\",\n> > +             \"encoding\",\n> > +             \"glob\",\n> > +             \"exclude\",\n> > +             \"exclude-hidden\",\n> > +     };\n>\n> Is this hardcoded list complete?  It misses options parsed via\n> diff_merges_parse_opts() in diff-merges.c (e.g., --diff-merges), as\n> well as options handled in diff.c (e.g., --src-prefix and\n> --dst-prefix), which also take separate arguments and are accepted\n> by git rev-list.  Would\n>\n>     $ git rev-list --src-prefix --missing-only HEAD\n>\n> take --missing-only as an extra option or a prefix?\n>\n> Thanks.\n\n"},{"id":"557723","messageId":"xmqqa4nlkelo.fsf@gitster.g","threadId":"66622","inReplyTo":"CAPki72HBWEP8t9mu1zuKBA33SU1Oj-4bL4SQTqrn0G-H0P+g=g@mail.gmail.com","subject":"Re: [PATCH v4] rev-list: handle arguments in early option scan","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-06T18:18:59Z","receivedAt":"2026-11-06T18:18:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Azuama Odinaka Maximus <azuama69@gmail.com> writes:\n\n> I've investigated the relevant parsing paths further:\n>\n> 1. Revision options are handled by handle_revision_opt() in\n> revision.c. It already determines argument consumption through helpers\n> such as parse_long_opt(), which returns whether an option uses an\n> attached or separate argument. However, the function also applies the\n> option's effects to struct rev_info, so calling it again purely to\n> determine argument consumption would be unsafe.\n\nCorrect.  There is no dry-run mode for this.\n\n> 2. Revision pseudo-options are handled separately by\n> handle_revision_pseudo_opt().\n\nYes, this is called from various code paths.  No dry-run, either.\n\n> 3. Diff-merge options are handled by diff_merges_parse_opts() in diff-merges.c.\n>\n> 4. Diff options are defined through add_diff_options() in diff.c,\n> which provides an existing struct option table. This includes options\n> such as --src-prefix and --dst-prefix.\n\nCorrect.  I do not think there is any dry-run to any of these.\n\nI am not sure if the above is exhausitve, though.  I didn't check.\n\n> This suggests that the early scan needs to obtain argument-consumption\n> information from the same option definitions or recognition logic used\n> by normal parsing, rather than maintaining another list of option\n> names.\n\nIt is what the NEEDSWORK comment boils down to, I think.  I do not\nsee how the above survey helps with that conclusion, though.\n\n> One direction I'm considering is separating option recognition and\n> argument consumption from option application, so that the early scan\n> and normal parser can share the recognition logic without executing\n> parsing side effects twice.\n>\n> I have not settled on the implementation yet, particularly how best to\n> accommodate the hand-written revision and diff-merge parsers alongside\n> the diff option table.\n>\n> Would you consider this a reasonable direction? Or do you see an\n> existing Git parser interface or abstraction that would be preferable\n> to extend for this purpose?\n\nAll of the above assumes that we want to keep a separate \"early\nscan\", but I wonder if that is really a good direction to go.  If\nyou can clearly identify the problem the \"early scan\" wanted to\nsolve, and can come up with a way to solve that problem without\nscanning the list of arguments twice (i.e., not involving an \"early\nscan\" at all), would that give you a cleaner implementation?\n\nIf the default of an option (is it '.fetch_if_missing' alone, or are\nthere many other settings involved?) needs to depend on other\noptions, perhaps fixing it is simpler if the presence of an explicit\noption that sets '.fetch_if_missing' is recorded in a separate\nmember of the struct, and then at the very end after all the command\nline options have been seen, take these other options and the\nexplicit option setting for it into account to synthesize the\nresult?  If '.fetch_if_missing' was explicitly set from what the\nuser said from the command line, there is no need to look at any\nother options, and if not, then the settings left by parsing other\noptions that the misdesigned \"early scan\" pays attention to can be\nconsulted to decide what the desirable value should be.\n\nJust thinking out loud.  It seems that this started at df11e19648\n(rev-list: support termination at promisor objects, 2017-12-08), and\nthen other needs may have been piled on top, but going back to that\noriginal commit may be a good place to start understanding and\nreevaluating if the \"early scan\" was the best approach to solve\nwhatever problem it was trying to solve.\n\n> Thanks again for the guidance.\n>\n> On Fri, 6 Nov 2026 at 01:36, Junio C Hamano <gitster@pobox.com> wrote:\n\nNever top-post.\n\n"}]}