Skip to content

Commit

Permalink
[PATCH] Add a function for getting a struct tree for an ent.
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Daniel Barkalow authored and Junio C Hamano committed Sep 11, 2005
1 parent c9d023b commit 77675e2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tree.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "tree.h"
#include "blob.h"
#include "commit.h"
#include "tag.h"
#include "cache.h"
#include <stdlib.h>

Expand Down Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 77675e2

Please sign in to comment.