object: split out functions relating to object store subsystem
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>
Patrick Steinhardt committed
Apr 15, 2025 at 11:38 UTC
a36d513eca23303a174083f1c0573dc1a6cd2264
3 files changed
+66
-70
object-store-ll.h
-3
@@ -92,9 +92,6 @@ struct oidtree *odb_loose_cache(struct object_directory *odb,
92
/* Empty the loose object cache for the specified object directory. */
93
void odb_clear_loose_cache(struct object_directory *odb);
94
95
-/* Clear and free the specified object directory */
96
-void free_object_directory(struct object_directory *odb);
97
-
95
struct packed_git {
96
struct hashmap_entry packmap_ent;
97
struct packed_git *next;
object-store.c
+66
@@ -2,11 +2,13 @@
2
3
#include "git-compat-util.h"
4
#include "abspath.h"
5
+#include "commit-graph.h"
6
#include "config.h"
7
#include "environment.h"
8
#include "gettext.h"
9
#include "hex.h"
10
#include "lockfile.h"
11
+#include "loose.h"
12
#include "object-file-convert.h"
13
#include "object-file.h"
14
#include "object-store.h"
@@ -361,6 +363,14 @@ struct object_directory *set_temporary_primary_odb(const char *dir, int will_des
363
return new_odb->next;
364
}
365
366
+static void free_object_directory(struct object_directory *odb)
367
+{
368
+ free(odb->path);
369
+ odb_clear_loose_cache(odb);
370
+ loose_object_map_clear(&odb->loose_map);
371
+ free(odb);
372
+}
373
+
374
void restore_primary_odb(struct object_directory *restore_odb, const char *old_path)
375
{
376
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)
980
die(_("%s is not a valid '%s' object"), oid_to_hex(oid),
981
type_name(expect));
982
}
983
+
984
+struct raw_object_store *raw_object_store_new(void)
985
+{
986
+ struct raw_object_store *o = xmalloc(sizeof(*o));
987
+
988
+ memset(o, 0, sizeof(*o));
989
+ INIT_LIST_HEAD(&o->packed_git_mru);
990
+ hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
991
+ pthread_mutex_init(&o->replace_mutex, NULL);
992
+ return o;
993
+}
994
+
995
+static void free_object_directories(struct raw_object_store *o)
996
+{
997
+ while (o->odb) {
998
+ struct object_directory *next;
999
+
1000
+ next = o->odb->next;
1001
+ free_object_directory(o->odb);
1002
+ o->odb = next;
1003
+ }
1004
+ kh_destroy_odb_path_map(o->odb_by_path);
1005
+ o->odb_by_path = NULL;
1006
+}
1007
+
1008
+void raw_object_store_clear(struct raw_object_store *o)
1009
+{
1010
+ FREE_AND_NULL(o->alternate_db);
1011
+
1012
+ oidmap_free(o->replace_map, 1);
1013
+ FREE_AND_NULL(o->replace_map);
1014
+ pthread_mutex_destroy(&o->replace_mutex);
1015
+
1016
+ free_commit_graph(o->commit_graph);
1017
+ o->commit_graph = NULL;
1018
+ o->commit_graph_attempted = 0;
1019
+
1020
+ free_object_directories(o);
1021
+ o->odb_tail = NULL;
1022
+ o->loaded_alternates = 0;
1023
+
1024
+ INIT_LIST_HEAD(&o->packed_git_mru);
1025
+ close_object_store(o);
1026
+
1027
+ /*
1028
+ * `close_object_store()` only closes the packfiles, but doesn't free
1029
+ * them. We thus have to do this manually.
1030
+ */
1031
+ for (struct packed_git *p = o->packed_git, *next; p; p = next) {
1032
+ next = p->next;
1033
+ free(p);
1034
+ }
1035
+ o->packed_git = NULL;
1036
+
1037
+ hashmap_clear(&o->pack_map);
1038
+}
object.c
-67
@@ -6,16 +6,13 @@
6
#include "object.h"
7
#include "replace-object.h"
8
#include "object-file.h"
9
-#include "object-store.h"
9
#include "blob.h"
10
#include "statinfo.h"
11
#include "tree.h"
12
#include "commit.h"
13
#include "tag.h"
14
#include "alloc.h"
16
-#include "packfile.h"
15
#include "commit-graph.h"
18
-#include "loose.h"
16
17
unsigned int get_max_object_index(const struct repository *repo)
18
{
@@ -567,70 +564,6 @@ struct parsed_object_pool *parsed_object_pool_new(struct repository *repo)
564
return o;
565
}
566
570
-struct raw_object_store *raw_object_store_new(void)
571
-{
572
- struct raw_object_store *o = xmalloc(sizeof(*o));
573
-
574
- memset(o, 0, sizeof(*o));
575
- INIT_LIST_HEAD(&o->packed_git_mru);
576
- hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
577
- pthread_mutex_init(&o->replace_mutex, NULL);
578
- return o;
579
-}
580
-
581
-void free_object_directory(struct object_directory *odb)
582
-{
583
- free(odb->path);
584
- odb_clear_loose_cache(odb);
585
- loose_object_map_clear(&odb->loose_map);
586
- free(odb);
587
-}
588
-
589
-static void free_object_directories(struct raw_object_store *o)
590
-{
591
- while (o->odb) {
592
- struct object_directory *next;
593
-
594
- next = o->odb->next;
595
- free_object_directory(o->odb);
596
- o->odb = next;
597
- }
598
- kh_destroy_odb_path_map(o->odb_by_path);
599
- o->odb_by_path = NULL;
600
-}
601
-
602
-void raw_object_store_clear(struct raw_object_store *o)
603
-{
604
- FREE_AND_NULL(o->alternate_db);
605
-
606
- oidmap_free(o->replace_map, 1);
607
- FREE_AND_NULL(o->replace_map);
608
- pthread_mutex_destroy(&o->replace_mutex);
609
-
610
- free_commit_graph(o->commit_graph);
611
- o->commit_graph = NULL;
612
- o->commit_graph_attempted = 0;
613
-
614
- free_object_directories(o);
615
- o->odb_tail = NULL;
616
- o->loaded_alternates = 0;
617
-
618
- INIT_LIST_HEAD(&o->packed_git_mru);
619
- close_object_store(o);
620
-
621
- /*
622
- * `close_object_store()` only closes the packfiles, but doesn't free
623
- * them. We thus have to do this manually.
624
- */
625
- for (struct packed_git *p = o->packed_git, *next; p; p = next) {
626
- next = p->next;
627
- free(p);
628
- }
629
- o->packed_git = NULL;
630
-
631
- hashmap_clear(&o->pack_map);
632
-}
633
-
567
void parsed_object_pool_reset_commit_grafts(struct parsed_object_pool *o)
568
{
569
for (int i = 0; i < o->grafts_nr; i++) {