GIT 1.5.1.2
[gitweb.git] / tree.c
diff --git a/tree.c b/tree.c
index ea386e506659c65224cfe55bdc4f8d086171637a..d188c0fbaee110a17ca7a0d16dcc979091f44ded 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -4,7 +4,6 @@
 #include "commit.h"
 #include "tag.h"
 #include "tree-walk.h"
-#include <stdlib.h>
 
 const char *tree_type = "tree";
 
@@ -84,8 +83,7 @@ int read_tree_recursive(struct tree *tree,
        if (parse_tree(tree))
                return -1;
 
-       desc.buf = tree->buffer;
-       desc.size = tree->size;
+       init_tree_desc(&desc, tree->buffer, tree->size);
 
        while (tree_entry(&desc, &entry)) {
                if (!match_tree_entry(base, baselen, entry.path, entry.mode, match))
@@ -102,14 +100,15 @@ int read_tree_recursive(struct tree *tree,
                if (S_ISDIR(entry.mode)) {
                        int retval;
                        char *newbase;
+                       unsigned int pathlen = tree_entry_len(entry.path, entry.sha1);
 
-                       newbase = xmalloc(baselen + 1 + entry.pathlen);
+                       newbase = xmalloc(baselen + 1 + pathlen);
                        memcpy(newbase, base, baselen);
-                       memcpy(newbase + baselen, entry.path, entry.pathlen);
-                       newbase[baselen + entry.pathlen] = '/';
+                       memcpy(newbase + baselen, entry.path, pathlen);
+                       newbase[baselen + pathlen] = '/';
                        retval = read_tree_recursive(lookup_tree(entry.sha1),
                                                     newbase,
-                                                    baselen + entry.pathlen + 1,
+                                                    baselen + pathlen + 1,
                                                     stage, match, fn);
                        free(newbase);
                        if (retval)
@@ -152,18 +151,14 @@ static void track_tree_refs(struct tree *item)
        struct name_entry entry;
 
        /* Count how many entries there are.. */
-       desc.buf = item->buffer;
-       desc.size = item->size;
-       while (desc.size) {
+       init_tree_desc(&desc, item->buffer, item->size);
+       while (tree_entry(&desc, &entry))
                n_refs++;
-               update_tree_entry(&desc);
-       }
 
        /* Allocate object refs and walk it again.. */
        i = 0;
        refs = alloc_object_refs(n_refs);
-       desc.buf = item->buffer;
-       desc.size = item->size;
+       init_tree_desc(&desc, item->buffer, item->size);
        while (tree_entry(&desc, &entry)) {
                struct object *obj;
 
@@ -191,17 +186,17 @@ int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
 
 int parse_tree(struct tree *item)
 {
-        char type[20];
+        enum object_type type;
         void *buffer;
         unsigned long size;
 
        if (item->object.parsed)
                return 0;
-       buffer = read_sha1_file(item->object.sha1, type, &size);
+       buffer = read_sha1_file(item->object.sha1, &type, &size);
        if (!buffer)
                return error("Could not read %s",
                             sha1_to_hex(item->object.sha1));
-       if (strcmp(type, tree_type)) {
+       if (type != OBJ_TREE) {
                free(buffer);
                return error("Object %s not a tree",
                             sha1_to_hex(item->object.sha1));