aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2026-01-26 10:51:26 +0100
committerJunio C Hamano <gitster@pobox.com>2026-01-26 08:26:07 -0800
commit317ea9a6c3c134a1bcdee49bbbbf1731c17b967a (patch)
treed64034f71e3773f95825eb384be5b8c608c87ca1 /builtin
parent2813c97310a998510ad4bcbbf38a774fd6bb5386 (diff)
downloadgit-317ea9a6c3c134a1bcdee49bbbbf1731c17b967a.tar.xz
treewide: drop uses of `for_each_{loose,packed}_object()`
We're using `for_each_loose_object()` and `for_each_packed_object()` at a couple of callsites to enumerate all loose and packed objects, respectively. These functions will be removed in a subsequent commit in favor of the newly introduced `odb_source_loose_for_each_object()` and `packfile_store_for_each_object()` replacements. Prepare for this by refactoring the sites accordingly. Note that ideally, we'd convert all callsites to use the generic `odb_for_each_object()` function already. But for some callers this is not possible (yet), and it would require some significant refactorings to make this work. Converting these site will thus be deferred to a later patch series. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/cat-file.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 6964a5a52c..e2c63dbedf 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -806,11 +806,14 @@ struct for_each_object_payload {
void *payload;
};
-static int batch_one_object_loose(const struct object_id *oid,
- const char *path UNUSED,
- void *_payload)
+static int batch_one_object_oi(const struct object_id *oid,
+ struct object_info *oi,
+ void *_payload)
{
struct for_each_object_payload *payload = _payload;
+ if (oi && oi->whence == OI_PACKED)
+ return payload->callback(oid, oi->u.packed.pack, oi->u.packed.offset,
+ payload->payload);
return payload->callback(oid, NULL, 0, payload->payload);
}
@@ -846,8 +849,21 @@ static void batch_each_object(struct batch_options *opt,
.payload = _payload,
};
struct bitmap_index *bitmap = prepare_bitmap_git(the_repository);
+ struct odb_source *source;
- for_each_loose_object(the_repository->objects, batch_one_object_loose, &payload, 0);
+ /*
+ * TODO: we still need to tap into implementation details of the object
+ * database sources. Ideally, we should extend `odb_for_each_object()`
+ * to handle object filters itself so that we can move the filtering
+ * logic into the individual sources.
+ */
+ odb_prepare_alternates(the_repository->objects);
+ for (source = the_repository->objects->sources; source; source = source->next) {
+ int ret = odb_source_loose_for_each_object(source, NULL, batch_one_object_oi,
+ &payload, flags);
+ if (ret)
+ break;
+ }
if (bitmap && !for_each_bitmapped_object(bitmap, &opt->objects_filter,
batch_one_object_bitmapped, &payload)) {
@@ -861,8 +877,14 @@ static void batch_each_object(struct batch_options *opt,
&payload, flags);
}
} else {
- for_each_packed_object(the_repository, batch_one_object_packed,
- &payload, flags);
+ struct object_info oi = { 0 };
+
+ for (source = the_repository->objects->sources; source; source = source->next) {
+ int ret = packfile_store_for_each_object(source->packfiles, &oi,
+ batch_one_object_oi, &payload, flags);
+ if (ret)
+ break;
+ }
}
free_bitmap_index(bitmap);