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

[PATCH 3/3] builtin/grep: read ".gitmodules" via passed-in repository

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 30, 2026, 10:21 UTC
Message-ID
<20261030-pks-grep-recurse-submodule-v1-3-d4eb5c87d8fb@pks.im>
In-Reply-To
<20261030-pks-grep-recurse-submodule-v1-0-d4eb5c87d8fb@pks.im>

When grepping through a list of objects with "--recurse-submodules", we call `gitmodules_config_oid()` to load gitmodules for the specific revision. But instead of passing `opt->repo` we pass `the_repository` to that function, which is somewhat fishy.

This is again not a bug because `grep_objects()` is only ever called by `cmd_grep()`, and consequently we know that `opt->repo` is always going to be set to `the_repository`. But it's a code smell regardless of that, so adapt the code to use `opt->repo` instead.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/grep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index cb518d8155e..22f0a1b0d0e 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -883,7 +883,7 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
 		if (recurse_submodules) {
 			submodule_free(opt->repo);
 			obj_read_lock();
-			gitmodules_config_oid(the_repository, &real_obj->oid);
+			gitmodules_config_oid(opt->repo, &real_obj->oid);
 			obj_read_unlock();
 		}
 		if (grep_object(opt, pathspec, real_obj, list->objects[i].name,
-- 
2.56.0.341.g393f52fd96.dirty
Previous: Patrick Steinhardt
Message 5 of 5 in “builtin/grep: fix reading objects from wrong repository”
  1. 0/3 builtin/grep: fix reading objects from wrong repositoryPatrick Steinhardt, Oct 30, 2026
  2. 1/3 builtin/grep: read submodule trees via their repositoryPatrick Steinhardt, Oct 30, 2026
  3. Toon ClaesOct 30, 2026
  4. 2/3 builtin/grep: read sparse directory trees via passed-in repositoryPatrick Steinhardt, Oct 30, 2026
  5. 3/3 builtin/grep: read ".gitmodules" via passed-in repositoryPatrick Steinhardt, Oct 30, 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.