Merge branch 'master' of git://repo.or.cz/git-gui
[gitweb.git] / tree.c
diff --git a/tree.c b/tree.c
index 46923ee61bcce99e677abcc37e233359d39cc9fc..e4a39aa3c36964c9034d2393a8b9cb483d1543da 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)
@@ -127,12 +127,8 @@ int read_tree(struct tree *tree, int stage, const char **match)
 struct tree *lookup_tree(const unsigned char *sha1)
 {
        struct object *obj = lookup_object(sha1);
-       if (!obj) {
-               struct tree *ret = alloc_tree_node();
-               created_object(sha1, &ret->object);
-               ret->object.type = OBJ_TREE;
-               return ret;
-       }
+       if (!obj)
+               return create_object(sha1, OBJ_TREE, alloc_tree_node());
        if (!obj->type)
                obj->type = OBJ_TREE;
        if (obj->type != OBJ_TREE) {
@@ -143,6 +139,14 @@ struct tree *lookup_tree(const unsigned char *sha1)
        return (struct tree *) obj;
 }
 
+/*
+ * NOTE! Tree refs to external git repositories
+ * (ie gitlinks) do not count as real references.
+ *
+ * You don't have to have those repositories
+ * available at all, much less have the objects
+ * accessible from the current repository.
+ */
 static void track_tree_refs(struct tree *item)
 {
        int n_refs = 0, i;
@@ -151,21 +155,22 @@ 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)) {
+               if (S_ISDIRLNK(entry.mode))
+                       continue;
                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;
 
+               if (S_ISDIRLNK(entry.mode))
+                       continue;
                if (S_ISDIR(entry.mode))
                        obj = &lookup_tree(entry.sha1)->object;
                else