From: Daniel Barkalow Date: Wed, 31 Aug 2005 03:49:10 GMT Subject: [PATCH 1/2] Object model additions for read-tree Message-ID: In-Reply-To: Adds object_list_append() and a function to get the struct tree from an ent. Signed-off-by: Daniel Barkalow --- object.c | 11 +++++++++++ object.h | 3 +++ tree.c | 19 +++++++++++++++++++ tree.h | 3 +++ 4 files changed, 36 insertions(+), 0 deletions(-) 49d33c385aa69d17c991300f73e77c6718a2b4a6 diff --git a/object.c b/object.c --- a/object.c +++ b/object.c @@ -184,6 +184,17 @@ struct object_list *object_list_insert(s return new_list; } +void object_list_append(struct object *item, + struct object_list **list_p) +{ + while (*list_p) { + list_p = &((*list_p)->next); + } + *list_p = xmalloc(sizeof(struct object_list)); + (*list_p)->next = NULL; + (*list_p)->item = item; +} + unsigned object_list_length(struct object_list *list) { unsigned ret = 0; diff --git a/object.h b/object.h --- a/object.h +++ b/object.h @@ -41,6 +41,9 @@ void mark_reachable(struct object *obj, struct object_list *object_list_insert(struct object *item, struct object_list **list_p); +void object_list_append(struct object *item, + struct object_list **list_p); + unsigned object_list_length(struct object_list *list); int object_list_contains(struct object_list *list, struct object *obj); diff --git a/tree.c b/tree.c --- a/tree.c +++ b/tree.c @@ -1,5 +1,7 @@ #include "tree.h" #include "blob.h" +#include "commit.h" +#include "tag.h" #include "cache.h" #include @@ -212,3 +214,20 @@ int parse_tree(struct tree *item) free(buffer); return ret; } + +struct tree *parse_tree_indirect(const unsigned char *sha1) +{ + struct object *obj = parse_object(sha1); + do { + if (!obj) + return NULL; + if (obj->type == tree_type) + return (struct tree *) obj; + else if (obj->type == commit_type) + return ((struct commit *) obj)->tree; + else if (obj->type == tag_type) + obj = ((struct tag *) obj)->tagged; + else + return NULL; + } while (1); +} diff --git a/tree.h b/tree.h --- a/tree.h +++ b/tree.h @@ -32,4 +32,7 @@ int parse_tree_buffer(struct tree *item, int parse_tree(struct tree *tree); +/* Parses and returns the tree in the given ent, chasing tags and commits. */ +struct tree *parse_tree_indirect(const unsigned char *sha1); + #endif /* TREE_H */