From 1bba3c035d2283456edcb159e965b8be2015e114 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 17 Jun 2026 08:40:00 +0200 Subject: [PATCH] odb/source-packed: drop pointer to "files" parent source Over the last commits we have turned the packfile store into a proper object database source that can be used as a standalone backend. As such, it is no longer necessary to have it coupled to the "files" parent source. Remove the pointer to the owning "files" source so that the "packed" source can be used as a standalone entity. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- odb/source-files.c | 2 +- odb/source-packed.c | 27 +++++++++++++-------------- odb/source-packed.h | 7 ++++--- packfile.c | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/odb/source-files.c b/odb/source-files.c index fa2e18e71b..3bc6419dd7 100644 --- a/odb/source-files.c +++ b/odb/source-files.c @@ -269,7 +269,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb, CALLOC_ARRAY(files, 1); odb_source_init(&files->base, odb, ODB_SOURCE_FILES, path, local); files->loose = odb_source_loose_new(odb, path, local); - files->packed = odb_source_packed_new(files); + files->packed = odb_source_packed_new(odb, path, local); files->base.free = odb_source_files_free; files->base.close = odb_source_files_close; diff --git a/odb/source-packed.c b/odb/source-packed.c index d513b3efc3..42c28fba0e 100644 --- a/odb/source-packed.c +++ b/odb/source-packed.c @@ -585,7 +585,7 @@ static void report_pack_garbage(struct string_list *list) } struct prepare_pack_data { - struct odb_source *source; + struct odb_source_packed *source; struct string_list *garbage; }; @@ -593,15 +593,14 @@ static void prepare_pack(const char *full_name, size_t full_name_len, const char *file_name, void *_data) { struct prepare_pack_data *data = (struct prepare_pack_data *)_data; - struct odb_source_files *files = odb_source_files_downcast(data->source); size_t base_len = full_name_len; if (strip_suffix_mem(full_name, &base_len, ".idx") && - !(files->packed->midx && - midx_contains_pack(files->packed->midx, 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(files->packed, - trimmed_path, data->source->local); + packfile_store_load_pack(data->source, + trimmed_path, data->source->base.local); free(trimmed_path); } @@ -626,7 +625,7 @@ static void prepare_pack(const char *full_name, size_t full_name_len, report_garbage(PACKDIR_FILE_GARBAGE, full_name); } -static void prepare_packed_git_one(struct odb_source *source) +static void prepare_packed_git_one(struct odb_source_packed *source) { struct string_list garbage = STRING_LIST_INIT_DUP; struct prepare_pack_data data = { @@ -634,7 +633,7 @@ static void prepare_packed_git_one(struct odb_source *source) .garbage = &garbage, }; - for_each_file_in_pack_dir(source->path, prepare_pack, &data); + for_each_file_in_pack_dir(source->base.path, prepare_pack, &data); report_pack_garbage(data.garbage); string_list_clear(data.garbage, 0); @@ -675,7 +674,7 @@ void odb_source_packed_prepare(struct odb_source_packed *source) return; prepare_multi_pack_index_one(source); - prepare_packed_git_one(&source->files->base); + prepare_packed_git_one(source); sort_packs(&source->packs.head, sort_pack); for (struct packfile_list_entry *e = source->packs.head; e; e = e->next) @@ -733,14 +732,14 @@ static void odb_source_packed_free(struct odb_source *source) free(packed); } -struct odb_source_packed *odb_source_packed_new(struct odb_source_files *parent) +struct odb_source_packed *odb_source_packed_new(struct object_database *odb, + const char *path, + bool local) { struct odb_source_packed *packed; CALLOC_ARRAY(packed, 1); - odb_source_init(&packed->base, parent->base.odb, ODB_SOURCE_PACKED, - parent->base.path, parent->base.local); - packed->files = parent; + odb_source_init(&packed->base, odb, ODB_SOURCE_PACKED, path, local); strmap_init(&packed->packs_by_path); packed->base.free = odb_source_packed_free; @@ -758,7 +757,7 @@ struct odb_source_packed *odb_source_packed_new(struct odb_source_files *parent) packed->base.read_alternates = odb_source_packed_read_alternates; packed->base.write_alternate = odb_source_packed_write_alternate; - if (!is_absolute_path(parent->base.path)) + if (!is_absolute_path(path)) chdir_notify_register(NULL, odb_source_packed_reparent, packed); return packed; diff --git a/odb/source-packed.h b/odb/source-packed.h index 9d4796261a..88994098c1 100644 --- a/odb/source-packed.h +++ b/odb/source-packed.h @@ -10,7 +10,6 @@ */ struct odb_source_packed { struct odb_source base; - struct odb_source_files *files; /* * The list of packfiles in the order in which they have been most @@ -66,9 +65,11 @@ struct odb_source_packed { /* * Allocate and initialize a new empty packfile store for the given object - * database source. + * database. */ -struct odb_source_packed *odb_source_packed_new(struct odb_source_files *parent); +struct odb_source_packed *odb_source_packed_new(struct object_database *odb, + const char *path, + bool local); /* * Cast the given object database source to the packed backend. This will cause diff --git a/packfile.c b/packfile.c index a577275d4f..59cee7925d 100644 --- a/packfile.c +++ b/packfile.c @@ -801,7 +801,7 @@ struct packed_git *packfile_store_load_pack(struct odb_source_packed *store, p = strmap_get(&store->packs_by_path, key.buf); if (!p) { - p = add_packed_git(store->files->base.odb->repo, idx_path, + p = add_packed_git(store->base.odb->repo, idx_path, strlen(idx_path), local); if (p) packfile_store_add_pack(store, p);