diff options
author | Junio C Hamano <junkio@cox.net> | 2006-06-17 17:56:52 -0700 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-06-17 17:56:52 -0700 |
commit | 75c3a5ccdf114b5485e4828db1923bf4a35b19e2 (patch) | |
tree | e919c376fa68f0ce8b46918b499d8ed8516c048a /cache-tree.c | |
parent | 8c278abcbe35b23e9f93e99daf2144336fad1849 (diff) | |
parent | d6970e42a1763b549ccf93558de7f54a78819d7a (diff) | |
download | git-75c3a5ccdf114b5485e4828db1923bf4a35b19e2.tar.gz |
Merge branch 'jc/rw-prefix'
* jc/rw-prefix:
read-tree: reorganize bind_merge code.
write-tree: --prefix=<path>
read-tree: --prefix=<path>/ option.
Diffstat (limited to 'cache-tree.c')
-rw-r--r-- | cache-tree.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/cache-tree.c b/cache-tree.c index a880c97b38..d9f7e1e3dd 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; +} |