diff options
| author | Patrick Steinhardt <ps@pks.im> | 2026-01-26 10:51:21 +0100 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-01-26 08:26:07 -0800 |
| commit | 37353119046414b2dccb26b32cb5224e0c9258e1 (patch) | |
| tree | 9a7ab0ddb62b7bcf178ed9c0a05fe4ed26459151 /packfile.c | |
| parent | cde615b6f05228cd7cf125de6bf5757381f65381 (diff) | |
| download | git-37353119046414b2dccb26b32cb5224e0c9258e1.tar.xz | |
packfile: extract function to iterate through objects of a store
In the next commit we're about to introduce a new function that knows to
iterate through objects of a given packfile store. Same as with the
equivalent function for loose objects, this new function will also be
agnostic of backends by using a `struct object_info`.
Prepare for this by extracting a new shared function to iterate through
a single packfile store.
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.c | 78 |
1 files changed, 45 insertions, 33 deletions
diff --git a/packfile.c b/packfile.c index 79fe64a25b..d15a2ce12b 100644 --- a/packfile.c +++ b/packfile.c @@ -2301,51 +2301,63 @@ int for_each_object_in_pack(struct packed_git *p, return r; } -int for_each_packed_object(struct repository *repo, each_packed_object_fn cb, - void *data, unsigned flags) +static int packfile_store_for_each_object_internal(struct packfile_store *store, + each_packed_object_fn cb, + void *data, + unsigned flags, + int *pack_errors) { - struct odb_source *source; - int r = 0; - int pack_errors = 0; + struct packfile_list_entry *e; + int ret = 0; - odb_prepare_alternates(repo->objects); + store->skip_mru_updates = true; - for (source = repo->objects->sources; source; source = source->next) { - struct packfile_list_entry *e; + for (e = packfile_store_get_packs(store); e; e = e->next) { + struct packed_git *p = e->pack; - source->packfiles->skip_mru_updates = true; + if ((flags & ODB_FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local) + continue; + if ((flags & ODB_FOR_EACH_OBJECT_PROMISOR_ONLY) && + !p->pack_promisor) + continue; + if ((flags & ODB_FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS) && + p->pack_keep_in_core) + continue; + if ((flags & ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS) && + p->pack_keep) + continue; + if (open_pack_index(p)) { + *pack_errors = 1; + continue; + } - for (e = packfile_store_get_packs(source->packfiles); e; e = e->next) { - struct packed_git *p = e->pack; + ret = for_each_object_in_pack(p, cb, data, flags); + if (ret) + break; + } - if ((flags & ODB_FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local) - continue; - if ((flags & ODB_FOR_EACH_OBJECT_PROMISOR_ONLY) && - !p->pack_promisor) - continue; - if ((flags & ODB_FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS) && - p->pack_keep_in_core) - continue; - if ((flags & ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS) && - p->pack_keep) - continue; - if (open_pack_index(p)) { - pack_errors = 1; - continue; - } + store->skip_mru_updates = false; - r = for_each_object_in_pack(p, cb, data, flags); - if (r) - break; - } + return ret; +} - source->packfiles->skip_mru_updates = false; +int for_each_packed_object(struct repository *repo, each_packed_object_fn cb, + void *data, unsigned flags) +{ + struct odb_source *source; + int pack_errors = 0; + int ret = 0; - if (r) + odb_prepare_alternates(repo->objects); + + for (source = repo->objects->sources; source; source = source->next) { + ret = packfile_store_for_each_object_internal(source->packfiles, cb, data, + flags, &pack_errors); + if (ret) break; } - return r ? r : pack_errors; + return ret ? ret : pack_errors; } static int add_promisor_object(const struct object_id *oid, |
