]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb: adopt logic to close object databases
authorPatrick Steinhardt <ps@pks.im>
Wed, 19 Nov 2025 07:50:51 +0000 (08:50 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 20 Nov 2025 01:41:03 +0000 (17:41 -0800)
The logic to close an object database is currently contained in the
packfile subsystem. That choice is somewhat relatable, as most of the
logic really is to close resources associated with the packfile store
itself. But we also end up handling object sources and commit graphs,
which certainly is not related to packfiles.

Move the function into the object database subsystem and rename it to
`odb_close()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/clone.c
builtin/gc.c
builtin/repack.c
midx-write.c
odb.c
odb.h
packfile.c
packfile.h
run-command.c
scalar.c

index c990f398ef6f37ef5c7b30941491722f633c54c8..b19b302b06546710b7c8bc20b696a0944c9f1b78 100644 (file)
@@ -1617,7 +1617,7 @@ int cmd_clone(int argc,
        transport_disconnect(transport);
 
        if (option_dissociate) {
-               close_object_store(the_repository->objects);
+               odb_close(the_repository->objects);
                dissociate_from_references();
        }
 
index d212cbb9b847810a83856d74cba5edc5a99f1c38..961fa343c4b1803f9eb64cf335a9a1cb7c5c72ef 100644 (file)
@@ -1048,7 +1048,7 @@ int cmd_gc(int argc,
        report_garbage = report_pack_garbage;
        odb_reprepare(the_repository->objects);
        if (pack_garbage.nr > 0) {
-               close_object_store(the_repository->objects);
+               odb_close(the_repository->objects);
                clean_pack_garbage();
        }
 
index cfdb4c0920b191de4b6d1d98d263974116acb678..d9012141f699c9174cf51d79542130ec541a8950 100644 (file)
@@ -488,7 +488,7 @@ int cmd_repack(int argc,
 
        string_list_sort(&names);
 
-       close_object_store(repo->objects);
+       odb_close(repo->objects);
 
        /*
         * Ok we have prepared all new packfiles.
index c73010df6d3a4fe5c241597500f35bf5a71188dd..60497586fdf2f472e7b63a146b929fcbad0fa9c8 100644 (file)
@@ -1459,7 +1459,7 @@ static int write_midx_internal(struct odb_source *source,
        }
 
        if (ctx.m || ctx.base_midx)
-               close_object_store(ctx.repo->objects);
+               odb_close(ctx.repo->objects);
 
        if (commit_lock_file(&lk) < 0)
                die_errno(_("could not write multi-pack-index"));
diff --git a/odb.c b/odb.c
index 3ec21ef24e16bb6da22b58abfa50553318f98761..bcefa5cede60b524852c19a8b1f9ab03382dab88 100644 (file)
--- a/odb.c
+++ b/odb.c
@@ -9,6 +9,7 @@
 #include "khash.h"
 #include "lockfile.h"
 #include "loose.h"
+#include "midx.h"
 #include "object-file-convert.h"
 #include "object-file.h"
 #include "odb.h"
@@ -1044,6 +1045,21 @@ struct object_database *odb_new(struct repository *repo)
        return o;
 }
 
+void odb_close(struct object_database *o)
+{
+       struct odb_source *source;
+
+       packfile_store_close(o->packfiles);
+
+       for (source = o->sources; source; source = source->next) {
+               if (source->midx)
+                       close_midx(source->midx);
+               source->midx = NULL;
+       }
+
+       close_commit_graph(o);
+}
+
 static void odb_free_sources(struct object_database *o)
 {
        while (o->sources) {
@@ -1076,7 +1092,7 @@ void odb_clear(struct object_database *o)
                free((char *) o->cached_objects[i].value.buf);
        FREE_AND_NULL(o->cached_objects);
 
-       close_object_store(o);
+       odb_close(o);
        packfile_store_free(o->packfiles);
        o->packfiles = NULL;
 
diff --git a/odb.h b/odb.h
index 9bb28008b1d953774ee198828298cec364478201..71b4897c82f3a87146422b4eff92ab61c1455b53 100644 (file)
--- a/odb.h
+++ b/odb.h
@@ -169,6 +169,13 @@ struct object_database {
 struct object_database *odb_new(struct repository *repo);
 void odb_clear(struct object_database *o);
 
+/*
+ * Close the object database and all of its sources so that any held resources
+ * will be released. The database can still be used after closing it, in which
+ * case these resources may be reallocated.
+ */
+void odb_close(struct object_database *o);
+
 /*
  * Clear caches, reload alternates and then reload object sources so that new
  * objects may become accessible.
index 40f733dd234900662dc23d5c48906690b0046d88..af71eaf7e344610614ac152bb6e66944115ef16f 100644 (file)
@@ -359,21 +359,6 @@ void close_pack(struct packed_git *p)
        oidset_clear(&p->bad_objects);
 }
 
-void close_object_store(struct object_database *o)
-{
-       struct odb_source *source;
-
-       packfile_store_close(o->packfiles);
-
-       for (source = o->sources; source; source = source->next) {
-               if (source->midx)
-                       close_midx(source->midx);
-               source->midx = NULL;
-       }
-
-       close_commit_graph(o);
-}
-
 void unlink_pack_path(const char *pack_name, int force_delete)
 {
        static const char *exts[] = {".idx", ".pack", ".rev", ".keep", ".bitmap", ".promisor", ".mtimes"};
index 58fcc88e20224b18319168d4d6efdb6e2d6a3dff..d9226a072ac96d73e313743b93bc70bf64bed593 100644 (file)
@@ -279,7 +279,6 @@ struct object_database;
 unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
 void close_pack_windows(struct packed_git *);
 void close_pack(struct packed_git *);
-void close_object_store(struct object_database *o);
 void unuse_pack(struct pack_window **);
 void clear_delta_base_cache(void);
 struct packed_git *add_packed_git(struct repository *r, const char *path,
index ed9575bd6a8cbbab0f25b92e09cf9c2752498523..e3e02475ccec50163865d571902b18ba2e339a36 100644 (file)
@@ -743,7 +743,7 @@ fail_pipe:
        fflush(NULL);
 
        if (cmd->close_object_store)
-               close_object_store(the_repository->objects);
+               odb_close(the_repository->objects);
 
 #ifndef GIT_WINDOWS_NATIVE
 {
index f7543116272b773f7f54f4a4638dd78a5a6f9e3e..2aeb191cc89b729c55b7a748e1d67ae8b23b72a3 100644 (file)
--- a/scalar.c
+++ b/scalar.c
@@ -931,7 +931,7 @@ static int cmd_delete(int argc, const char **argv)
        if (dir_inside_of(cwd, enlistment.buf) >= 0)
                res = error(_("refusing to delete current working directory"));
        else {
-               close_object_store(the_repository->objects);
+               odb_close(the_repository->objects);
                res = delete_enlistment(&enlistment);
        }
        strbuf_release(&enlistment);