From: Ping Yin <pkufranky@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, Ping Yin <pkufranky@gmail.com>
Subject: [PATCH RFC] git-submodule: multi-level module support
Date: Sun, 2 Mar 2008 00:23:54 +0800 [thread overview]
Message-ID: <1204388634-757-1-git-send-email-pkufranky@gmail.com> (raw)
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(-)
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
reply other threads:[~2008-03-01 16:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1204388634-757-1-git-send-email-pkufranky@gmail.com \
--to=pkufranky@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).