git-upload-pack: More efficient usage of the has_sha1 array
[gitweb.git] / tree.c
diff --git a/tree.c b/tree.c
index dabc2e7a2c6f51255914d49f854d82e42ddcab77..315b6a5d1ce0e83fc75a399a3b74e51f46c5b392 100644 (file)
--- 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 <stdlib.h>
 
@@ -167,6 +169,7 @@ int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
                entry->directory = S_ISDIR(mode) != 0;
                entry->executable = (mode & S_IXUSR) != 0;
                entry->symlink = S_ISLNK(mode) != 0;
+               entry->zeropad = *(char *)bufptr == '0';
                entry->mode = mode;
                entry->next = NULL;
 
@@ -211,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);
+}