]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb/source: make `close()` function pluggable
authorPatrick Steinhardt <ps@pks.im>
Thu, 5 Mar 2026 14:19:48 +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.c
odb/source-files.c
odb/source.h

diff --git a/odb.c b/odb.c
index 2cf6a53dc32baec494f8a600beccf474319e9cbe..f7487eb0df93b9004d0ff18284d37254859880c3 100644 (file)
--- a/odb.c
+++ b/odb.c
@@ -1062,10 +1062,8 @@ struct object_database *odb_new(struct repository *repo,
 void odb_close(struct object_database *o)
 {
        struct odb_source *source;
-       for (source = o->sources; source; source = source->next) {
-               struct odb_source_files *files = odb_source_files_downcast(source);
-               packfile_store_close(files->packed);
-       }
+       for (source = o->sources; source; source = source->next)
+               odb_source_close(source);
        close_commit_graph(o);
 }
 
index d0f7ee072ed3475732281c3aba56e3e5d905401b..20a24f524a46cd4772f1375d73ac8cf86852208c 100644 (file)
@@ -28,6 +28,12 @@ static void odb_source_files_free(struct odb_source *source)
        free(files);
 }
 
+static void odb_source_files_close(struct odb_source *source)
+{
+       struct odb_source_files *files = odb_source_files_downcast(source);
+       packfile_store_close(files->packed);
+}
+
 static void odb_source_files_reprepare(struct odb_source *source)
 {
        struct odb_source_files *files = odb_source_files_downcast(source);
@@ -47,6 +53,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
        files->packed = packfile_store_new(&files->base);
 
        files->base.free = odb_source_files_free;
+       files->base.close = odb_source_files_close;
        files->base.reprepare = odb_source_files_reprepare;
 
        /*
index 09cca839fedbfeeb42da21bb6e37246c875c200d..0e6c6abdb1c19ad752d194a001c0f4bfb35f5b06 100644 (file)
@@ -58,6 +58,14 @@ struct odb_source {
         */
        void (*free)(struct odb_source *source);
 
+       /*
+        * This callback is expected to close any open resources, like for
+        * example file descriptors or connections. The source is expected to
+        * still be usable after it has been closed. Closed resources may need
+        * to be reopened in that case.
+        */
+       void (*close)(struct odb_source *source);
+
        /*
         * This callback is expected to clear underlying caches of the object
         * database source. The function is called when the repository has for
@@ -103,6 +111,16 @@ void odb_source_free(struct odb_source *source);
  */
 void odb_source_release(struct odb_source *source);
 
+/*
+ * Close the object database source without releasing he underlying data. The
+ * source can still be used going forward, but it first needs to be reopened.
+ * This can be useful to reduce resource usage.
+ */
+static inline void odb_source_close(struct odb_source *source)
+{
+       source->close(source);
+}
+
 /*
  * Reprepare the object database source and clear any caches. Depending on the
  * backend used this may have the effect that concurrently-written objects