From: imyousuf@gmail.com
To: git@vger.kernel.org
Cc: gitster@pobox.com, Imran M Yousuf <imyousuf@smartitengineering.com>
Subject: [PATCH] - Added recurse command to git submodule
Date: Wed, 9 Jan 2008 11:51:46 +0600 [thread overview]
Message-ID: <1199857906-26321-1-git-send-email-imyousuf@gmail.com> (raw)
From: Imran M Yousuf <imyousuf@smartitengineering.com>
- The purpose of the recurse command in the git submodule is to recurse
a command in its submodule at depths specified. For example if one wants
to do a diff on its project with submodules at once, one can simply do
git-submodule recurse diff HEAD and would see the diff for all the modules
it contains. If during recursion it is found that a module has not been
initialized or updated than the command also initializes and updates them.
It is to be noted that argument specification to the command intended (in
above example diff) to recurse will be same as its original command (i.e.
git diff). If the original command spec changes it will have no effect on
the recurse command. Depth of recursion can be specified simply by
mentioning the -d <recursion depth> argument to recurse command. If not
specified or specified to 0, it will be comprehended to recurse at all
depth; if a positive number is specified than maximum recursion depth will
never cross that depth. In order to see some information -v option may be
used
Signed-off-by: Imran M Yousuf <imyousuf@smartitengineering.com>
---
git-submodule.sh | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 111 insertions(+), 1 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 8a29382..5cb931e 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -4,7 +4,7 @@
#
# Copyright (c) 2007 Lars Hjemli
-USAGE='[--quiet] [--cached] [add <repo> [-b branch]|status|init|update] [--] [<path>...]'
+USAGE='[[--quiet] [--cached] [add <repo> [-b branch]|status|init|update] [--] [<path>...]|[recurse [-v] [-d <recursion depth>] <command> <arguments> ...]]'
OPTIONS_SPEC=
. git-sh-setup
require_work_tree
@@ -17,6 +17,9 @@ status=
quiet=
cached=
command=
+recurse_verbose=0
+recursion_depth=0
+current_recursion_depth=0
#
# print stuff on stdout unless -q was specified
@@ -294,6 +297,82 @@ modules_list()
done
}
+# Initializes the submodule if already not initialized
+initialize_sub_module() {
+ if [ ! -d "$1"/.git ]; then
+ if [ $recurse_verbose -eq 1 ]; then
+ echo Initializing and updating "$1"
+ fi
+ git-submodule init "$1"; git-submodule update "$1"
+ fi
+}
+
+# This actually traverses the module; checks
+# whether the module is initialized or not.
+# if not initialized, then done so and then the
+# intended command is evaluated. Then it
+# recursively goes into it modules.
+traverse_module() {
+ if [ $recurse_verbose -eq 1 ]; then
+ echo Current recursion depth: "$current_recursion_depth"
+ fi
+ initialize_sub_module "$1"
+ (
+ submod_path="$1"
+ shift
+ cd "$submod_path"
+ if [ $recurse_verbose -eq 1 ]; then
+ echo Working in mod "$submod_path" @ `pwd` with "$@" \("$#"\)
+ fi
+ git "$@"
+ # Check whether submodules exists only if recursion to that depth
+ # was requested by user
+ if test "$recursion_depth" -eq 0 || test "$current_recursion_depth" -lt "$recursion_depth"
+ then
+ if [ -f .gitmodules ]; then
+ for mod_path in `sed -n -e 's/path = //p' .gitmodules`; do
+ export current_recursion_depth=$(echo "$current_recursion_depth+1" | bc)
+ traverse_module "$mod_path" "$@"
+ export current_recursion_depth=$(echo "$current_recursion_depth-1" | bc)
+ done
+ fi
+ fi
+ )
+}
+
+# Propagates or recurses over all the submodules at any
+# depth with any git command, e.g. git-clone, git-status,
+# git-commit etc., with the arguments supplied exactly as
+# it would have been supplied to the command otherwise.
+# This actually starts the recursive propagation
+modules_recurse() {
+ project_home=`pwd`
+ echo Project Home: "$project_home"
+ if [ $recurse_verbose -eq 1 ]; then
+ if [ $recursion_depth = 0 ]; then
+ echo Recursion will go to all depths
+ else
+ echo Recursion depth specified to "$recursion_depth"
+ fi
+ fi
+ if [ -d "$project_home"/.git/ ]; then
+ if [ $recurse_verbose -eq 1 ]; then
+ echo Command to recurse: git "$@"
+ fi
+ git "$@"
+ if [ -f .gitmodules ]; then
+ for mod_path in `sed -n -e 's/path = //p' .gitmodules`; do
+ export current_recursion_depth=1
+ traverse_module $mod_path "$@"
+ done
+ fi
+ else
+ echo "$project_home" not a git repo thus exiting
+ exit
+ fi
+ unset current_recursion_depth
+}
+
# command specifies the whole function name since
# one of theirs prefix is module not modules
while test $# != 0
@@ -326,6 +405,37 @@ do
--cached)
command="modules_list"
;;
+ recurse)
+ command="modules_$1"
+ repeat=1
+ while test $repeat = 1
+ do
+ case "$2" in
+ -v)
+ recurse_verbose=1
+ shift
+ ;;
+ -d)
+ if [ -z $3 ]; then
+ echo No \<recursion depth\> specified
+ usage
+ elif [ `expr "$3" : '[1-9][0-9]*.*'` -eq `expr "$3" : '.*'` ]; then
+ recursion_depth="$3"
+ shift
+ shift
+ else
+ echo \<recursion depth\> not an integer
+ usage
+ fi
+ ;;
+ *)
+ repeat=0
+ ;;
+ esac
+ done
+ shift
+ break
+ ;;
--)
break
;;
--
1.5.3.7
next reply other threads:[~2008-01-09 5:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-09 5:51 imyousuf [this message]
2008-01-09 8:38 ` [PATCH] - Added recurse command to git submodule Junio C Hamano
2008-01-09 8:55 ` Imran M Yousuf
2008-01-09 10:42 ` Lars Hjemli
2008-01-09 20:26 ` Junio C Hamano
2008-01-10 3:27 ` Imran M Yousuf
2008-01-10 4:09 ` Junio C Hamano
2008-01-10 4:50 ` Imran M Yousuf
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=1199857906-26321-1-git-send-email-imyousuf@gmail.com \
--to=imyousuf@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=imyousuf@smartitengineering.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).