git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 5/6] commit-graph: store graph in struct object_store

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Jul 11, 2018, 22:42 UTC
Message-ID
<a045aef6d3a8600759c8186b41fa9c4960d65176.1531348540.git.jonathantanmy@google.com>
In-Reply-To
<cover.1531348540.git.jonathantanmy@google.com>

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>
---
 commit-graph.c | 40 +++++++++++++++++++---------------------
 object-store.h |  3 +++
 object.c       |  5 +++++
 3 files changed, 27 insertions(+), 21 deletions(-)
diff --git a/commit-graph.c b/commit-graph.c
index 143a587581..b6a76a1413 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -183,24 +183,20 @@ struct commit_graph *load_commit_graph_one(const char *graph_file)
 	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;
diff --git a/object-store.h b/object-store.h
index 0e13543bab..e481f7ad41 100644
--- a/object-store.h
+++ b/object-store.h
@@ -106,6 +106,9 @@ struct raw_object_store {
 	 */
 	struct oidmap *replace_map;
 
+	struct commit_graph *commit_graph;
+	unsigned commit_graph_attempted : 1; /* if loading has been attempted */
+
 	/*
 	 * private data
 	 *
diff --git a/object.c b/object.c
index b0faab85d4..e2c112cc1a 100644
--- a/object.c
+++ b/object.c
@@ -9,6 +9,7 @@
 #include "alloc.h"
 #include "object-store.h"
 #include "packfile.h"
+#include "commit-graph.h"
 
 unsigned int get_max_object_index(void)
 {
@@ -507,6 +508,10 @@ void raw_object_store_clear(struct raw_object_store *o)
 	oidmap_free(o->replace_map, 1);
 	FREE_AND_NULL(o->replace_map);
 
+	free_commit_graph(o->commit_graph);
+	o->commit_graph = NULL;
+	o->commit_graph_attempted = 0;
+
 	free_alt_odbs(o);
 	o->alt_odb_tail = NULL;
 
-- 
2.18.0.203.gfac676dfb9-goog
Previous: Jonathan TanNext: Jonathan Tan
Message 43 of 49 in “Object store refactoring: commit graph”
  1. 0/5 Object store refactoring: commit graphJonathan Tan, Jun 21, 2018
  2. 1/5 object-store: add missing includeJonathan Tan, Jun 21, 2018
  3. 2/5 commit-graph: add missing forward declarationJonathan Tan, Jun 21, 2018
  4. Stefan BellerJun 21, 2018
  5. Jonathan TanJun 21, 2018
  6. Derrick StoleeJun 22, 2018
  7. 3/5 commit-graph: add free_commit_graphJonathan Tan, Jun 21, 2018
  8. 4/5 commit-graph: store graph in struct object_storeJonathan Tan, Jun 21, 2018
  9. Junio C HamanoJun 25, 2018
  10. Jonathan TanJun 25, 2018
  11. Junio C HamanoJun 26, 2018
  12. 5/5 commit-graph: add repo arg to graph readersJonathan Tan, Jun 21, 2018
  13. Stefan BellerJun 21, 2018
  14. Jonathan TanJun 21, 2018
  15. Derrick StoleeJun 22, 2018
  16. Derrick StoleeJun 22, 2018
  17. Jonathan TanJun 22, 2018
  18. 0/6 Object store refactoring: commit graphJonathan Tan, Jul 9, 2018
  19. 1/6 commit-graph: refactor preparing commit graphJonathan Tan, Jul 9, 2018
  20. Stefan BellerJul 9, 2018
  21. Derrick StoleeJul 10, 2018
  22. 2/6 object-store: add missing includeJonathan Tan, Jul 9, 2018
  23. 3/6 commit-graph: add missing forward declarationJonathan Tan, Jul 9, 2018
  24. 4/6 commit-graph: add free_commit_graphJonathan Tan, Jul 9, 2018
  25. 5/6 commit-graph: store graph in struct object_storeJonathan Tan, Jul 9, 2018
  26. 6/6 commit-graph: add repo arg to graph readersJonathan Tan, Jul 9, 2018
  27. Derrick StoleeJul 10, 2018
  28. Jonathan TanJul 10, 2018
  29. Derrick StoleeJul 11, 2018
  30. Jonathan TanJul 11, 2018
  31. SZEDER GáborJul 10, 2018
  32. Johannes SchindelinJul 10, 2018
  33. Jonathan TanJul 10, 2018
  34. Stefan BellerJul 9, 2018
  35. Junio C HamanoJul 9, 2018
  36. Derrick StoleeJul 10, 2018
  37. Derrick StoleeJul 10, 2018
  38. 0/6 Object store refactoring: commit graphJonathan Tan, Jul 11, 2018
  39. 1/6 commit-graph: refactor preparing commit graphJonathan Tan, Jul 11, 2018
  40. 2/6 object-store: add missing includeJonathan Tan, Jul 11, 2018
  41. 3/6 commit-graph: add missing forward declarationJonathan Tan, Jul 11, 2018
  42. 4/6 commit-graph: add free_commit_graphJonathan Tan, Jul 11, 2018
  43. 5/6 commit-graph: store graph in struct object_storeJonathan Tan, Jul 11, 2018
  44. 6/6 commit-graph: add repo arg to graph readersJonathan Tan, Jul 11, 2018
  45. t5318: avoid unnecessary command substitutionsSZEDER Gábor, Aug 13, 2018
  46. Derrick StoleeAug 13, 2018
  47. Junio C HamanoAug 13, 2018
  48. Junio C HamanoJul 12, 2018
  49. Derrick StoleeJul 12, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.