summaryrefslogtreecommitdiff
path: root/commit-graph.c
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2018-07-11 22:42:41 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-07-17 22:47:48 (GMT)
commit8527750626f8a1b0fe641a5163760be054cc1d64 (patch)
tree38cc0bee20fbe5e7da17212ae9594211a9ba00dd /commit-graph.c
parentc3756d5b7fc6e163032296aa6c10fad2589273dc (diff)
downloadgit-8527750626f8a1b0fe641a5163760be054cc1d64.zip
git-8527750626f8a1b0fe641a5163760be054cc1d64.tar.gz
git-8527750626f8a1b0fe641a5163760be054cc1d64.tar.bz2
commit-graph: store graph in struct object_store
Instead of storing commit graphs in static variables, store them in struct object_store. There are no changes to the signatures of existing functions - they all still only support the_repository, and support for other instances of struct repository will be added in a subsequent commit. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit-graph.c')
-rw-r--r--commit-graph.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/commit-graph.c b/commit-graph.c
index 143a587..b6a76a1 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -183,24 +183,20 @@ cleanup_fail:
exit(1);
}
-/* global storage */
-static struct commit_graph *commit_graph = NULL;
-
static void prepare_commit_graph_one(const char *obj_dir)
{
char *graph_name;
- if (commit_graph)
+ if (the_repository->objects->commit_graph)
return;
graph_name = get_commit_graph_filename(obj_dir);
- commit_graph = load_commit_graph_one(graph_name);
+ the_repository->objects->commit_graph =
+ load_commit_graph_one(graph_name);
FREE_AND_NULL(graph_name);
}
-static int prepare_commit_graph_run_once = 0;
-
/*
* Return 1 if commit_graph is non-NULL, and 0 otherwise.
*
@@ -212,9 +208,9 @@ static int prepare_commit_graph(void)
struct alternate_object_database *alt;
char *obj_dir;
- if (prepare_commit_graph_run_once)
- return !!commit_graph;
- prepare_commit_graph_run_once = 1;
+ if (the_repository->objects->commit_graph_attempted)
+ return !!the_repository->objects->commit_graph;
+ the_repository->objects->commit_graph_attempted = 1;
if (!core_commit_graph)
return 0;
@@ -223,16 +219,16 @@ static int prepare_commit_graph(void)
prepare_commit_graph_one(obj_dir);
prepare_alt_odb(the_repository);
for (alt = the_repository->objects->alt_odb_list;
- !commit_graph && alt;
+ !the_repository->objects->commit_graph && alt;
alt = alt->next)
prepare_commit_graph_one(alt->path);
- return !!commit_graph;
+ return !!the_repository->objects->commit_graph;
}
static void close_commit_graph(void)
{
- free_commit_graph(commit_graph);
- commit_graph = NULL;
+ free_commit_graph(the_repository->objects->commit_graph);
+ the_repository->objects->commit_graph = NULL;
}
static int bsearch_graph(struct commit_graph *g, struct object_id *oid, uint32_t *pos)
@@ -342,7 +338,7 @@ int parse_commit_in_graph(struct commit *item)
{
if (!prepare_commit_graph())
return 0;
- return parse_commit_in_graph_one(commit_graph, item);
+ return parse_commit_in_graph_one(the_repository->objects->commit_graph, item);
}
void load_commit_graph_info(struct commit *item)
@@ -350,8 +346,8 @@ void load_commit_graph_info(struct commit *item)
uint32_t pos;
if (!prepare_commit_graph())
return;
- if (find_commit_in_graph(item, commit_graph, &pos))
- fill_commit_graph_info(item, commit_graph, pos);
+ if (find_commit_in_graph(item, the_repository->objects->commit_graph, &pos))
+ fill_commit_graph_info(item, the_repository->objects->commit_graph, pos);
}
static struct tree *load_tree_for_commit(struct commit_graph *g, struct commit *c)
@@ -379,7 +375,7 @@ static struct tree *get_commit_tree_in_graph_one(struct commit_graph *g,
struct tree *get_commit_tree_in_graph(const struct commit *c)
{
- return get_commit_tree_in_graph_one(commit_graph, c);
+ return get_commit_tree_in_graph_one(the_repository->objects->commit_graph, c);
}
static void write_graph_chunk_fanout(struct hashfile *f,
@@ -696,15 +692,17 @@ void write_commit_graph(const char *obj_dir,
if (append) {
prepare_commit_graph_one(obj_dir);
- if (commit_graph)
- oids.alloc += commit_graph->num_commits;
+ if (the_repository->objects->commit_graph)
+ oids.alloc += the_repository->objects->commit_graph->num_commits;
}
if (oids.alloc < 1024)
oids.alloc = 1024;
ALLOC_ARRAY(oids.list, oids.alloc);
- if (append && commit_graph) {
+ if (append && the_repository->objects->commit_graph) {
+ struct commit_graph *commit_graph =
+ the_repository->objects->commit_graph;
for (i = 0; i < commit_graph->num_commits; i++) {
const unsigned char *hash = commit_graph->chunk_oid_lookup +
commit_graph->hash_len * i;