]> git.ipfire.org Git - thirdparty/git.git/commitdiff
object: split out functions relating to object store subsystem
authorPatrick Steinhardt <ps@pks.im>
Tue, 15 Apr 2025 09:38:21 +0000 (11:38 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 15 Apr 2025 15:24:36 +0000 (08:24 -0700)
Split out functions relating to the object store subsystem from
"object.c". This helps us to separate concerns.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
object-store-ll.h
object-store.c
object.c

index 8ae80b8a5fad646c924c3618a57f238578718dde..8bb0f33f9a88a89c837d7a27b2f01fef8a05d4b2 100644 (file)
@@ -92,9 +92,6 @@ struct oidtree *odb_loose_cache(struct object_directory *odb,
 /* Empty the loose object cache for the specified object directory. */
 void odb_clear_loose_cache(struct object_directory *odb);
 
-/* Clear and free the specified object directory */
-void free_object_directory(struct object_directory *odb);
-
 struct packed_git {
        struct hashmap_entry packmap_ent;
        struct packed_git *next;
index a2004dca15a63525931e4045b650fd635b7aaaf0..896d9ac3509f5109f95583324ba499e2e93cb03f 100644 (file)
@@ -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);
+}
index 154525a497234c1f8fab9d984752cea79f5ac688..ccda798b75f53d01eef0bebd68e460d32c62de64 100644 (file)
--- a/object.c
+++ b/object.c
@@ -6,16 +6,13 @@
 #include "object.h"
 #include "replace-object.h"
 #include "object-file.h"
-#include "object-store.h"
 #include "blob.h"
 #include "statinfo.h"
 #include "tree.h"
 #include "commit.h"
 #include "tag.h"
 #include "alloc.h"
-#include "packfile.h"
 #include "commit-graph.h"
-#include "loose.h"
 
 unsigned int get_max_object_index(const struct repository *repo)
 {
@@ -567,70 +564,6 @@ struct parsed_object_pool *parsed_object_pool_new(struct repository *repo)
        return o;
 }
 
-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;
-}
-
-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);
-}
-
-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);
-}
-
 void parsed_object_pool_reset_commit_grafts(struct parsed_object_pool *o)
 {
        for (int i = 0; i < o->grafts_nr; i++) {