From d3bee161fef7820e83b44b899c531228a5546e87 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sun, 25 Jan 2009 01:52:05 +0100 Subject: tree.c: allow read_tree_recursive() to traverse gitlink entries When the callback function invoked from read_tree_recursive() returns the value `READ_TREE_RECURSIVE` for a gitlink entry, the traversal will now continue into the tree connected to the gitlinked commit. This functionality can be used to allow inter-repository operations, but since the current users of read_tree_recursive() does not yet support such operations, they have been modified where necessary to make sure that they never return READ_TREE_RECURSIVE for gitlink entries (hence no change in behaviour should be introduces by this patch alone). Signed-off-by: Lars Hjemli Signed-off-by: Junio C Hamano --- tree.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tree.c') diff --git a/tree.c b/tree.c index 03e782a9c..dfe4d5f30 100644 --- a/tree.c +++ b/tree.c @@ -131,6 +131,34 @@ int read_tree_recursive(struct tree *tree, if (retval) return -1; continue; + } else if (S_ISGITLINK(entry.mode)) { + int retval; + struct strbuf path; + unsigned int entrylen; + struct commit *commit; + + entrylen = tree_entry_len(entry.path, entry.sha1); + strbuf_init(&path, baselen + entrylen + 1); + strbuf_add(&path, base, baselen); + strbuf_add(&path, entry.path, entrylen); + strbuf_addch(&path, '/'); + + commit = lookup_commit(entry.sha1); + if (!commit) + die("Commit %s in submodule path %s not found", + sha1_to_hex(entry.sha1), path.buf); + + if (parse_commit(commit)) + die("Invalid commit %s in submodule path %s", + sha1_to_hex(entry.sha1), path.buf); + + retval = read_tree_recursive(commit->tree, + path.buf, path.len, + stage, match, fn, context); + strbuf_release(&path); + if (retval) + return -1; + continue; } } return 0; -- cgit v1.2.1