]> git.ipfire.org Git - thirdparty/git.git/commitdiff
packfile: extract function to iterate through objects of a store
authorPatrick Steinhardt <ps@pks.im>
Thu, 15 Jan 2026 11:04:34 +0000 (12:04 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 15 Jan 2026 13:50:28 +0000 (05:50 -0800)
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>
packfile.c

index 79fe64a25b2f5ea962a485375e6bc6ae6999c6a0..d15a2ce12b1ce510fad1125c7a2495eb54b86b45 100644 (file)
@@ -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,