]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb/source: make `reprepare()` function pluggable
authorPatrick Steinhardt <ps@pks.im>
Thu, 5 Mar 2026 14:19:47 +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 86f7cf70a87310ea2ab9cadcec5082dbc772d6ab..2cf6a53dc32baec494f8a600beccf474319e9cbe 100644 (file)
--- a/odb.c
+++ b/odb.c
@@ -1119,11 +1119,8 @@ void odb_reprepare(struct object_database *o)
        o->loaded_alternates = 0;
        odb_prepare_alternates(o);
 
-       for (source = o->sources; source; source = source->next) {
-               struct odb_source_files *files = odb_source_files_downcast(source);
-               odb_source_loose_reprepare(source);
-               packfile_store_reprepare(files->packed);
-       }
+       for (source = o->sources; source; source = source->next)
+               odb_source_reprepare(source);
 
        o->approximate_object_count_valid = 0;
 
index 65d7805c5a88f2c80eb0944c8d5ed7cc350e9481..d0f7ee072ed3475732281c3aba56e3e5d905401b 100644 (file)
@@ -28,6 +28,13 @@ static void odb_source_files_free(struct odb_source *source)
        free(files);
 }
 
+static void odb_source_files_reprepare(struct odb_source *source)
+{
+       struct odb_source_files *files = odb_source_files_downcast(source);
+       odb_source_loose_reprepare(&files->base);
+       packfile_store_reprepare(files->packed);
+}
+
 struct odb_source_files *odb_source_files_new(struct object_database *odb,
                                              const char *path,
                                              bool local)
@@ -40,6 +47,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.reprepare = odb_source_files_reprepare;
 
        /*
         * Ideally, we would only ever store absolute paths in the source. This
index 4973fb425175b6b26c9ea1115f093c67366ac621..09cca839fedbfeeb42da21bb6e37246c875c200d 100644 (file)
@@ -57,6 +57,13 @@ struct odb_source {
         * all associated resources. The function will never be called with a NULL pointer.
         */
        void (*free)(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
+        * example just been repacked so that new objects will become visible.
+        */
+       void (*reprepare)(struct odb_source *source);
 };
 
 /*
@@ -96,4 +103,14 @@ void odb_source_free(struct odb_source *source);
  */
 void odb_source_release(struct odb_source *source);
 
+/*
+ * Reprepare the object database source and clear any caches. Depending on the
+ * backend used this may have the effect that concurrently-written objects
+ * become visible.
+ */
+static inline void odb_source_reprepare(struct odb_source *source)
+{
+       source->reprepare(source);
+}
+
 #endif