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>
This commit is contained in:
Patrick Steinhardt
2026-01-26 10:51:26 +01:00
committed by Junio C Hamano
parent 2813c97310
commit 317ea9a6c3
2 changed files with 60 additions and 20 deletions

View 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,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);

View File

@@ -1479,24 +1479,16 @@ static int write_graph_chunk_bloom_data(struct hashfile *f,
return 0;
}
static int add_packed_commits(const struct object_id *oid,
struct packed_git *pack,
uint32_t pos,
void *data)
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;
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)
if (*oi->typep != OBJ_COMMIT)
return 0;
oid_array_append(&ctx->oids, oid);
@@ -1505,6 +1497,22 @@ static int add_packed_commits(const struct object_id *oid,
return 0;
}
static int add_packed_commits(const struct object_id *oid,
struct packed_git *pack,
uint32_t pos,
void *data)
{
enum object_type type;
off_t offset = nth_packed_object_offset(pack, pos);
struct object_info oi = OBJECT_INFO_INIT;
oi.typep = &type;
if (packed_object_info(pack, offset, &oi) < 0)
die(_("unable to get type of object %s"), oid_to_hex(oid));
return add_packed_commits_oi(oid, &oi, data);
}
static void add_missing_parents(struct write_commit_graph_context *ctx, struct commit *commit)
{
struct commit_list *parent;
@@ -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);