aboutsummaryrefslogtreecommitdiffstats
path: root/object-store.c
diff options
context:
space:
mode:
Diffstat (limited to 'object-store.c')
-rw-r--r--object-store.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/object-store.c b/object-store.c
index a2004dca15..896d9ac350 100644
--- a/object-store.c
+++ b/object-store.c
@@ -2,11 +2,13 @@
#include "git-compat-util.h"
#include "abspath.h"
+#include "commit-graph.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
#include "lockfile.h"
+#include "loose.h"
#include "object-file-convert.h"
#include "object-file.h"
#include "object-store.h"
@@ -361,6 +363,14 @@ struct object_directory *set_temporary_primary_odb(const char *dir, int will_des
return new_odb->next;
}
+static void free_object_directory(struct object_directory *odb)
+{
+ free(odb->path);
+ odb_clear_loose_cache(odb);
+ loose_object_map_clear(&odb->loose_map);
+ free(odb);
+}
+
void restore_primary_odb(struct object_directory *restore_odb, const char *old_path)
{
struct object_directory *cur_odb = the_repository->objects->odb;
@@ -970,3 +980,59 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect)
die(_("%s is not a valid '%s' object"), oid_to_hex(oid),
type_name(expect));
}
+
+struct raw_object_store *raw_object_store_new(void)
+{
+ struct raw_object_store *o = xmalloc(sizeof(*o));
+
+ memset(o, 0, sizeof(*o));
+ INIT_LIST_HEAD(&o->packed_git_mru);
+ hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
+ pthread_mutex_init(&o->replace_mutex, NULL);
+ return o;
+}
+
+static void free_object_directories(struct raw_object_store *o)
+{
+ while (o->odb) {
+ struct object_directory *next;
+
+ next = o->odb->next;
+ free_object_directory(o->odb);
+ o->odb = next;
+ }
+ kh_destroy_odb_path_map(o->odb_by_path);
+ o->odb_by_path = NULL;
+}
+
+void raw_object_store_clear(struct raw_object_store *o)
+{
+ FREE_AND_NULL(o->alternate_db);
+
+ oidmap_free(o->replace_map, 1);
+ FREE_AND_NULL(o->replace_map);
+ pthread_mutex_destroy(&o->replace_mutex);
+
+ free_commit_graph(o->commit_graph);
+ o->commit_graph = NULL;
+ o->commit_graph_attempted = 0;
+
+ free_object_directories(o);
+ o->odb_tail = NULL;
+ o->loaded_alternates = 0;
+
+ INIT_LIST_HEAD(&o->packed_git_mru);
+ close_object_store(o);
+
+ /*
+ * `close_object_store()` only closes the packfiles, but doesn't free
+ * them. We thus have to do this manually.
+ */
+ for (struct packed_git *p = o->packed_git, *next; p; p = next) {
+ next = p->next;
+ free(p);
+ }
+ o->packed_git = NULL;
+
+ hashmap_clear(&o->pack_map);
+}