threads / rfc / 12410

RFC patchgit-submodule: multi-level module support

Subject: [PATCH RFC] git-submodule: multi-level module support

## tl;dr

One message between Mar 1, 2008 and Mar 1, 2008. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Ping Yin· Mar 1, 2008, 16:23 UTC · lore

This patch allows multi-level modules in .gitmodules as linus and Sven Verdoolaege etc. have suggested in mails "Let .git/config specify the url for submodules" (http://article.gmane.org/gmane.comp.version-control.git/48939).

Example multi-level .gitmodules
-----------------------------------------------
[submodule 'a']
	url = aurl
[submodule 'b']
	url = aurl
[submodule 'c']
	url = aurl
[submodule "all"]
	submodule = all1
	submodule = all2
[submodule "all1"]
	submodule = a
	submodule = b
[submodule "all2"]
	submodule = c
-----------------------------------------------

An option '-m|--module-name' is introduced to designate submodule by logical module names instead of module paths. So follwoing commands pairs (1,2), (3,4) will be equivalent.

-------------------------------------- $ git submodule a b c (1) $ git submodule -m all (2) $ git submodule init a b (3) $ git submodule -m init all1 (4) --------------------------------------

Signed-off-by: Ping Yin <pkufranky@gmail.com>
---
 git-submodule.sh |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 51 insertions(+), 3 deletions(-)
Show changes to git-submodule.sh +51 −3
diff --git a/git-submodule.sh b/git-submodule.sh
index a6aaf40..4359e53 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -13,6 +13,7 @@ command=
 branch=
 quiet=
 cached=
+use_module_name=
 
 #
 # print stuff on stdout unless -q was specified
@@ -81,6 +82,44 @@ module_name()
 }
 
 #
+# Map submodule names to path(s)
+# $@ = module names
+#
+module_name2path() {
+	while test $# != 0
+	do
+		local name=$1
+		shift
+		local paths=$( GIT_CONFIG=.gitmodules \
+			git config --get-all submodule.$name.submodule |
+			while read name
+			do
+				module_name2path $name
+			done
+			git config --get-all submodule.$name.path
+		)
+		if test -z "$paths"
+		then
+			git config --get-all submodule.$name.url >/dev/null &&
+			echo $name
+		else
+			echo "$paths"
+		fi
+	done
+}
+
+module_path() {
+	if test -n "$use_module_name"
+	then
+		paths=$(module_name2path "$@")
+		test -z "$paths" && die "no path for modules: $@"
+	else
+		paths=$@
+	fi
+	echo $paths
+}
+
+#
 # Clone a submodule
 #
 # Prior to calling, cmd_update checks that a possibly existing
@@ -220,7 +259,9 @@ cmd_init()
 		shift
 	done
 
-	git ls-files --stage -- "$@" | grep -e '^160000 ' |
+	mpaths=$(module_path "$@") || exit
+
+	git ls-files --stage -- $mpaths | grep -e '^160000 ' |
 	while read mode sha1 stage path
 	do
 		# Skip already registered paths
@@ -274,7 +315,9 @@ cmd_update()
 		shift
 	done
 
-	git ls-files --stage -- "$@" | grep -e '^160000 ' |
+	mpaths=$(module_path "$@") || exit
+
+	git ls-files --stage -- $mpaths | grep -e '^160000 ' |
 	while read mode sha1 stage path
 	do
 		name=$(module_name "$path") || exit
@@ -357,7 +400,9 @@ cmd_status()
 		shift
 	done
 
-	git ls-files --stage -- "$@" | grep -e '^160000 ' |
+	mpaths=$(module_path "$@") || exit
+
+	git ls-files --stage -- $mpaths | grep -e '^160000 ' |
 	while read mode sha1 stage path
 	do
 		name=$(module_name "$path") || exit
@@ -408,6 +453,9 @@ do
 	--cached)
 		cached=1
 		;;
+	-m|--module-name)
+		use_module_name=1
+		;;
 	--)
 		break
 		;;
-- 
1.5.4.3.347.g5314c

← back to recent threads