]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb/source-packed: extract logic to skip certain packs
authorPatrick Steinhardt <ps@pks.im>
Thu, 25 Jun 2026 09:57:39 +0000 (11:57 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 25 Jun 2026 20:20:20 +0000 (13:20 -0700)
The caller can pass flags that allow them to filter out specific kinds
of objects when iterating objects via `odb_for_each_object()`. This only
works for "normal" iteration though, as we `BUG()` when the user passes
flags and specifies an object prefix.

This limitation will be lifted in the next commit. Prepare for this by
extracting the logic that skips certain kinds of packs so that we can
easily reuse it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
odb/source-packed.c

index 42c28fba0e34b260d5e059b56acf11be6a56d63f..3afc4bf01f74bc5a8288361d0553165d454343f1 100644 (file)
@@ -126,6 +126,22 @@ static int match_hash(unsigned len, const unsigned char *a, const unsigned char
        return 1;
 }
 
+static bool should_exclude_pack(struct packed_git *p, enum odb_for_each_object_flags flags)
+{
+       if ((flags & ODB_FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)
+               return true;
+       if ((flags & ODB_FOR_EACH_OBJECT_PROMISOR_ONLY) &&
+           !p->pack_promisor)
+               return true;
+       if ((flags & ODB_FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS) &&
+           p->pack_keep_in_core)
+               return true;
+       if ((flags & ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS) &&
+           p->pack_keep)
+               return true;
+       return false;
+}
+
 static int for_each_prefixed_object_in_midx(
        struct odb_source_packed *store,
        struct multi_pack_index *m,
@@ -306,17 +322,9 @@ static int odb_source_packed_for_each_object(struct odb_source *source,
        for (e = packfile_store_get_packs(packed); e; e = e->next) {
                struct packed_git *p = e->pack;
 
-               if ((opts->flags & ODB_FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)
-                       continue;
-               if ((opts->flags & ODB_FOR_EACH_OBJECT_PROMISOR_ONLY) &&
-                   !p->pack_promisor)
-                       continue;
-               if ((opts->flags & ODB_FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS) &&
-                   p->pack_keep_in_core)
-                       continue;
-               if ((opts->flags & ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS) &&
-                   p->pack_keep)
+               if (should_exclude_pack(p, opts->flags))
                        continue;
+
                if (open_pack_index(p)) {
                        pack_errors = 1;
                        continue;