]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb/source-packed: support flags when iterating an object prefix
authorPatrick Steinhardt <ps@pks.im>
Thu, 25 Jun 2026 09:57:40 +0000 (11:57 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 25 Jun 2026 20:20:20 +0000 (13:20 -0700)
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>
odb/source-packed.c

index 3afc4bf01f74bc5a8288361d0553165d454343f1..96fc436770afd190f70e1cec767bb0bd4829f14a 100644 (file)
@@ -148,6 +148,7 @@ static int for_each_prefixed_object_in_midx(
        const struct odb_for_each_object_options *opts,
        struct odb_source_packed_for_each_object_wrapper_data *data)
 {
+       bool pack_errors = false;
        int ret;
 
        for (; m; m = m->base_midx) {
@@ -176,6 +177,20 @@ static int for_each_prefixed_object_in_midx(
                        if (!match_hash(len, opts->prefix->hash, current->hash))
                                break;
 
+                       if (opts->flags) {
+                               uint32_t pack_id = nth_midxed_pack_int_id(m, i);
+                               struct packed_git *pack;
+
+                               if (prepare_midx_pack(m, pack_id)) {
+                                       pack_errors = true;
+                                       continue;
+                               }
+
+                               pack = nth_midxed_pack(m, pack_id);
+                               if (should_exclude_pack(pack, opts->flags))
+                                       continue;
+                       }
+
                        if (data->request) {
                                struct object_info oi = *data->request;
 
@@ -198,6 +213,8 @@ static int for_each_prefixed_object_in_midx(
        ret = 0;
 
 out:
+       if (!ret && pack_errors)
+               ret = -1;
        return ret;
 }
 
@@ -260,9 +277,6 @@ static int odb_source_packed_for_each_prefixed_object(
        bool pack_errors = false;
        int ret;
 
-       if (opts->flags)
-               BUG("flags unsupported");
-
        store->skip_mru_updates = true;
 
        m = get_multi_pack_index(store);
@@ -275,6 +289,8 @@ static int odb_source_packed_for_each_prefixed_object(
        for (e = packfile_store_get_packs(store); e; e = e->next) {
                if (e->pack->multi_pack_index)
                        continue;
+               if (should_exclude_pack(e->pack, opts->flags))
+                       continue;
 
                if (open_pack_index(e->pack)) {
                        pack_errors = true;