t7900-subtree.sh: use the $( ... ) construct for command substitution
[gitweb.git] / cache-tree.c
index d00f4ef7c2cb44392007e1f41cc2d0bc4d1e5c76..7fa524a11323621d24c352b0a1108ae953a60cf5 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);
@@ -121,11 +117,11 @@ void cache_tree_invalidate_path(struct cache_tree *it, const char *path)
 
        if (!it)
                return;
-       slash = strchr(path, '/');
+       slash = strchrnul(path, '/');
+       namelen = slash - path;
        it->entry_count = -1;
-       if (!slash) {
+       if (!*slash) {
                int pos;
-               namelen = strlen(path);
                pos = subtree_pos(it, path, namelen);
                if (0 <= pos) {
                        cache_tree_free(&it->down[pos]->cache_tree);
@@ -143,7 +139,6 @@ void cache_tree_invalidate_path(struct cache_tree *it, const char *path)
                }
                return;
        }
-       namelen = slash - path;
        down = find_subtree(it, path, namelen, 0);
        if (down)
                cache_tree_invalidate_path(down->cache_tree, slash + 1);
@@ -555,18 +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;
-               while (*slash && *slash == '/')
-                       slash++;
-               if (!*slash)
-                       return it; /* prefix ended with slashes */
+
                path = slash;
+               while (*path == '/')
+                       path++;
        }
        return it;
 }