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

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

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 3, 2026, 12:43 UTC
Message-ID
<20261103-pks-grep-recurse-submodule-v2-3-b00e3b3dc865@pks.im>
In-Reply-To
<20261103-pks-grep-recurse-submodule-v2-0-b00e3b3dc865@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.500.g5d06dc02cd.dirty
Previous: Patrick Steinhardt
Message 10 of 10 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. Patrick SteinhardtNov 3, 2026
  5. 2/3 builtin/grep: read sparse directory trees via passed-in repositoryPatrick Steinhardt, Oct 30, 2026
  6. 3/3 builtin/grep: read ".gitmodules" via passed-in repositoryPatrick Steinhardt, Oct 30, 2026
  7. 0/3 builtin/grep: fix reading objects from wrong repositoryPatrick Steinhardt, Nov 3, 2026
  8. 1/3 builtin/grep: read submodule trees via their repositoryPatrick Steinhardt, Nov 3, 2026
  9. 2/3 builtin/grep: read sparse directory trees via passed-in repositoryPatrick Steinhardt, Nov 3, 2026
  10. 3/3 builtin/grep: read ".gitmodules" via passed-in repositoryPatrick Steinhardt, Nov 3, 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.