Skip to content

Commit a36d513

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8a54ebd commit a36d513

File tree

3 files changed

+66
-70
lines changed

3 files changed

+66
-70
lines changed

object-store-ll.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ struct oidtree *odb_loose_cache(struct object_directory *odb,
9292
/* Empty the loose object cache for the specified object directory. */
9393
void odb_clear_loose_cache(struct object_directory *odb);
9494

95-
/* Clear and free the specified object directory */
96-
void free_object_directory(struct object_directory *odb);
97-
9895
struct packed_git {
9996
struct hashmap_entry packmap_ent;
10097
struct packed_git *next;

object-store.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
#include "git-compat-util.h"
44
#include "abspath.h"
5+
#include "commit-graph.h"
56
#include "config.h"
67
#include "environment.h"
78
#include "gettext.h"
89
#include "hex.h"
910
#include "lockfile.h"
11+
#include "loose.h"
1012
#include "object-file-convert.h"
1113
#include "object-file.h"
1214
#include "object-store.h"
@@ -361,6 +363,14 @@ struct object_directory *set_temporary_primary_odb(const char *dir, int will_des
361363
return new_odb->next;
362364
}
363365

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+
364374
void restore_primary_odb(struct object_directory *restore_odb, const char *old_path)
365375
{
366376
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)
970980
die(_("%s is not a valid '%s' object"), oid_to_hex(oid),
971981
type_name(expect));
972982
}
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

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@
66
#include "object.h"
77
#include "replace-object.h"
88
#include "object-file.h"
9-
#include "object-store.h"
109
#include "blob.h"
1110
#include "statinfo.h"
1211
#include "tree.h"
1312
#include "commit.h"
1413
#include "tag.h"
1514
#include "alloc.h"
16-
#include "packfile.h"
1715
#include "commit-graph.h"
18-
#include "loose.h"
1916

2017
unsigned int get_max_object_index(const struct repository *repo)
2118
{
@@ -567,70 +564,6 @@ struct parsed_object_pool *parsed_object_pool_new(struct repository *repo)
567564
return o;
568565
}
569566

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-
634567
void parsed_object_pool_reset_commit_grafts(struct parsed_object_pool *o)
635568
{
636569
for (int i = 0; i < o->grafts_nr; i++) {

0 commit comments

Comments
 (0)