]> git.ipfire.org Git - thirdparty/git.git/commitdiff
treewide: drop uses of `for_each_{loose,packed}_object()`
authorPatrick Steinhardt <ps@pks.im>
Thu, 15 Jan 2026 11:04:39 +0000 (12:04 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 15 Jan 2026 13:50:29 +0000 (05:50 -0800)
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.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/cat-file.c
commit-graph.c

index 6964a5a52c1646cadae97e92aafa35f90e4ce273..7d16fbc1b865565686a4104509f734c1e305b469 100644 (file)
@@ -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,15 @@ 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);
+       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 +871,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);
index 7f1145a0821cbb6bc1ae37f16e2a93cbe237a2f1..a3087d78835677f686d48bddb7b265ebc162420f 100644 (file)
@@ -1479,30 +1479,38 @@ static int write_graph_chunk_bloom_data(struct hashfile *f,
        return 0;
 }
 
+static int add_packed_commits_oi(const struct object_id *oid,
+                                struct object_info *oi,
+                                void *data)
+{
+       struct write_commit_graph_context *ctx = (struct write_commit_graph_context*)data;
+
+       if (ctx->progress)
+               display_progress(ctx->progress, ++ctx->progress_done);
+
+       if (*oi->typep != OBJ_COMMIT)
+               return 0;
+
+       oid_array_append(&ctx->oids, oid);
+       set_commit_pos(ctx->r, oid);
+
+       return 0;
+}
+
 static int add_packed_commits(const struct object_id *oid,
                              struct packed_git *pack,
                              uint32_t pos,
                              void *data)
 {
-       struct write_commit_graph_context *ctx = (struct write_commit_graph_context*)data;
        enum object_type type;
        off_t offset = nth_packed_object_offset(pack, pos);
        struct object_info oi = OBJECT_INFO_INIT;
 
-       if (ctx->progress)
-               display_progress(ctx->progress, ++ctx->progress_done);
-
        oi.typep = &type;
        if (packed_object_info(pack, offset, &oi) < 0)
                die(_("unable to get type of object %s"), oid_to_hex(oid));
 
-       if (type != OBJ_COMMIT)
-               return 0;
-
-       oid_array_append(&ctx->oids, oid);
-       set_commit_pos(ctx->r, oid);
-
-       return 0;
+       return add_packed_commits_oi(oid, &oi, data);
 }
 
 static void add_missing_parents(struct write_commit_graph_context *ctx, struct commit *commit)
@@ -1959,13 +1967,23 @@ static int fill_oids_from_commits(struct write_commit_graph_context *ctx,
 
 static void fill_oids_from_all_packs(struct write_commit_graph_context *ctx)
 {
+       struct odb_source *source;
+       enum object_type type;
+       struct object_info oi = {
+               .typep = &type,
+       };
+
        if (ctx->report_progress)
                ctx->progress = start_delayed_progress(
                        ctx->r,
                        _("Finding commits for commit graph among packed objects"),
                        ctx->approx_nr_objects);
-       for_each_packed_object(ctx->r, add_packed_commits, ctx,
-                              ODB_FOR_EACH_OBJECT_PACK_ORDER);
+
+       odb_prepare_alternates(ctx->r->objects);
+       for (source = ctx->r->objects->sources; source; source = source->next)
+               packfile_store_for_each_object(source->packfiles, &oi, add_packed_commits_oi,
+                                              ctx, ODB_FOR_EACH_OBJECT_PACK_ORDER);
+
        if (ctx->progress_done < ctx->approx_nr_objects)
                display_progress(ctx->progress, ctx->approx_nr_objects);
        stop_progress(&ctx->progress);