Skip to content

Commit 317ea9a

Browse files
pks-tgitster
authored andcommitted
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>
1 parent 2813c97 commit 317ea9a

2 files changed

Lines changed: 59 additions & 19 deletions

File tree

builtin/cat-file.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -806,11 +806,14 @@ struct for_each_object_payload {
806806
void *payload;
807807
};
808808

809-
static int batch_one_object_loose(const struct object_id *oid,
810-
const char *path UNUSED,
811-
void *_payload)
809+
static int batch_one_object_oi(const struct object_id *oid,
810+
struct object_info *oi,
811+
void *_payload)
812812
{
813813
struct for_each_object_payload *payload = _payload;
814+
if (oi && oi->whence == OI_PACKED)
815+
return payload->callback(oid, oi->u.packed.pack, oi->u.packed.offset,
816+
payload->payload);
814817
return payload->callback(oid, NULL, 0, payload->payload);
815818
}
816819

@@ -846,8 +849,21 @@ static void batch_each_object(struct batch_options *opt,
846849
.payload = _payload,
847850
};
848851
struct bitmap_index *bitmap = prepare_bitmap_git(the_repository);
852+
struct odb_source *source;
849853

850-
for_each_loose_object(the_repository->objects, batch_one_object_loose, &payload, 0);
854+
/*
855+
* TODO: we still need to tap into implementation details of the object
856+
* database sources. Ideally, we should extend `odb_for_each_object()`
857+
* to handle object filters itself so that we can move the filtering
858+
* logic into the individual sources.
859+
*/
860+
odb_prepare_alternates(the_repository->objects);
861+
for (source = the_repository->objects->sources; source; source = source->next) {
862+
int ret = odb_source_loose_for_each_object(source, NULL, batch_one_object_oi,
863+
&payload, flags);
864+
if (ret)
865+
break;
866+
}
851867

852868
if (bitmap && !for_each_bitmapped_object(bitmap, &opt->objects_filter,
853869
batch_one_object_bitmapped, &payload)) {
@@ -861,8 +877,14 @@ static void batch_each_object(struct batch_options *opt,
861877
&payload, flags);
862878
}
863879
} else {
864-
for_each_packed_object(the_repository, batch_one_object_packed,
865-
&payload, flags);
880+
struct object_info oi = { 0 };
881+
882+
for (source = the_repository->objects->sources; source; source = source->next) {
883+
int ret = packfile_store_for_each_object(source->packfiles, &oi,
884+
batch_one_object_oi, &payload, flags);
885+
if (ret)
886+
break;
887+
}
866888
}
867889

868890
free_bitmap_index(bitmap);

commit-graph.c

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,30 +1479,38 @@ static int write_graph_chunk_bloom_data(struct hashfile *f,
14791479
return 0;
14801480
}
14811481

1482+
static int add_packed_commits_oi(const struct object_id *oid,
1483+
struct object_info *oi,
1484+
void *data)
1485+
{
1486+
struct write_commit_graph_context *ctx = (struct write_commit_graph_context*)data;
1487+
1488+
if (ctx->progress)
1489+
display_progress(ctx->progress, ++ctx->progress_done);
1490+
1491+
if (*oi->typep != OBJ_COMMIT)
1492+
return 0;
1493+
1494+
oid_array_append(&ctx->oids, oid);
1495+
set_commit_pos(ctx->r, oid);
1496+
1497+
return 0;
1498+
}
1499+
14821500
static int add_packed_commits(const struct object_id *oid,
14831501
struct packed_git *pack,
14841502
uint32_t pos,
14851503
void *data)
14861504
{
1487-
struct write_commit_graph_context *ctx = (struct write_commit_graph_context*)data;
14881505
enum object_type type;
14891506
off_t offset = nth_packed_object_offset(pack, pos);
14901507
struct object_info oi = OBJECT_INFO_INIT;
14911508

1492-
if (ctx->progress)
1493-
display_progress(ctx->progress, ++ctx->progress_done);
1494-
14951509
oi.typep = &type;
14961510
if (packed_object_info(pack, offset, &oi) < 0)
14971511
die(_("unable to get type of object %s"), oid_to_hex(oid));
14981512

1499-
if (type != OBJ_COMMIT)
1500-
return 0;
1501-
1502-
oid_array_append(&ctx->oids, oid);
1503-
set_commit_pos(ctx->r, oid);
1504-
1505-
return 0;
1513+
return add_packed_commits_oi(oid, &oi, data);
15061514
}
15071515

15081516
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,
19591967

19601968
static void fill_oids_from_all_packs(struct write_commit_graph_context *ctx)
19611969
{
1970+
struct odb_source *source;
1971+
enum object_type type;
1972+
struct object_info oi = {
1973+
.typep = &type,
1974+
};
1975+
19621976
if (ctx->report_progress)
19631977
ctx->progress = start_delayed_progress(
19641978
ctx->r,
19651979
_("Finding commits for commit graph among packed objects"),
19661980
ctx->approx_nr_objects);
1967-
for_each_packed_object(ctx->r, add_packed_commits, ctx,
1968-
ODB_FOR_EACH_OBJECT_PACK_ORDER);
1981+
1982+
odb_prepare_alternates(ctx->r->objects);
1983+
for (source = ctx->r->objects->sources; source; source = source->next)
1984+
packfile_store_for_each_object(source->packfiles, &oi, add_packed_commits_oi,
1985+
ctx, ODB_FOR_EACH_OBJECT_PACK_ORDER);
1986+
19691987
if (ctx->progress_done < ctx->approx_nr_objects)
19701988
display_progress(ctx->progress, ctx->approx_nr_objects);
19711989
stop_progress(&ctx->progress);

0 commit comments

Comments
 (0)