Commit 77675e2a authored by Daniel Barkalow's avatar Daniel Barkalow Committed by Junio C Hamano

[PATCH] Add a function for getting a struct tree for an ent.

Signed-off-by: default avatarDaniel Barkalow <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent c9d023b2
#include "tree.h"
#include "blob.h"
#include "commit.h"
#include "tag.h"
#include "cache.h"
#include <stdlib.h>
......@@ -212,3 +214,22 @@ int parse_tree(struct tree *item)
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;
return NULL;
if (!obj->parsed)
} while (1);
......@@ -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 */
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment