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

[PATCH v3] rev-list: skip --grep argument in early scan

From
AMAzuama Odinaka Maximus <azuama69@gmail.com>
Date
Oct 26, 2026, 08:30 UTC
Message-ID
<20261026083055.18873-1-azuama69@gmail.com>
In-Reply-To
<20261021172458.6373-1-azuama69@gmail.com>

The early option scan in rev-list does not account for options that take a separate argument. As a result, a pattern passed to --grep can be mistaken for another option.

Skip the argument to --grep so that it is not interpreted as an option during the early scan.

The tests check that patterns beginning with "--" are actually matched by --grep, including when the pattern resembles an option that the early scan handles specially.

Signed-off-by: Azuama Odinaka Maximus <azuama69@gmail.com>
---
Changes in v3:
- Improve both regression tests to verify that --grep matches the
  expected commit when its pattern begins with "--".
- Add a blank line between the tests.
 builtin/rev-list.c          |  2 ++
 t/t6022-rev-list-missing.sh | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+)
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 0faa833fac..453d82d25c 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -771,6 +771,8 @@ int cmd_rev_list(int argc,
 			revs.exclude_promisor_objects = 1;
 		} else if (skip_prefix(arg, "--missing=", &arg)) {
 			parse_missing_action_value(repo, arg);
+		} else if (!strcmp(arg, "--grep")) {
+			i++;
 		} else if (!strcmp(arg, "--missing-only")) {
 			arg_missing_only = 1;
 		} else if (!strcmp(arg, "-z")) {
diff --git a/t/t6022-rev-list-missing.sh b/t/t6022-rev-list-missing.sh
index 1bd2c3bc4f..3757bde708 100755
--- a/t/t6022-rev-list-missing.sh
+++ b/t/t6022-rev-list-missing.sh
@@ -215,6 +215,26 @@ do
 	'
 done
 
+test_expect_success "--grep accepts a pattern beginning with --" '
+        test_commit --no-tag --missing-only &&
+        commit=$(git rev-parse HEAD) &&
+        echo "$commit" >expect &&
+        git rev-list --grep=--missing-only HEAD >actual &&
+        test_cmp expect actual &&
+        git rev-list --grep --missing-only HEAD >actual &&
+        test_cmp expect actual
+'
+
+test_expect_success "--grep does not trigger --exclude-promisor-objects in early scan" '
+        test_commit --no-tag --exclude-promisor-objects &&
+        commit=$(git rev-parse HEAD) &&
+        echo "$commit" >expect &&
+        git rev-list --grep=--exclude-promisor-objects --missing=print HEAD >actual &&
+        test_cmp expect actual &&
+        git rev-list --grep --exclude-promisor-objects --missing=print HEAD >actual &&
+        test_cmp expect actual
+'
+
 test_expect_success "--missing-only requires --missing=print or --missing=print-info" '
 	test_must_fail git rev-list --missing-only --objects HEAD 2>err &&
 	test_grep "requires --missing=print" err
-- 
2.53.0
Previous: Junio C HamanoNext: Tanga Joris
Message 6 of 11 in “rev-list: skip --grep argument in early scan”
  1. rev-list: skip --grep argument in early scanAzuama Odinaka Maximus, Oct 21, 2026
  2. Pushkar SinghOct 21, 2026
  3. rev-list: skip --grep argument in early scanAzuama Odinaka Maximus, Oct 21, 2026
  4. Pushkar SinghOct 22, 2026
  5. Junio C HamanoOct 23, 2026
  6. rev-list: skip --grep argument in early scanAzuama Odinaka Maximus, Oct 26, 2026
  7. Tanga JorisNov 5, 2026
  8. rev-list: handle arguments in early option scanAzuama Odinaka Maximus, Nov 5, 2026
  9. Junio C HamanoNov 6, 2026
  10. Azuama Odinaka MaximusNov 6, 2026
  11. Junio C HamanoNov 6, 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.