[RFC/PATCH 1/3] tree.c: add support for traversal of submodules

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If the commit referenced by a gitlink is available in the (possibly
alternate) object database, read_tree_recursive() is now able to descend
into the tree of the linked commit if the flag 'traverse_gitlinks' is
turned on.

Signed-off-by: Lars Hjemli <hjemli@xxxxxxxxx>
---
 tree.c |   20 +++++++++++++++++---
 tree.h |    1 +
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/tree.c b/tree.c
index 03e782a..1468e10 100644
--- a/tree.c
+++ b/tree.c
@@ -7,6 +7,7 @@
 #include "tree-walk.h"
 
 const char *tree_type = "tree";
+int traverse_gitlinks = 0;
 
 static int read_one_entry_opt(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage, int opt)
 {
@@ -114,16 +115,29 @@ int read_tree_recursive(struct tree *tree,
 		default:
 			return -1;
 		}
-		if (S_ISDIR(entry.mode)) {
+		if (S_ISDIR(entry.mode) || (traverse_gitlinks && S_ISGITLINK(entry.mode))) {
 			int retval;
 			char *newbase;
 			unsigned int pathlen = tree_entry_len(entry.path, entry.sha1);
-
+			struct commit *commit;
+			struct tree *node;
+
+			if (S_ISDIR(entry.mode)) {
+				node = lookup_tree(entry.sha1);
+			} else {
+				commit = lookup_commit_reference_gently(entry.sha1, 1);
+				if (!commit)
+					continue;
+				if (parse_commit(commit))
+					die("parse_commit(%s) failed",
+					    sha1_to_hex(entry.sha1));
+				node = commit->tree;
+			}
 			newbase = xmalloc(baselen + 1 + pathlen);
 			memcpy(newbase, base, baselen);
 			memcpy(newbase + baselen, entry.path, pathlen);
 			newbase[baselen + pathlen] = '/';
-			retval = read_tree_recursive(lookup_tree(entry.sha1),
+			retval = read_tree_recursive(node,
 						     newbase,
 						     baselen + pathlen + 1,
 						     stage, match, fn, context);
diff --git a/tree.h b/tree.h
index 2ff01a4..b6b938f 100644
--- a/tree.h
+++ b/tree.h
@@ -4,6 +4,7 @@
 #include "object.h"
 
 extern const char *tree_type;
+extern int traverse_gitlinks;
 
 struct tree {
 	struct object object;
-- 
1.6.1.81.g1df1.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux