Skip to content

Commit 9aaba57

Browse files
pks-tgitster
authored andcommitted
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>
1 parent 7c188a9 commit 9aaba57

10 files changed

Lines changed: 30 additions & 23 deletions

File tree

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ int cmd_clone(int argc,
16171617
transport_disconnect(transport);
16181618

16191619
if (option_dissociate) {
1620-
close_object_store(the_repository->objects);
1620+
odb_close(the_repository->objects);
16211621
dissociate_from_references();
16221622
}
16231623

builtin/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ int cmd_gc(int argc,
10481048
report_garbage = report_pack_garbage;
10491049
odb_reprepare(the_repository->objects);
10501050
if (pack_garbage.nr > 0) {
1051-
close_object_store(the_repository->objects);
1051+
odb_close(the_repository->objects);
10521052
clean_pack_garbage();
10531053
}
10541054

builtin/repack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ int cmd_repack(int argc,
488488

489489
string_list_sort(&names);
490490

491-
close_object_store(repo->objects);
491+
odb_close(repo->objects);
492492

493493
/*
494494
* Ok we have prepared all new packfiles.

midx-write.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ static int write_midx_internal(struct odb_source *source,
14591459
}
14601460

14611461
if (ctx.m || ctx.base_midx)
1462-
close_object_store(ctx.repo->objects);
1462+
odb_close(ctx.repo->objects);
14631463

14641464
if (commit_lock_file(&lk) < 0)
14651465
die_errno(_("could not write multi-pack-index"));

odb.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "khash.h"
1010
#include "lockfile.h"
1111
#include "loose.h"
12+
#include "midx.h"
1213
#include "object-file-convert.h"
1314
#include "object-file.h"
1415
#include "odb.h"
@@ -1044,6 +1045,21 @@ struct object_database *odb_new(struct repository *repo)
10441045
return o;
10451046
}
10461047

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+
10471063
static void odb_free_sources(struct object_database *o)
10481064
{
10491065
while (o->sources) {
@@ -1076,7 +1092,7 @@ void odb_clear(struct object_database *o)
10761092
free((char *) o->cached_objects[i].value.buf);
10771093
FREE_AND_NULL(o->cached_objects);
10781094

1079-
close_object_store(o);
1095+
odb_close(o);
10801096
packfile_store_free(o->packfiles);
10811097
o->packfiles = NULL;
10821098

odb.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ struct object_database {
169169
struct object_database *odb_new(struct repository *repo);
170170
void odb_clear(struct object_database *o);
171171

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+
172179
/*
173180
* Clear caches, reload alternates and then reload object sources so that new
174181
* objects may become accessible.

packfile.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -359,21 +359,6 @@ void close_pack(struct packed_git *p)
359359
oidset_clear(&p->bad_objects);
360360
}
361361

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-
377362
void unlink_pack_path(const char *pack_name, int force_delete)
378363
{
379364
static const char *exts[] = {".idx", ".pack", ".rev", ".keep", ".bitmap", ".promisor", ".mtimes"};

packfile.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ struct object_database;
279279
unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
280280
void close_pack_windows(struct packed_git *);
281281
void close_pack(struct packed_git *);
282-
void close_object_store(struct object_database *o);
283282
void unuse_pack(struct pack_window **);
284283
void clear_delta_base_cache(void);
285284
struct packed_git *add_packed_git(struct repository *r, const char *path,

run-command.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ int start_command(struct child_process *cmd)
743743
fflush(NULL);
744744

745745
if (cmd->close_object_store)
746-
close_object_store(the_repository->objects);
746+
odb_close(the_repository->objects);
747747

748748
#ifndef GIT_WINDOWS_NATIVE
749749
{

scalar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ static int cmd_delete(int argc, const char **argv)
931931
if (dir_inside_of(cwd, enlistment.buf) >= 0)
932932
res = error(_("refusing to delete current working directory"));
933933
else {
934-
close_object_store(the_repository->objects);
934+
odb_close(the_repository->objects);
935935
res = delete_enlistment(&enlistment);
936936
}
937937
strbuf_release(&enlistment);

0 commit comments

Comments
 (0)