diff options
| author | Patrick Steinhardt <ps@pks.im> | 2026-01-26 10:51:26 +0100 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-01-26 08:26:07 -0800 |
| commit | 317ea9a6c3c134a1bcdee49bbbbf1731c17b967a (patch) | |
| tree | d64034f71e3773f95825eb384be5b8c608c87ca1 /commit-graph.c | |
| parent | 2813c97310a998510ad4bcbbf38a774fd6bb5386 (diff) | |
| download | git-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 'commit-graph.c')
| -rw-r--r-- | commit-graph.c | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/commit-graph.c b/commit-graph.c index 7f1145a082..a3087d7883 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -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); |
