From 77675e2aff434cb1f0e62540ae42f5716a5a778d Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Mon, 5 Sep 2005 02:03:51 -0400 Subject: [PATCH] Add a function for getting a struct tree for an ent. Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano diff --git a/tree.c b/tree.c index 8f490b8..315b6a5 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); +} diff --git a/tree.h b/tree.h index 0df065a..9975e88 100644 --- a/tree.h +++ b/tree.h @@ -32,4 +32,7 @@ int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size); 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 */ -- cgit v0.10.2-6-g49f6