odb/source-packed: extract logic to skip certain packs
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>
Patrick Steinhardt committed
Jun 25, 2026 at 11:57 UTC
d45f956f2022a90d39b1ce82aea668cce73f1d75
1 file changed
+18
-10
odb/source-packed.c
+18
-10
@@ -126,6 +126,22 @@ static int match_hash(unsigned len, const unsigned char *a, const unsigned char
126
return 1;
127
}
128
129
+static bool should_exclude_pack(struct packed_git *p, enum odb_for_each_object_flags flags)
130
+{
131
+ if ((flags & ODB_FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)
132
+ return true;
133
+ if ((flags & ODB_FOR_EACH_OBJECT_PROMISOR_ONLY) &&
134
+ !p->pack_promisor)
135
+ return true;
136
+ if ((flags & ODB_FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS) &&
137
+ p->pack_keep_in_core)
138
+ return true;
139
+ if ((flags & ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS) &&
140
+ p->pack_keep)
141
+ return true;
142
+ return false;
143
+}
144
+
145
static int for_each_prefixed_object_in_midx(
146
struct odb_source_packed *store,
147
struct multi_pack_index *m,
@@ -306,17 +322,9 @@ static int odb_source_packed_for_each_object(struct odb_source *source,
322
for (e = packfile_store_get_packs(packed); e; e = e->next) {
323
struct packed_git *p = e->pack;
324
309
- if ((opts->flags & ODB_FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)
310
- continue;
311
- if ((opts->flags & ODB_FOR_EACH_OBJECT_PROMISOR_ONLY) &&
312
- !p->pack_promisor)
313
- continue;
314
- if ((opts->flags & ODB_FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS) &&
315
- p->pack_keep_in_core)
316
- continue;
317
- if ((opts->flags & ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS) &&
318
- p->pack_keep)
325
+ if (should_exclude_pack(p, opts->flags))
326
continue;
327
+
328
if (open_pack_index(p)) {
329
pack_errors = 1;
330
continue;