From 6bd20358a9b831b3b545284188871bc844245c25 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 26 Apr 2006 01:20:50 -0700 Subject: write-tree: --prefix= The "bind" commit can express an aggregation of multiple projects into a single commit. In such an organization, there would be one project, root of whose tree object is at the same level of the root of the aggregated projects, and other projects have their toplevel in separate subdirectories. Let's call that root level project the "primary project", and call other ones just "subprojects". You would first read-tree the primary project, and then graft the subprojects under their appropriate location using read-tree --prefix=/ repeatedly. To write out a tree object from such an index for a subproject, write-tree --prefix=/ is used. Signed-off-by: Junio C Hamano --- cache-tree.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'cache-tree.c') diff --git a/cache-tree.c b/cache-tree.c index e452238ba7..dae4399c1e 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -525,3 +525,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; +} -- cgit v1.2.1