builtin/grep: stop registering submodule ODB as source

Same as with the preceding commit, git-grep(1) registers each
submodule's object database as an in-memory source of the main object
database before grepping it. This was introduced as an eager alternate
registration and converted into the lazy mechanism via 8d33c3af0b (grep:
use submodule-ODB-as-alternate lazy-addition, 2021-08-16).

Starting with 0693806bf8 (grep: add repository to OID grep sources,
2021-08-16), the command instead knows to pass submodule repositories to
our workers, which means that those now use that repository to look up
objects, too. As a consequence, registering submodule sources as
alternates is not required anymore.

Remove the logic to register submodule sources. Unfortunately, this does
not allow us to get rid of the object read lock as initializing the
subrepository is still racy.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
jch^2
Patrick Steinhardt 2026-09-01 13:09:04 +02:00 committed by Junio C Hamano
parent 5dc4c496db
commit 6f16066ff7
1 changed files with 6 additions and 20 deletions

View File

@ -463,16 +463,6 @@ static int grep_submodule(struct grep_opt *opt,
ALLOC_GROW(repos_to_free, repos_to_free_nr + 1, repos_to_free_alloc);
repos_to_free[repos_to_free_nr++] = subrepo;

/*
* NEEDSWORK: repo_read_gitmodules() might call
* odb_add_to_alternates_memory() via config_from_gitmodules(). This
* operation causes a race condition with concurrent object readings
* performed by the worker threads. That's why we need obj_read_lock()
* here. It should be removed once it's no longer necessary to add the
* subrepo's odbs to the in-memory alternates list.
*/
obj_read_lock();

/*
* NEEDSWORK: when reading a submodule, the sparsity settings in the
* superproject are incorrectly forgotten or misused. For example:
@ -498,18 +488,14 @@ static int grep_submodule(struct grep_opt *opt,
* ditto.
*
* Note that this list is not exhaustive.
*
* NEEDSWORK: initializing the subrepository is not thread-safe,
* either, as it may cause us to race around `get_main_ref_store()`. We
* thus need to hold the object-read lock to serialize all readers with
* one another.
*/
obj_read_lock();
repo_read_gitmodules(subrepo, 0);

/*
* All code paths tested by test code no longer need submodule ODBs to
* be added as alternates, but add it to the list just in case.
* Submodule ODBs added through add_submodule_odb_by_path() will be
* lazily registered as alternates when needed (and except in an
* unexpected code interaction, it won't be needed).
*/
odb_add_submodule_source_by_path(the_repository->objects,
subrepo->objects->sources->path);
obj_read_unlock();

memcpy(&subopt, opt, sizeof(subopt));