Skip to content

Commit 445952b

Browse files
pks-tgitster
authored andcommitted
packfile: refactor find_pack_entry() to work on the packfile store
The function `find_pack_entry()` doesn't work on a specific packfile store, but instead works on the whole repository. This causes a bit of a conceptual mismatch in its callers: - `packfile_store_freshen_object()` supposedly acts on a store, and its callers know to iterate through all sources already. - `packfile_store_read_object_info()` behaves likewise. The only exception that doesn't know to handle iteration through sources is `has_object_pack()`, but that function is trivial to adapt. Refactor the code so that `find_pack_entry()` works on the packfile store level instead. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4020dff commit 445952b

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

packfile.c

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,29 +2087,23 @@ static int fill_pack_entry(const struct object_id *oid,
20872087
return 1;
20882088
}
20892089

2090-
static int find_pack_entry(struct repository *r,
2090+
static int find_pack_entry(struct packfile_store *store,
20912091
const struct object_id *oid,
20922092
struct pack_entry *e)
20932093
{
2094-
struct odb_source *source;
2095-
2096-
for (source = r->objects->sources; source; source = source->next) {
2097-
packfile_store_prepare(r->objects->sources->packfiles);
2098-
if (source->midx && fill_midx_entry(source->midx, oid, e))
2099-
return 1;
2100-
}
2094+
struct packfile_list_entry *l;
21012095

2102-
for (source = r->objects->sources; source; source = source->next) {
2103-
struct packfile_list_entry *l;
2096+
packfile_store_prepare(store);
2097+
if (store->source->midx && fill_midx_entry(store->source->midx, oid, e))
2098+
return 1;
21042099

2105-
for (l = source->packfiles->packs.head; l; l = l->next) {
2106-
struct packed_git *p = l->pack;
2100+
for (l = store->packs.head; l; l = l->next) {
2101+
struct packed_git *p = l->pack;
21072102

2108-
if (!p->multi_pack_index && fill_pack_entry(oid, e, p)) {
2109-
if (!source->packfiles->skip_mru_updates)
2110-
packfile_list_prepend(&source->packfiles->packs, p);
2111-
return 1;
2112-
}
2103+
if (!p->multi_pack_index && fill_pack_entry(oid, e, p)) {
2104+
if (!store->skip_mru_updates)
2105+
packfile_list_prepend(&store->packs, p);
2106+
return 1;
21132107
}
21142108
}
21152109

@@ -2120,7 +2114,7 @@ int packfile_store_freshen_object(struct packfile_store *store,
21202114
const struct object_id *oid)
21212115
{
21222116
struct pack_entry e;
2123-
if (!find_pack_entry(store->source->odb->repo, oid, &e))
2117+
if (!find_pack_entry(store, oid, &e))
21242118
return 0;
21252119
if (e.p->is_cruft)
21262120
return 0;
@@ -2141,7 +2135,7 @@ int packfile_store_read_object_info(struct packfile_store *store,
21412135
struct pack_entry e;
21422136
int rtype;
21432137

2144-
if (!find_pack_entry(store->source->odb->repo, oid, &e))
2138+
if (!find_pack_entry(store, oid, &e))
21452139
return 1;
21462140

21472141
/*
@@ -2217,8 +2211,17 @@ struct packed_git **packfile_store_get_kept_pack_cache(struct packfile_store *st
22172211

22182212
int has_object_pack(struct repository *r, const struct object_id *oid)
22192213
{
2214+
struct odb_source *source;
22202215
struct pack_entry e;
2221-
return find_pack_entry(r, oid, &e);
2216+
2217+
odb_prepare_alternates(r->objects);
2218+
for (source = r->objects->sources; source; source = source->next) {
2219+
int ret = find_pack_entry(source->packfiles, oid, &e);
2220+
if (ret)
2221+
return ret;
2222+
}
2223+
2224+
return 0;
22222225
}
22232226

22242227
int has_object_kept_pack(struct repository *r, const struct object_id *oid,

0 commit comments

Comments
 (0)