X-Git-Url: https://git.octo.it/?p=git.git;a=blobdiff_plain;f=cache-tree.c;h=d9f7e1e3dd598d34e08d6370544b562daf4640d2;hp=a880c97b38e7d36f2a45a1743e9565cc1e58280d;hb=HEAD;hpb=0a8f4f0020cb35095005852c0797f0b90e9ebb74 diff --git a/cache-tree.c b/cache-tree.c index a880c97b..d9f7e1e3 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -529,3 +529,29 @@ struct cache_tree *cache_tree_read(const char *buffer, unsigned long size) return NULL; /* not the whole tree */ return read_one(&buffer, &size); } + +struct cache_tree *cache_tree_find(struct cache_tree *it, const char *path) +{ + while (*path) { + const char *slash; + struct cache_tree_sub *sub; + + slash = strchr(path, '/'); + if (!slash) + slash = path + strlen(path); + /* 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 || !*slash) + return it; /* prefix ended with slashes */ + path = slash; + } + return it; +}