[PATCH 136/194] alloc: allow arbitrary repositories for alloc functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We have to convert them all at once, because alloc_report uses funky a
macro for reporting. It is better for the sake of mechanical conversion
to convert multiple functions at once rather than changing the structure
of the reporting function.

Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx>
---
 alloc.c      | 48 ++++++++++++++++++++++++++----------------------
 cache.h      | 22 ++++++++--------------
 object.h     | 20 +++++++++++++++++++-
 repository.c |  6 ++++++
 4 files changed, 59 insertions(+), 37 deletions(-)

diff --git a/alloc.c b/alloc.c
index 277dadd221..0e11c7766a 100644
--- a/alloc.c
+++ b/alloc.c
@@ -32,6 +32,11 @@ struct alloc_state {
 	void *p;   /* first free node in current allocation */
 };
 
+void *allocate_alloc_state(void)
+{
+	return xcalloc(1, sizeof(struct alloc_state));
+}
+
 static inline void *alloc_node(struct alloc_state *s, size_t node_size)
 {
 	void *ret;
@@ -48,51 +53,49 @@ static inline void *alloc_node(struct alloc_state *s, size_t node_size)
 	return ret;
 }
 
-static struct alloc_state blob_state;
-void *alloc_blob_node_the_repository(void)
+struct alloc_state the_repository_blob_state;
+void *alloc_blob_node(struct repository *r)
 {
-	struct blob *b = alloc_node(&blob_state, sizeof(struct blob));
+	struct blob *b = alloc_node(r->parsed_objects.blob_state, sizeof(struct blob));
 	b->object.type = OBJ_BLOB;
 	return b;
 }
 
-static struct alloc_state tree_state;
-void *alloc_tree_node_the_repository(void)
+struct alloc_state the_repository_tree_state;
+void *alloc_tree_node(struct repository *r)
 {
-	struct tree *t = alloc_node(&tree_state, sizeof(struct tree));
+	struct tree *t = alloc_node(r->parsed_objects.tree_state, sizeof(struct tree));
 	t->object.type = OBJ_TREE;
 	return t;
 }
 
-static struct alloc_state tag_state;
-void *alloc_tag_node_the_repository(void)
+struct alloc_state the_repository_tag_state;
+void *alloc_tag_node(struct repository *r)
 {
-	struct tag *t = alloc_node(&tag_state, sizeof(struct tag));
+	struct tag *t = alloc_node(r->parsed_objects.tag_state, sizeof(struct tag));
 	t->object.type = OBJ_TAG;
 	return t;
 }
 
-static struct alloc_state object_state;
-void *alloc_object_node_the_repository(void)
+struct alloc_state the_repository_object_state;
+void *alloc_object_node(struct repository *r)
 {
-	struct object *obj = alloc_node(&object_state, sizeof(union any_object));
+	struct object *obj = alloc_node(r->parsed_objects.object_state, sizeof(union any_object));
 	obj->type = OBJ_NONE;
 	return obj;
 }
 
-static struct alloc_state commit_state;
-
-unsigned int alloc_commit_index_the_repository(void)
+unsigned int alloc_commit_index(struct repository *r)
 {
-	static unsigned int count;
-	return count++;
+	return r->parsed_objects.commit_count++;
 }
 
-void *alloc_commit_node_the_repository(void)
+struct alloc_state the_repository_commit_state;
+void *alloc_commit_node(struct repository *r)
 {
-	struct commit *c = alloc_node(&commit_state, sizeof(struct commit));
+	struct commit *c = alloc_node(r->parsed_objects.commit_state, sizeof(struct commit));
 	c->object.type = OBJ_COMMIT;
-	c->index = alloc_commit_index(the_repository);
+	c->index = alloc_commit_index(r);
 	return c;
 }
 
@@ -103,9 +106,10 @@ static void report(const char *name, unsigned int count, size_t size)
 }
 
 #define REPORT(name, type)	\
-    report(#name, name##_state.count, name##_state.count * sizeof(type) >> 10)
+    report(#name, r->parsed_objects.name##_state->count, \
+		  r->parsed_objects.name##_state->count * sizeof(type) >> 10)
 
-void alloc_report_the_repository(void)
+void alloc_report(struct repository *r)
 {
 	REPORT(blob, struct blob);
 	REPORT(tree, struct tree);
diff --git a/cache.h b/cache.h
index 40aa3f25aa..ee01daf130 100644
--- a/cache.h
+++ b/cache.h
@@ -1575,20 +1575,14 @@ int decode_85(char *dst, const char *line, int linelen);
 void encode_85(char *buf, const unsigned char *data, int bytes);
 
 /* alloc.c */
-#define alloc_blob_node(r) alloc_blob_node_##r()
-extern void *alloc_blob_node_the_repository(void);
-#define alloc_tree_node(r) alloc_tree_node_##r()
-extern void *alloc_tree_node_the_repository(void);
-#define alloc_commit_node(r) alloc_commit_node_##r()
-extern void *alloc_commit_node_the_repository(void);
-#define alloc_tag_node(r) alloc_tag_node_##r()
-extern void *alloc_tag_node_the_repository(void);
-#define alloc_object_node(r) alloc_object_node_##r()
-extern void *alloc_object_node_the_repository(void);
-#define alloc_report(r) alloc_report_##r()
-extern void alloc_report_the_repository(void);
-#define alloc_commit_index(r) alloc_commit_index_##r()
-extern unsigned int alloc_commit_index_the_repository(void);
+extern void *alloc_blob_node(struct repository *r);
+extern void *alloc_tree_node(struct repository *r);
+extern void *alloc_commit_node(struct repository *r);
+extern void *alloc_tag_node(struct repository *r);
+extern void *alloc_object_node(struct repository *r);
+extern void alloc_report(struct repository *r);
+extern unsigned int alloc_commit_index(struct repository *r);
+void *allocate_alloc_state(void);
 
 /* pkt-line.c */
 void packet_trace_identity(const char *prog);
diff --git a/object.h b/object.h
index a61d965700..587db55dfe 100644
--- a/object.h
+++ b/object.h
@@ -8,9 +8,27 @@ struct object_parser {
 	/* parent substitutions from .git/info/grafts and .git/shallow */
 	struct commit_graft **grafts;
 	int grafts_alloc, grafts_nr;
+
+	struct alloc_state *blob_state;
+	struct alloc_state *tree_state;
+	struct alloc_state *commit_state;
+	struct alloc_state *tag_state;
+	struct alloc_state *object_state;
+	unsigned commit_count;
 };
 
-#define OBJECT_PARSER_INIT { NULL, 0, 0, NULL, 0, 0 }
+extern struct alloc_state the_repository_blob_state;
+extern struct alloc_state the_repository_tree_state;
+extern struct alloc_state the_repository_commit_state;
+extern struct alloc_state the_repository_tag_state;
+extern struct alloc_state the_repository_object_state;
+#define OBJECT_PARSER_INIT { NULL, 0, 0, NULL, 0, 0, \
+	&the_repository_blob_state, \
+	&the_repository_tree_state, \
+	&the_repository_commit_state, \
+	&the_repository_tag_state, \
+	&the_repository_object_state, \
+	0 }
 
 struct object_list {
 	struct object *item;
diff --git a/repository.c b/repository.c
index 361e503824..f76f0ddd37 100644
--- a/repository.c
+++ b/repository.c
@@ -175,6 +175,12 @@ int repo_init(struct repository *repo, const char *gitdir, const char *worktree)
 
 	repo_set_hash_algo(repo, format.hash_algo);
 
+	repo->parsed_objects.blob_state = allocate_alloc_state();
+	repo->parsed_objects.tree_state = allocate_alloc_state();
+	repo->parsed_objects.commit_state = allocate_alloc_state();
+	repo->parsed_objects.tag_state = allocate_alloc_state();
+	repo->parsed_objects.object_state = allocate_alloc_state();
+
 	if (worktree)
 		repo_set_worktree(repo, worktree);
 
-- 
2.15.1.433.g936d1b9894.dirty




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux