aboutsummaryrefslogtreecommitdiff
path: root/packfile.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2026-01-09 09:33:17 +0100
committerJunio C Hamano <gitster@pobox.com>2026-01-09 06:40:07 -0800
commita593373b097322adc74aa5f9614c7650f87ebed9 (patch)
treef18677a1b2d09d7adc531735f4447217bda704e2 /packfile.c
parent6acefa0d2ca0fd95461b19026917d09210032b3d (diff)
downloadgit-a593373b097322adc74aa5f9614c7650f87ebed9.tar.xz
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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'packfile.c')
-rw-r--r--packfile.c43
1 files changed, 23 insertions, 20 deletions
diff --git a/packfile.c b/packfile.c
index 3bce1b150d..0e4c63e11d 100644
--- a/packfile.c
+++ b/packfile.c
@@ -2087,29 +2087,23 @@ static int fill_pack_entry(const struct object_id *oid,
return 1;
}
-static int find_pack_entry(struct repository *r,
+static int find_pack_entry(struct packfile_store *store,
const struct object_id *oid,
struct pack_entry *e)
{
- struct odb_source *source;
-
- for (source = r->objects->sources; source; source = source->next) {
- packfile_store_prepare(r->objects->sources->packfiles);
- if (source->midx && fill_midx_entry(source->midx, oid, e))
- return 1;
- }
+ struct packfile_list_entry *l;
- for (source = r->objects->sources; source; source = source->next) {
- struct packfile_list_entry *l;
+ packfile_store_prepare(store);
+ if (store->source->midx && fill_midx_entry(store->source->midx, oid, e))
+ return 1;
- for (l = source->packfiles->packs.head; l; l = l->next) {
- struct packed_git *p = l->pack;
+ for (l = store->packs.head; l; l = l->next) {
+ struct packed_git *p = l->pack;
- if (!p->multi_pack_index && fill_pack_entry(oid, e, p)) {
- if (!source->packfiles->skip_mru_updates)
- packfile_list_prepend(&source->packfiles->packs, p);
- return 1;
- }
+ if (!p->multi_pack_index && fill_pack_entry(oid, e, p)) {
+ if (!store->skip_mru_updates)
+ packfile_list_prepend(&store->packs, p);
+ return 1;
}
}
@@ -2120,7 +2114,7 @@ int packfile_store_freshen_object(struct packfile_store *store,
const struct object_id *oid)
{
struct pack_entry e;
- if (!find_pack_entry(store->source->odb->repo, oid, &e))
+ if (!find_pack_entry(store, oid, &e))
return 0;
if (e.p->is_cruft)
return 0;
@@ -2141,7 +2135,7 @@ int packfile_store_read_object_info(struct packfile_store *store,
struct pack_entry e;
int rtype;
- if (!find_pack_entry(store->source->odb->repo, oid, &e))
+ if (!find_pack_entry(store, oid, &e))
return 1;
/*
@@ -2217,8 +2211,17 @@ struct packed_git **packfile_store_get_kept_pack_cache(struct packfile_store *st
int has_object_pack(struct repository *r, const struct object_id *oid)
{
+ struct odb_source *source;
struct pack_entry e;
- return find_pack_entry(r, oid, &e);
+
+ odb_prepare_alternates(r->objects);
+ for (source = r->objects->sources; source; source = source->next) {
+ int ret = find_pack_entry(source->packfiles, oid, &e);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
}
int has_object_kept_pack(struct repository *r, const struct object_id *oid,