Skip to content

Commit c36ecc0

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 995ee88 commit c36ecc0

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

packfile.c

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -974,37 +974,32 @@ static int sort_pack(const struct packed_git *a, const struct packed_git *b)
974974
return -1;
975975
}
976976

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)
983978
{
984979
struct packed_git *p;
985980

986-
INIT_LIST_HEAD(&r->objects->packfiles->mru);
981+
INIT_LIST_HEAD(&store->mru);
987982

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);
990985
}
991986

992-
static void prepare_packed_git(struct repository *r)
987+
static void packfile_store_prepare(struct packfile_store *store)
993988
{
994989
struct odb_source *source;
995990

996-
if (r->objects->packfiles->initialized)
991+
if (store->initialized)
997992
return;
998993

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) {
1001996
prepare_multi_pack_index_one(source);
1002997
prepare_packed_git_one(source);
1003998
}
1004-
rearrange_packed_git(r);
999+
sort_packs(&store->packs, sort_pack);
10051000

1006-
prepare_packed_git_mru(r);
1007-
r->objects->packfiles->initialized = true;
1001+
packfile_store_prepare_mru(store);
1002+
store->initialized = true;
10081003
}
10091004

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

10281023
r->objects->approximate_object_count_valid = 0;
10291024
r->objects->packfiles->initialized = false;
1030-
prepare_packed_git(r);
1025+
packfile_store_prepare(r->objects->packfiles);
10311026
obj_read_unlock();
10321027
}
10331028

10341029
struct packed_git *get_packed_git(struct repository *r)
10351030
{
1036-
prepare_packed_git(r);
1031+
packfile_store_prepare(r->objects->packfiles);
10371032
return r->objects->packfiles->packs;
10381033
}
10391034

10401035
struct multi_pack_index *get_multi_pack_index(struct odb_source *source)
10411036
{
1042-
prepare_packed_git(source->odb->repo);
1037+
packfile_store_prepare(source->odb->packfiles);
10431038
return source->midx;
10441039
}
10451040

10461041
struct packed_git *get_all_packs(struct repository *r)
10471042
{
1048-
prepare_packed_git(r);
1043+
packfile_store_prepare(r->objects->packfiles);
10491044

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

10611056
struct list_head *get_packed_git_mru(struct repository *r)
10621057
{
1063-
prepare_packed_git(r);
1058+
packfile_store_prepare(r->objects->packfiles);
10641059
return &r->objects->packfiles->mru;
10651060
}
10661061

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

1081-
prepare_packed_git(r);
1076+
packfile_store_prepare(r->objects->packfiles);
10821077

10831078
for (source = r->objects->sources; source; source = source->next) {
10841079
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
20682063
{
20692064
struct list_head *pos;
20702065

2071-
prepare_packed_git(r);
2066+
packfile_store_prepare(r->objects->packfiles);
20722067

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

0 commit comments

Comments
 (0)