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>maint
parent
8a54ebd5ed
commit
a36d513eca
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
67
object.c
67
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++) {
|
||||
|
|
Loading…
Reference in New Issue