]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb/source: make `free()` function pluggable
authorPatrick Steinhardt <ps@pks.im>
Thu, 5 Mar 2026 14:19:46 +0000 (15:19 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 5 Mar 2026 19:45:15 +0000 (11:45 -0800)
Introduce a new callback function in `struct odb_source` to make the
function pluggable.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
odb/source-files.c
odb/source-files.h
odb/source.c
odb/source.h

index 7496e1d9f82266474ce500cf5b4e0f62c84a2faf..65d7805c5a88f2c80eb0944c8d5ed7cc350e9481 100644 (file)
@@ -18,10 +18,9 @@ static void odb_source_files_reparent(const char *name UNUSED,
        files->base.path = path;
 }
 
-void odb_source_files_free(struct odb_source_files *files)
+static void odb_source_files_free(struct odb_source *source)
 {
-       if (!files)
-               return;
+       struct odb_source_files *files = odb_source_files_downcast(source);
        chdir_notify_unregister(NULL, odb_source_files_reparent, files);
        odb_source_loose_free(files->loose);
        packfile_store_free(files->packed);
@@ -40,6 +39,8 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
        files->loose = odb_source_loose_new(&files->base);
        files->packed = packfile_store_new(&files->base);
 
+       files->base.free = odb_source_files_free;
+
        /*
         * Ideally, we would only ever store absolute paths in the source. This
         * is not (yet) possible though because we access and assume relative
index 803fa995fb961101f604aa9dbe9a1a4c2dfed76b..23a3b4e04b1218344b3cad09816dd4054a2014df 100644 (file)
@@ -21,9 +21,6 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
                                              const char *path,
                                              bool local);
 
-/* Free the object source and release all associated resources. */
-void odb_source_files_free(struct odb_source_files *files);
-
 /*
  * Cast the given object database source to the files backend. This will cause
  * a BUG in case the source doesn't use this backend.
index c7dcc528f62bb5bb5b0aefbc651382ab539745a5..7993dcbd659399f963798e0905de65b7a456132f 100644 (file)
@@ -25,11 +25,9 @@ void odb_source_init(struct odb_source *source,
 
 void odb_source_free(struct odb_source *source)
 {
-       struct odb_source_files *files;
        if (!source)
                return;
-       files = odb_source_files_downcast(source);
-       odb_source_files_free(files);
+       source->free(source);
 }
 
 void odb_source_release(struct odb_source *source)
index 45b72b81a0ad182be04aaafc1012e96fcde12838..4973fb425175b6b26c9ea1115f093c67366ac621 100644 (file)
@@ -51,6 +51,12 @@ struct odb_source {
         * the current working directory.
         */
        char *path;
+
+       /*
+        * This callback is expected to free the underlying object database source and
+        * all associated resources. The function will never be called with a NULL pointer.
+        */
+       void (*free)(struct odb_source *source);
 };
 
 /*