packfile: pass source to prepare_pack()

When preparing a packfile we pass various pieces attached to the pack's
object database source via the `struct prepare_pack_data`. Refactor this
code to instead pass in the source directly. This reduces the number of
variables we need to pass and allows for a subsequent refactoring where
we start to prepare the pack via the source.

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-09 09:33:10 +01:00 committed by Junio C Hamano
parent 480336a9ce
commit 0316c63ca4

View File

@ -975,10 +975,8 @@ void for_each_file_in_pack_dir(const char *objdir,
}
struct prepare_pack_data {
struct repository *r;
struct odb_source *source;
struct string_list *garbage;
int local;
struct multi_pack_index *m;
};
static void prepare_pack(const char *full_name, size_t full_name_len,
@ -988,10 +986,10 @@ static void prepare_pack(const char *full_name, size_t full_name_len,
size_t base_len = full_name_len;
if (strip_suffix_mem(full_name, &base_len, ".idx") &&
!(data->m && midx_contains_pack(data->m, file_name))) {
!(data->source->midx && midx_contains_pack(data->source->midx, file_name))) {
char *trimmed_path = xstrndup(full_name, full_name_len);
packfile_store_load_pack(data->r->objects->packfiles,
trimmed_path, data->local);
packfile_store_load_pack(data->source->odb->packfiles,
trimmed_path, data->source->local);
free(trimmed_path);
}
@ -1020,10 +1018,8 @@ static void prepare_packed_git_one(struct odb_source *source)
{
struct string_list garbage = STRING_LIST_INIT_DUP;
struct prepare_pack_data data = {
.m = source->midx,
.r = source->odb->repo,
.source = source,
.garbage = &garbage,
.local = source->local,
};
for_each_file_in_pack_dir(source->path, prepare_pack, &data);