Skip to content

Commit dd097bb

Browse files
pks-tgitster
authored andcommitted
builtin/pack-objects: use packfile_store_for_each_object()
When enumerating objects that are supposed to be stored in a new cruft pack we use `for_each_packed_object()` and then derive each object's mtime individually. Refactor this logic to instead use the new `packfile_store_for_each_object()` function with an object info request that asks for the respective mtimes. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 7b7cbae commit dd097bb

1 file changed

Lines changed: 22 additions & 24 deletions

File tree

builtin/pack-objects.c

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4314,25 +4314,12 @@ static void show_edge(struct commit *commit)
43144314
}
43154315

43164316
static int add_object_in_unpacked_pack(const struct object_id *oid,
4317-
struct packed_git *pack,
4318-
uint32_t pos,
4317+
struct object_info *oi,
43194318
void *data UNUSED)
43204319
{
43214320
if (cruft) {
4322-
off_t offset;
4323-
time_t mtime;
4324-
4325-
if (pack->is_cruft) {
4326-
if (load_pack_mtimes(pack) < 0)
4327-
die(_("could not load cruft pack .mtimes"));
4328-
mtime = nth_packed_mtime(pack, pos);
4329-
} else {
4330-
mtime = pack->mtime;
4331-
}
4332-
offset = nth_packed_object_offset(pack, pos);
4333-
4334-
add_cruft_object_entry(oid, OBJ_NONE, pack, offset,
4335-
NULL, mtime);
4321+
add_cruft_object_entry(oid, OBJ_NONE, oi->u.packed.pack,
4322+
oi->u.packed.offset, NULL, *oi->mtimep);
43364323
} else {
43374324
add_object_entry(oid, OBJ_NONE, "", 0);
43384325
}
@@ -4341,14 +4328,25 @@ static int add_object_in_unpacked_pack(const struct object_id *oid,
43414328

43424329
static void add_objects_in_unpacked_packs(void)
43434330
{
4344-
if (for_each_packed_object(to_pack.repo,
4345-
add_object_in_unpacked_pack,
4346-
NULL,
4347-
ODB_FOR_EACH_OBJECT_PACK_ORDER |
4348-
ODB_FOR_EACH_OBJECT_LOCAL_ONLY |
4349-
ODB_FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS |
4350-
ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS))
4351-
die(_("cannot open pack index"));
4331+
struct odb_source *source;
4332+
time_t mtime;
4333+
struct object_info oi = {
4334+
.mtimep = &mtime,
4335+
};
4336+
4337+
odb_prepare_alternates(to_pack.repo->objects);
4338+
for (source = to_pack.repo->objects->sources; source; source = source->next) {
4339+
if (!source->local)
4340+
continue;
4341+
4342+
if (packfile_store_for_each_object(source->packfiles, &oi,
4343+
add_object_in_unpacked_pack, NULL,
4344+
ODB_FOR_EACH_OBJECT_PACK_ORDER |
4345+
ODB_FOR_EACH_OBJECT_LOCAL_ONLY |
4346+
ODB_FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS |
4347+
ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS))
4348+
die(_("cannot open pack index"));
4349+
}
43524350
}
43534351

43544352
static int add_loose_object(const struct object_id *oid, const char *path,

0 commit comments

Comments
 (0)