update-index: be specific what part of the index has changed
[gitweb.git] / cache-tree.c
index 2130f32e260c85f506d14ed9c22e6db978a17653..52f8692efa2367c369d48ae1b61516be26981813 100644 (file)
@@ -75,11 +75,7 @@ static struct cache_tree_sub *find_subtree(struct cache_tree *it,
                return NULL;
 
        pos = -pos-1;
-       if (it->subtree_alloc <= it->subtree_nr) {
-               it->subtree_alloc = alloc_nr(it->subtree_alloc);
-               it->down = xrealloc(it->down, it->subtree_alloc *
-                                   sizeof(*it->down));
-       }
+       ALLOC_GROW(it->down, it->subtree_nr + 1, it->subtree_alloc);
        it->subtree_nr++;
 
        down = xmalloc(sizeof(*down) + pathlen + 1);
@@ -554,19 +550,18 @@ static struct cache_tree *cache_tree_find(struct cache_tree *it, const char *pat
                struct cache_tree_sub *sub;
 
                slash = strchrnul(path, '/');
-               /* between path and slash is the name of the
-                * subtree to look for.
+               /*
+                * Between path and slash is the name of the subtree
+                * to look for.
                 */
                sub = find_subtree(it, path, slash - path, 0);
                if (!sub)
                        return NULL;
                it = sub->cache_tree;
-               if (*slash)
-                       while (*slash && *slash == '/')
-                               slash++;
-               if (!*slash)
-                       return it; /* prefix ended with slashes */
+
                path = slash;
+               while (*path == '/')
+                       path++;
        }
        return it;
 }
@@ -600,8 +595,7 @@ int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
                                      active_nr, flags) < 0)
                        return WRITE_TREE_UNMERGED_INDEX;
                if (0 <= newfd) {
-                       if (!write_cache(newfd, active_cache, active_nr) &&
-                           !commit_lock_file(lock_file))
+                       if (!write_locked_index(&the_index, lock_file, COMMIT_LOCK))
                                newfd = -1;
                }
                /* Not being able to write is fine -- we are only interested