X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=tree.c;h=315b6a5d1ce0e83fc75a399a3b74e51f46c5b392;hb=9e48b389990c0201487e58f3bac32734a59a7e89;hp=8f490b8984bf95a13720ffb2d9b23a2dd8c03394;hpb=b30245c8e92ecaf8fb877189d7620a5a9a205120;p=git.git diff --git a/tree.c b/tree.c index 8f490b89..315b6a5d 100644 --- 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,22 @@ 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) + obj = &(((struct commit *) obj)->tree->object); + else if (obj->type == tag_type) + obj = ((struct tag *) obj)->tagged; + else + return NULL; + if (!obj->parsed) + parse_object(obj->sha1); + } while (1); +}