odb/source-packed: support flags when iterating an object prefix

Callers of `odb_for_each_object()` can specify an optional object name prefix so that we only yield objects that match it. This is incompatible though with passing flags at the same time, as we don't yet know to handle them. Loosen this restriction by calling `should_exclude_pack()`. 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 8ed957112de135f449698e9408f2582eabb9401e
1 file changed +19 -3
odb/source-packed.c
+19 -3
@@ -148,6 +148,7 @@ static int for_each_prefixed_object_in_midx(
148 const struct odb_for_each_object_options *opts,
149 struct odb_source_packed_for_each_object_wrapper_data *data)
150 {
151 + bool pack_errors = false;
152 int ret;
153
154 for (; m; m = m->base_midx) {
@@ -176,6 +177,20 @@ static int for_each_prefixed_object_in_midx(
177 if (!match_hash(len, opts->prefix->hash, current->hash))
178 break;
179
180 + if (opts->flags) {
181 + uint32_t pack_id = nth_midxed_pack_int_id(m, i);
182 + struct packed_git *pack;
183 +
184 + if (prepare_midx_pack(m, pack_id)) {
185 + pack_errors = true;
186 + continue;
187 + }
188 +
189 + pack = nth_midxed_pack(m, pack_id);
190 + if (should_exclude_pack(pack, opts->flags))
191 + continue;
192 + }
193 +
194 if (data->request) {
195 struct object_info oi = *data->request;
196
@@ -198,6 +213,8 @@ static int for_each_prefixed_object_in_midx(
213 ret = 0;
214
215 out:
216 + if (!ret && pack_errors)
217 + ret = -1;
218 return ret;
219 }
220
@@ -260,9 +277,6 @@ static int odb_source_packed_for_each_prefixed_object(
277 bool pack_errors = false;
278 int ret;
279
263 - if (opts->flags)
264 - BUG("flags unsupported");
265 -
280 store->skip_mru_updates = true;
281
282 m = get_multi_pack_index(store);
@@ -275,6 +289,8 @@ static int odb_source_packed_for_each_prefixed_object(
289 for (e = packfile_store_get_packs(store); e; e = e->next) {
290 if (e->pack->multi_pack_index)
291 continue;
292 + if (should_exclude_pack(e->pack, opts->flags))
293 + continue;
294
295 if (open_pack_index(e->pack)) {
296 pack_errors = true;