packfile: split up responsibilities of reprepare_packed_git()

In `reprepare_packed_git()` we perform a couple of operations:

  - We reload alternate object directories.

  - We clear the loose object cache.

  - We reprepare packfiles.

While the logic is hosted in "packfile.c", it clearly reaches into other
subsystems that aren't related to packfiles.

Split up the responsibility and introduce `odb_reprepare()` which now
becomes responsible for repreparing the whole object database. The
existing `reprepare_packed_git()` function is refactored accordingly and
only cares about reloading the packfile store now.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2025-09-23 12:17:08 +02:00
committed by Junio C Hamano
parent c36ecc0685
commit 78237ea53d
13 changed files with 55 additions and 35 deletions

27
odb.c
View File

@@ -694,7 +694,7 @@ static int do_oid_object_info_extended(struct object_database *odb,
/* Not a loose object; someone else may have just packed it. */
if (!(flags & OBJECT_INFO_QUICK)) {
reprepare_packed_git(odb->repo);
odb_reprepare(odb->repo->objects);
if (find_pack_entry(odb->repo, real, &e))
break;
}
@@ -1040,3 +1040,28 @@ void odb_clear(struct object_database *o)
string_list_clear(&o->submodule_source_paths, 0);
}
void odb_reprepare(struct object_database *o)
{
struct odb_source *source;
obj_read_lock();
/*
* Reprepare alt odbs, in case the alternates file was modified
* during the course of this process. This only _adds_ odbs to
* the linked list, so existing odbs will continue to exist for
* the lifetime of the process.
*/
o->loaded_alternates = 0;
odb_prepare_alternates(o);
for (source = o->sources; source; source = source->next)
odb_clear_loose_cache(source);
o->approximate_object_count_valid = 0;
packfile_store_reprepare(o->packfiles);
obj_read_unlock();
}