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>
Patrick Steinhardt committed
Sep 23, 2025 at 12:17 UTC
c36ecc0685a75f913fe4871766715221c71f4b09
1 file changed
+18
-23
packfile.c
+18
-23
@@ -974,37 +974,32 @@ static int sort_pack(const struct packed_git *a, const struct packed_git *b)
974
return -1;
975
}
976
977
-static void rearrange_packed_git(struct repository *r)
978
-{
979
- sort_packs(&r->objects->packfiles->packs, sort_pack);
980
-}
981
-
982
-static void prepare_packed_git_mru(struct repository *r)
977
+static void packfile_store_prepare_mru(struct packfile_store *store)
978
{
979
struct packed_git *p;
980
986
- INIT_LIST_HEAD(&r->objects->packfiles->mru);
981
+ INIT_LIST_HEAD(&store->mru);
982
988
- for (p = r->objects->packfiles->packs; p; p = p->next)
989
- list_add_tail(&p->mru, &r->objects->packfiles->mru);
983
+ for (p = store->packs; p; p = p->next)
984
+ list_add_tail(&p->mru, &store->mru);
985
}
986
992
-static void prepare_packed_git(struct repository *r)
987
+static void packfile_store_prepare(struct packfile_store *store)
988
{
989
struct odb_source *source;
990
996
- if (r->objects->packfiles->initialized)
991
+ if (store->initialized)
992
return;
993
999
- odb_prepare_alternates(r->objects);
1000
- for (source = r->objects->sources; source; source = source->next) {
994
+ odb_prepare_alternates(store->odb);
995
+ for (source = store->odb->sources; source; source = source->next) {
996
prepare_multi_pack_index_one(source);
997
prepare_packed_git_one(source);
998
}
1004
- rearrange_packed_git(r);
999
+ sort_packs(&store->packs, sort_pack);
1000
1006
- prepare_packed_git_mru(r);
1007
- r->objects->packfiles->initialized = true;
1001
+ packfile_store_prepare_mru(store);
1002
+ store->initialized = true;
1003
}
1004
1005
void reprepare_packed_git(struct repository *r)
@@ -1027,25 +1022,25 @@ void reprepare_packed_git(struct repository *r)
1022
1023
r->objects->approximate_object_count_valid = 0;
1024
r->objects->packfiles->initialized = false;
1030
- prepare_packed_git(r);
1025
+ packfile_store_prepare(r->objects->packfiles);
1026
obj_read_unlock();
1027
}
1028
1029
struct packed_git *get_packed_git(struct repository *r)
1030
{
1036
- prepare_packed_git(r);
1031
+ packfile_store_prepare(r->objects->packfiles);
1032
return r->objects->packfiles->packs;
1033
}
1034
1035
struct multi_pack_index *get_multi_pack_index(struct odb_source *source)
1036
{
1042
- prepare_packed_git(source->odb->repo);
1037
+ packfile_store_prepare(source->odb->packfiles);
1038
return source->midx;
1039
}
1040
1041
struct packed_git *get_all_packs(struct repository *r)
1042
{
1048
- prepare_packed_git(r);
1043
+ packfile_store_prepare(r->objects->packfiles);
1044
1045
for (struct odb_source *source = r->objects->sources; source; source = source->next) {
1046
struct multi_pack_index *m = source->midx;
@@ -1060,7 +1055,7 @@ struct packed_git *get_all_packs(struct repository *r)
1055
1056
struct list_head *get_packed_git_mru(struct repository *r)
1057
{
1063
- prepare_packed_git(r);
1058
+ packfile_store_prepare(r->objects->packfiles);
1059
return &r->objects->packfiles->mru;
1060
}
1061
@@ -1078,7 +1073,7 @@ unsigned long repo_approximate_object_count(struct repository *r)
1073
unsigned long count = 0;
1074
struct packed_git *p;
1075
1081
- prepare_packed_git(r);
1076
+ packfile_store_prepare(r->objects->packfiles);
1077
1078
for (source = r->objects->sources; source; source = source->next) {
1079
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
2063
{
2064
struct list_head *pos;
2065
2071
- prepare_packed_git(r);
2066
+ packfile_store_prepare(r->objects->packfiles);
2067
2068
for (struct odb_source *source = r->objects->sources; source; source = source->next)
2069
if (source->midx && fill_midx_entry(source->midx, oid, e))