[PATCH] Add a function for getting a struct tree for an ent.
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Daniel Barkalow committed
Sep 5, 2005 at 02:03 UTC
77675e2aff434cb1f0e62540ae42f5716a5a778d
2 files changed
+24
tree.c
+21
@@ -1,5 +1,7 @@
1
#include "tree.h"
2
#include "blob.h"
3
+#include "commit.h"
4
+#include "tag.h"
5
#include "cache.h"
6
#include <stdlib.h>
7
@@ -212,3 +214,22 @@ int parse_tree(struct tree *item)
214
free(buffer);
215
return ret;
216
}
217
+
218
+struct tree *parse_tree_indirect(const unsigned char *sha1)
219
+{
220
+ struct object *obj = parse_object(sha1);
221
+ do {
222
+ if (!obj)
223
+ return NULL;
224
+ if (obj->type == tree_type)
225
+ return (struct tree *) obj;
226
+ else if (obj->type == commit_type)
227
+ obj = &(((struct commit *) obj)->tree->object);
228
+ else if (obj->type == tag_type)
229
+ obj = ((struct tag *) obj)->tagged;
230
+ else
231
+ return NULL;
232
+ if (!obj->parsed)
233
+ parse_object(obj->sha1);
234
+ } while (1);
235
+}
tree.h
+3
@@ -32,4 +32,7 @@ int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
32
33
int parse_tree(struct tree *tree);
34
35
+/* Parses and returns the tree in the given ent, chasing tags and commits. */
36
+struct tree *parse_tree_indirect(const unsigned char *sha1);
37
+
38
#endif /* TREE_H */