odb: adopt logic to close object databases
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>
Patrick Steinhardt committed
Nov 19, 2025 at 08:50 UTC
9aaba579932781c74f67d6cecddaad59f0daaaef
10 files changed
+30
-23
builtin/clone.c
+1
-1
@@ -1617,7 +1617,7 @@ int cmd_clone(int argc,
1617
transport_disconnect(transport);
1618
1619
if (option_dissociate) {
1620
- close_object_store(the_repository->objects);
1620
+ odb_close(the_repository->objects);
1621
dissociate_from_references();
1622
}
1623
builtin/gc.c
+1
-1
@@ -1048,7 +1048,7 @@ int cmd_gc(int argc,
1048
report_garbage = report_pack_garbage;
1049
odb_reprepare(the_repository->objects);
1050
if (pack_garbage.nr > 0) {
1051
- close_object_store(the_repository->objects);
1051
+ odb_close(the_repository->objects);
1052
clean_pack_garbage();
1053
}
1054
builtin/repack.c
+1
-1
@@ -488,7 +488,7 @@ int cmd_repack(int argc,
488
489
string_list_sort(&names);
490
491
- close_object_store(repo->objects);
491
+ odb_close(repo->objects);
492
493
/*
494
* Ok we have prepared all new packfiles.
midx-write.c
+1
-1
@@ -1459,7 +1459,7 @@ static int write_midx_internal(struct odb_source *source,
1459
}
1460
1461
if (ctx.m || ctx.base_midx)
1462
- close_object_store(ctx.repo->objects);
1462
+ odb_close(ctx.repo->objects);
1463
1464
if (commit_lock_file(&lk) < 0)
1465
die_errno(_("could not write multi-pack-index"));
odb.c
+17
-1
@@ -9,6 +9,7 @@
9
#include "khash.h"
10
#include "lockfile.h"
11
#include "loose.h"
12
+#include "midx.h"
13
#include "object-file-convert.h"
14
#include "object-file.h"
15
#include "odb.h"
@@ -1044,6 +1045,21 @@ struct object_database *odb_new(struct repository *repo)
1045
return o;
1046
}
1047
1048
+void odb_close(struct object_database *o)
1049
+{
1050
+ struct odb_source *source;
1051
+
1052
+ packfile_store_close(o->packfiles);
1053
+
1054
+ for (source = o->sources; source; source = source->next) {
1055
+ if (source->midx)
1056
+ close_midx(source->midx);
1057
+ source->midx = NULL;
1058
+ }
1059
+
1060
+ close_commit_graph(o);
1061
+}
1062
+
1063
static void odb_free_sources(struct object_database *o)
1064
{
1065
while (o->sources) {
@@ -1076,7 +1092,7 @@ void odb_clear(struct object_database *o)
1092
free((char *) o->cached_objects[i].value.buf);
1093
FREE_AND_NULL(o->cached_objects);
1094
1079
- close_object_store(o);
1095
+ odb_close(o);
1096
packfile_store_free(o->packfiles);
1097
o->packfiles = NULL;
1098
odb.h
+7
@@ -169,6 +169,13 @@ struct object_database {
169
struct object_database *odb_new(struct repository *repo);
170
void odb_clear(struct object_database *o);
171
172
+/*
173
+ * Close the object database and all of its sources so that any held resources
174
+ * will be released. The database can still be used after closing it, in which
175
+ * case these resources may be reallocated.
176
+ */
177
+void odb_close(struct object_database *o);
178
+
179
/*
180
* Clear caches, reload alternates and then reload object sources so that new
181
* objects may become accessible.
packfile.c
-15
@@ -359,21 +359,6 @@ void close_pack(struct packed_git *p)
359
oidset_clear(&p->bad_objects);
360
}
361
362
-void close_object_store(struct object_database *o)
363
-{
364
- struct odb_source *source;
365
-
366
- packfile_store_close(o->packfiles);
367
-
368
- for (source = o->sources; source; source = source->next) {
369
- if (source->midx)
370
- close_midx(source->midx);
371
- source->midx = NULL;
372
- }
373
-
374
- close_commit_graph(o);
375
-}
376
-
362
void unlink_pack_path(const char *pack_name, int force_delete)
363
{
364
static const char *exts[] = {".idx", ".pack", ".rev", ".keep", ".bitmap", ".promisor", ".mtimes"};
packfile.h
-1
@@ -279,7 +279,6 @@ struct object_database;
279
unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
280
void close_pack_windows(struct packed_git *);
281
void close_pack(struct packed_git *);
282
-void close_object_store(struct object_database *o);
282
void unuse_pack(struct pack_window **);
283
void clear_delta_base_cache(void);
284
struct packed_git *add_packed_git(struct repository *r, const char *path,
run-command.c
+1
-1
@@ -743,7 +743,7 @@ fail_pipe:
743
fflush(NULL);
744
745
if (cmd->close_object_store)
746
- close_object_store(the_repository->objects);
746
+ odb_close(the_repository->objects);
747
748
#ifndef GIT_WINDOWS_NATIVE
749
{
scalar.c
+1
-1
@@ -931,7 +931,7 @@ static int cmd_delete(int argc, const char **argv)
931
if (dir_inside_of(cwd, enlistment.buf) >= 0)
932
res = error(_("refusing to delete current working directory"));
933
else {
934
- close_object_store(the_repository->objects);
934
+ odb_close(the_repository->objects);
935
res = delete_enlistment(&enlistment);
936
}
937
strbuf_release(&enlistment);