summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2c1cbec)
raw | patch | inline | side by side (parent: 2c1cbec)
author | Linus Torvalds <torvalds@linux-foundation.org> | |
Tue, 17 Apr 2007 05:11:43 +0000 (22:11 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 17 Apr 2007 06:36:16 +0000 (23:36 -0700) |
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>
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>
alloc.c | patch | blob | history | |
blob.c | patch | blob | history | |
cache.h | patch | blob | history | |
commit.c | patch | blob | history | |
object.c | patch | blob | history | |
object.h | patch | blob | history | |
tag.c | patch | blob | history | |
tree.c | patch | blob | history |
index 53eba373dbb923e27998ccac5e655047772d41fe..216c23a6f854c614d38c743cd7687a37f304161b 100644 (file)
--- a/alloc.c
+++ b/alloc.c
#define DEFINE_ALLOCATOR(name, type) \
static unsigned int name##_allocs; \
-struct name *alloc_##name##_node(void) \
+void *alloc_##name##_node(void) \
{ \
static int nr; \
static type *block; \
index 0a9ea417b8af4b06871eae8c47168dc178e9bb29..bd7d078e1ae5fe4ce0a16fda62a2c1743237941b 100644 (file)
--- a/blob.c
+++ b/blob.c
struct blob *lookup_blob(const unsigned char *sha1)
{
struct object *obj = lookup_object(sha1);
- if (!obj) {
- struct blob *ret = alloc_blob_node();
- created_object(sha1, &ret->object);
- ret->object.type = OBJ_BLOB;
- return ret;
- }
+ if (!obj)
+ return create_object(sha1, OBJ_BLOB, alloc_blob_node());
if (!obj->type)
obj->type = OBJ_BLOB;
if (obj->type != OBJ_BLOB) {
index aa72791947cd17c9b78313771c4ba6443787ed7f..4de25cc4b2c57131d48e62ae7ef5331a25b267ec 100644 (file)
--- a/cache.h
+++ b/cache.h
void encode_85(char *buf, const unsigned char *data, int bytes);
/* alloc.c */
-struct blob;
-struct tree;
-struct commit;
-struct tag;
-extern struct blob *alloc_blob_node(void);
-extern struct tree *alloc_tree_node(void);
-extern struct commit *alloc_commit_node(void);
-extern struct tag *alloc_tag_node(void);
-extern struct object *alloc_object_node(void);
+extern void *alloc_blob_node(void);
+extern void *alloc_tree_node(void);
+extern void *alloc_commit_node(void);
+extern void *alloc_tag_node(void);
+extern void *alloc_object_node(void);
extern void alloc_report(void);
/* trace.c */
diff --git a/commit.c b/commit.c
index 952095faa70dd8f5166f106a83382e50e131897a..10466c4ae0cb1db8648b9191fece9d9dbf238cb6 100644 (file)
--- a/commit.c
+++ b/commit.c
struct commit *lookup_commit(const unsigned char *sha1)
{
struct object *obj = lookup_object(sha1);
- if (!obj) {
- struct commit *ret = alloc_commit_node();
- created_object(sha1, &ret->object);
- ret->object.type = OBJ_COMMIT;
- return ret;
- }
+ if (!obj)
+ return create_object(sha1, OBJ_COMMIT, alloc_commit_node());
if (!obj->type)
obj->type = OBJ_COMMIT;
return check_commit(obj, sha1, 0);
diff --git a/object.c b/object.c
index 153ebac66d86fb49df449edc4d92c9db4428f44a..7bd3fec55655584f9cf4aebc6a13de7b84a78af5 100644 (file)
--- a/object.c
+++ b/object.c
obj_hash_size = new_hash_size;
}
-void created_object(const unsigned char *sha1, struct object *obj)
+void *create_object(const unsigned char *sha1, int type, void *o)
{
+ struct object *obj = o;
+
obj->parsed = 0;
obj->used = 0;
- obj->type = OBJ_NONE;
+ obj->type = type;
obj->flags = 0;
hashcpy(obj->sha1, sha1);
insert_obj_hash(obj, obj_hash, obj_hash_size);
nr_objs++;
+ return obj;
}
struct object *lookup_unknown_object(const unsigned char *sha1)
{
struct object *obj = lookup_object(sha1);
- if (!obj) {
- obj = alloc_object_node();
- created_object(sha1, obj);
- obj->type = OBJ_NONE;
- }
+ if (!obj)
+ obj = create_object(sha1, OBJ_NONE, alloc_object_node());
return obj;
}
diff --git a/object.h b/object.h
index bdbbc1889c0227519de0ba02439f0e94dfcd1651..3e26a0e8b9f87526dc02841031e5544a2518c266 100644 (file)
--- a/object.h
+++ b/object.h
/** Internal only **/
struct object *lookup_object(const unsigned char *sha1);
-void created_object(const unsigned char *sha1, struct object *obj);
+extern void *create_object(const unsigned char *sha1, int type, void *obj);
/** Returns the object, having parsed it to find out what it is. **/
struct object *parse_object(const unsigned char *sha1);
index 56a49f4fe1f705ee70bc5318a504c35d1bce963e..330d287924765c95dac428f040b104930c316b81 100644 (file)
--- a/tag.c
+++ b/tag.c
struct tag *lookup_tag(const unsigned char *sha1)
{
- struct object *obj = lookup_object(sha1);
- if (!obj) {
- struct tag *ret = alloc_tag_node();
- created_object(sha1, &ret->object);
- ret->object.type = OBJ_TAG;
- return ret;
- }
+ struct object *obj = lookup_object(sha1);
+ if (!obj)
+ return create_object(sha1, OBJ_TAG, alloc_tag_node());
if (!obj->type)
obj->type = OBJ_TAG;
if (obj->type != OBJ_TAG) {
index d188c0fbaee110a17ca7a0d16dcc979091f44ded..e5bfbceb22a2fde619bfc3121fa81251c6f51765 100644 (file)
--- a/tree.c
+++ b/tree.c
struct tree *lookup_tree(const unsigned char *sha1)
{
struct object *obj = lookup_object(sha1);
- if (!obj) {
- struct tree *ret = alloc_tree_node();
- created_object(sha1, &ret->object);
- ret->object.type = OBJ_TREE;
- return ret;
- }
+ if (!obj)
+ return create_object(sha1, OBJ_TREE, alloc_tree_node());
if (!obj->type)
obj->type = OBJ_TREE;
if (obj->type != OBJ_TREE) {