packfile: refactor `prepare_packed_git()` to work on packfile store

The `prepare_packed_git()` function and its friends are responsible for
loading packfiles as well as the multi-pack index for a given object
database. Refactor these functions to accept a packfile store instead of
a repository to clarify their scope.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
main
Patrick Steinhardt 2025-09-23 12:17:07 +02:00 committed by Junio C Hamano
parent 995ee88027
commit c36ecc0685
1 changed files with 18 additions and 23 deletions

View File

@ -974,37 +974,32 @@ static int sort_pack(const struct packed_git *a, const struct packed_git *b)
return -1;
}

static void rearrange_packed_git(struct repository *r)
{
sort_packs(&r->objects->packfiles->packs, sort_pack);
}

static void prepare_packed_git_mru(struct repository *r)
static void packfile_store_prepare_mru(struct packfile_store *store)
{
struct packed_git *p;

INIT_LIST_HEAD(&r->objects->packfiles->mru);
INIT_LIST_HEAD(&store->mru);

for (p = r->objects->packfiles->packs; p; p = p->next)
list_add_tail(&p->mru, &r->objects->packfiles->mru);
for (p = store->packs; p; p = p->next)
list_add_tail(&p->mru, &store->mru);
}

static void prepare_packed_git(struct repository *r)
static void packfile_store_prepare(struct packfile_store *store)
{
struct odb_source *source;

if (r->objects->packfiles->initialized)
if (store->initialized)
return;

odb_prepare_alternates(r->objects);
for (source = r->objects->sources; source; source = source->next) {
odb_prepare_alternates(store->odb);
for (source = store->odb->sources; source; source = source->next) {
prepare_multi_pack_index_one(source);
prepare_packed_git_one(source);
}
rearrange_packed_git(r);
sort_packs(&store->packs, sort_pack);

prepare_packed_git_mru(r);
r->objects->packfiles->initialized = true;
packfile_store_prepare_mru(store);
store->initialized = true;
}

void reprepare_packed_git(struct repository *r)
@ -1027,25 +1022,25 @@ void reprepare_packed_git(struct repository *r)

r->objects->approximate_object_count_valid = 0;
r->objects->packfiles->initialized = false;
prepare_packed_git(r);
packfile_store_prepare(r->objects->packfiles);
obj_read_unlock();
}

struct packed_git *get_packed_git(struct repository *r)
{
prepare_packed_git(r);
packfile_store_prepare(r->objects->packfiles);
return r->objects->packfiles->packs;
}

struct multi_pack_index *get_multi_pack_index(struct odb_source *source)
{
prepare_packed_git(source->odb->repo);
packfile_store_prepare(source->odb->packfiles);
return source->midx;
}

struct packed_git *get_all_packs(struct repository *r)
{
prepare_packed_git(r);
packfile_store_prepare(r->objects->packfiles);

for (struct odb_source *source = r->objects->sources; source; source = source->next) {
struct multi_pack_index *m = source->midx;
@ -1060,7 +1055,7 @@ struct packed_git *get_all_packs(struct repository *r)

struct list_head *get_packed_git_mru(struct repository *r)
{
prepare_packed_git(r);
packfile_store_prepare(r->objects->packfiles);
return &r->objects->packfiles->mru;
}

@ -1078,7 +1073,7 @@ unsigned long repo_approximate_object_count(struct repository *r)
unsigned long count = 0;
struct packed_git *p;

prepare_packed_git(r);
packfile_store_prepare(r->objects->packfiles);

for (source = r->objects->sources; source; source = source->next) {
struct multi_pack_index *m = get_multi_pack_index(source);
@ -2068,7 +2063,7 @@ int find_pack_entry(struct repository *r, const struct object_id *oid, struct pa
{
struct list_head *pos;

prepare_packed_git(r);
packfile_store_prepare(r->objects->packfiles);

for (struct odb_source *source = r->objects->sources; source; source = source->next)
if (source->midx && fill_midx_entry(source->midx, oid, e))