[PATCH 2/3] builtin/grep: read sparse directory trees 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-2-d4eb5c87d8fb@pks.im>
- In-Reply-To
- <20261030-pks-grep-recurse-submodule-v1-0-d4eb5c87d8fb@pks.im>
When iterating through the index in `grep_cache()` we may encounter sparse directory entries. In that case we read the tree object they point to so that we can recurse into it via `grep_tree()`. We do so via `the_repository` though, even though `grep_cache()` may be called for a submodule via `grep_submodule()`.
This issue is similar to the one fixed in the preceding commit, where `grep_tree()` didn't use the correct repository. But in this case here the issue cannot be triggered as we call `repo_read_gitmodules()` on the submodule repository, and that function will cause us to read its index. But because we only ever set `command_requires_full_index` for the top-level repository we will convert the submodule's index into a full index, and consequently we will never see sparse directory entries. This is also documented as such in a NEEDSWORK comment in `grep_submodule()`.
Regardless of that the code is still wrong, and it may very easily turn into a bug once we start to handle sparse indices for submodules. Adapt it to use the correct repository to preempt such a future bug.
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 22fb365eeac..cb518d8155e 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -560,7 +560,7 @@ static int grep_cache(struct grep_opt *opt, void *data; size_t size; - data = odb_read_object(the_repository->objects, &ce->oid, + data = odb_read_object(repo->objects, &ce->oid, &type, &size); if (!data) die(_("unable to read tree %s"), oid_to_hex(&ce->oid));
-- 2.56.0.341.g393f52fd96.dirty