@matheusbsbs / matheus-bagliano / commits / 100c5f3b0b
Fork 0

Clean up object creation to use more common code

This replaces the fairly odd "created_object()" function that did _most_ of the object setup with a more complete "create_object()" function that also has a more natural calling convention. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Apr 16, 2007 at 22:11 UTC 100c5f3b0b27ec6617de1a785c4ff481e92636c1
8 files changed +23 -43
alloc.c
+1 -1
@@ -20,7 +20,7 @@
20
21 #define DEFINE_ALLOCATOR(name, type) \
22 static unsigned int name##_allocs; \
23 -struct name *alloc_##name##_node(void) \
23 +void *alloc_##name##_node(void) \
24 { \
25 static int nr; \
26 static type *block; \
blob.c
+2 -6
@@ -6,12 +6,8 @@ const char *blob_type = "blob";
6 struct blob *lookup_blob(const unsigned char *sha1)
7 {
8 struct object *obj = lookup_object(sha1);
9 - if (!obj) {
10 - struct blob *ret = alloc_blob_node();
11 - created_object(sha1, &ret->object);
12 - ret->object.type = OBJ_BLOB;
13 - return ret;
14 - }
9 + if (!obj)
10 + return create_object(sha1, OBJ_BLOB, alloc_blob_node());
11 if (!obj->type)
12 obj->type = OBJ_BLOB;
13 if (obj->type != OBJ_BLOB) {
cache.h
+5 -9
@@ -476,15 +476,11 @@ int decode_85(char *dst, const char *line, int linelen);
476 void encode_85(char *buf, const unsigned char *data, int bytes);
477
478 /* alloc.c */
479 -struct blob;
480 -struct tree;
481 -struct commit;
482 -struct tag;
483 -extern struct blob *alloc_blob_node(void);
484 -extern struct tree *alloc_tree_node(void);
485 -extern struct commit *alloc_commit_node(void);
486 -extern struct tag *alloc_tag_node(void);
487 -extern struct object *alloc_object_node(void);
479 +extern void *alloc_blob_node(void);
480 +extern void *alloc_tree_node(void);
481 +extern void *alloc_commit_node(void);
482 +extern void *alloc_tag_node(void);
483 +extern void *alloc_object_node(void);
484 extern void alloc_report(void);
485
486 /* trace.c */
commit.c
+2 -6
@@ -98,12 +98,8 @@ struct commit *lookup_commit_reference(const unsigned char *sha1)
98 struct commit *lookup_commit(const unsigned char *sha1)
99 {
100 struct object *obj = lookup_object(sha1);
101 - if (!obj) {
102 - struct commit *ret = alloc_commit_node();
103 - created_object(sha1, &ret->object);
104 - ret->object.type = OBJ_COMMIT;
105 - return ret;
106 - }
101 + if (!obj)
102 + return create_object(sha1, OBJ_COMMIT, alloc_commit_node());
103 if (!obj->type)
104 obj->type = OBJ_COMMIT;
105 return check_commit(obj, sha1, 0);
object.c
+7 -7
@@ -105,11 +105,13 @@ static void grow_object_hash(void)
105 obj_hash_size = new_hash_size;
106 }
107
108 -void created_object(const unsigned char *sha1, struct object *obj)
108 +void *create_object(const unsigned char *sha1, int type, void *o)
109 {
110 + struct object *obj = o;
111 +
112 obj->parsed = 0;
113 obj->used = 0;
112 - obj->type = OBJ_NONE;
114 + obj->type = type;
115 obj->flags = 0;
116 hashcpy(obj->sha1, sha1);
117
@@ -118,16 +120,14 @@ void created_object(const unsigned char *sha1, struct object *obj)
120
121 insert_obj_hash(obj, obj_hash, obj_hash_size);
122 nr_objs++;
123 + return obj;
124 }
125
126 struct object *lookup_unknown_object(const unsigned char *sha1)
127 {
128 struct object *obj = lookup_object(sha1);
126 - if (!obj) {
127 - obj = alloc_object_node();
128 - created_object(sha1, obj);
129 - obj->type = OBJ_NONE;
130 - }
129 + if (!obj)
130 + obj = create_object(sha1, OBJ_NONE, alloc_object_node());
131 return obj;
132 }
133
object.h
+1 -1
@@ -46,7 +46,7 @@ extern struct object_refs *lookup_object_refs(struct object *);
46 /** Internal only **/
47 struct object *lookup_object(const unsigned char *sha1);
48
49 -void created_object(const unsigned char *sha1, struct object *obj);
49 +extern void *create_object(const unsigned char *sha1, int type, void *obj);
50
51 /** Returns the object, having parsed it to find out what it is. **/
52 struct object *parse_object(const unsigned char *sha1);
tag.c
+3 -7
@@ -20,13 +20,9 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen)
20
21 struct tag *lookup_tag(const unsigned char *sha1)
22 {
23 - struct object *obj = lookup_object(sha1);
24 - if (!obj) {
25 - struct tag *ret = alloc_tag_node();
26 - created_object(sha1, &ret->object);
27 - ret->object.type = OBJ_TAG;
28 - return ret;
29 - }
23 + struct object *obj = lookup_object(sha1);
24 + if (!obj)
25 + return create_object(sha1, OBJ_TAG, alloc_tag_node());
26 if (!obj->type)
27 obj->type = OBJ_TAG;
28 if (obj->type != OBJ_TAG) {
tree.c
+2 -6
@@ -127,12 +127,8 @@ int read_tree(struct tree *tree, int stage, const char **match)
127 struct tree *lookup_tree(const unsigned char *sha1)
128 {
129 struct object *obj = lookup_object(sha1);
130 - if (!obj) {
131 - struct tree *ret = alloc_tree_node();
132 - created_object(sha1, &ret->object);
133 - ret->object.type = OBJ_TREE;
134 - return ret;
135 - }
130 + if (!obj)
131 + return create_object(sha1, OBJ_TREE, alloc_tree_node());
132 if (!obj->type)
133 obj->type = OBJ_TREE;
134 if (obj->type != OBJ_TREE) {