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

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

 



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@xxxxxxxxx>
---
 git-submodule.sh |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 51 insertions(+), 3 deletions(-)

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

--
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