]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb/source-packed: drop pointer to "files" parent source
authorPatrick Steinhardt <ps@pks.im>
Wed, 17 Jun 2026 06:40:00 +0000 (08:40 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 17 Jun 2026 12:00:01 +0000 (05:00 -0700)
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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
odb/source-files.c
odb/source-packed.c
odb/source-packed.h
packfile.c

index fa2e18e71b3cf6579d12fbf775978316c270e7ec..3bc6419dd7e2f9c56a2fc58db63ea29c8e699bf3 100644 (file)
@@ -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;
index d513b3efc367fdefd625394ed69df595f98799a1..42c28fba0e34b260d5e059b56acf11be6a56d63f 100644 (file)
@@ -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;
index 9d4796261a72d3dfecae9d3ac3ac6ed579ce85a5..88994098c18e7d12ac6d57566d63ecdf5cdc35a6 100644 (file)
@@ -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
index a577275d4f334e4e803cb7ee926afe5efbe1fc22..59cee7925daf0be593eef5d0c7c4dca131dec08f 100644 (file)
@@ -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);