git.el: Display some information about the HEAD commit.
[gitweb.git] / tree.c
diff --git a/tree.c b/tree.c
index b6f02fecc46ec4633dc1ee75f38bc90761a4fbe3..d188c0fbaee110a17ca7a0d16dcc979091f44ded 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -83,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))
@@ -101,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)
@@ -151,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;
 
@@ -190,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));