From: Eric Cousineau <eacousineau@gmail.com>
To: Phil Hord <phil.hord@gmail.com>
Cc: Jens Lehmann <Jens.Lehmann@web.de>,
Junio C Hamano <gitster@pobox.com>,
Heiko Voigt <hvoigt@hvoigt.net>,
"git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: [PATCH/RFC] Changing submodule foreach --recursive to be depth-first, --parent option to execute command in supermodule as well
Date: Thu, 14 Mar 2013 01:30:55 -0500 [thread overview]
Message-ID: <51416E9F.7000604@gmail.com> (raw)
In-Reply-To: <CABURp0qBA6myf7_SuaxJSrePJHmh2v-nmtLRzKTtgAJxLkJ-tQ@mail.gmail.com>
From 59fb432e17a1aae9de26bbaaca7f09cc7f03b471 Mon Sep 17 00:00:00 2001
From: Eric Cousineau <eacousineau@gmail.com>
Date: Thu, 14 Mar 2013 01:19:53 -0500
Subject: [PATCH] submodule-foreach: Added in --post-order=<command> per Jens
Lehmann's suggestion
Signed-off-by: Eric Cousineau <eacousineau@gmail.com>
---
Made the scope of the patch only relate to --post-order.
Would we want to rename this to just --post=<command> ?
Anywho, here it is running in a test setup, where the structure is:
a
- b
- - d
- c
$ git submodule foreach --recursive --post-order 'echo Post $name' 'echo
Pre $path'
Entering 'b'
Pre b
Entering 'b/d'
Pre d
Entering 'b/d'
Post d
Entering 'b'
Post b
Entering 'c'
Pre c
Entering 'c'
Post c
An interesting note is that it fails with 'git submodule foreach
--post-order', but not 'git submodule foreach --post-order=', since it
simply interprets that as an empty command.
If that is important, I could add in a check for $# when parsing the
argument for --post-order=*.
git-submodule.sh | 39 ++++++++++++++++++++++++++++++++++-----
1 file changed, 34 insertions(+), 5 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 004c034..9b70bc2 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -10,7 +10,7 @@ USAGE="[--quiet] add [-b <branch>] [-f|--force]
[--name <name>] [--reference <re
or: $dashless [--quiet] init [--] [<path>...]
or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch]
[-f|--force] [--rebase] [--reference <repository>] [--merge]
[--recursive] [--] [<path>...]
or: $dashless [--quiet] summary [--cached|--files] [--summary-limit
<n>] [commit] [--] [<path>...]
- or: $dashless [--quiet] foreach [--recursive] <command>
+ or: $dashless [--quiet] foreach [--recursive]
[--post-order=<command>] <command>
or: $dashless [--quiet] sync [--recursive] [--] [<path>...]"
OPTIONS_SPEC=
. git-sh-setup
@@ -434,6 +434,8 @@ Use -f if you really want to add it." >&2
cmd_foreach()
{
# parse $args after "submodule ... foreach".
+ # Gratuitous (empty) local's to prevent recursive bleeding
+ local recursive= post_order=
while test $# -ne 0
do
case "$1" in
@@ -443,6 +445,15 @@ cmd_foreach()
--recursive)
recursive=1
;;
+ --post-order)
+ test "$#" = "1" && usage
+ post_order="$2"
+ shift
+ ;;
+ --post-order=*)
+ # Will skip empty commands
+ post_order=${1#*=}
+ ;;
-*)
usage
;;
@@ -453,7 +464,7 @@ cmd_foreach()
shift
done
- toplevel=$(pwd)
+ local toplevel=$(pwd)
# dup stdin so that it can be restored when running the external
# command in the subshell (and a recursive call to this function)
@@ -465,18 +476,36 @@ cmd_foreach()
die_if_unmatched "$mode"
if test -e "$sm_path"/.git
then
- say "$(eval_gettext "Entering '\$prefix\$sm_path'")"
+ local name prefix path message epitaph
+ message="$(eval_gettext "Entering '\$prefix\$sm_path'")"
+ epitaph="$(eval_gettext "Stopping at '\$sm_path'; script
returned non-zero status.")"
name=$(module_name "$sm_path")
(
prefix="$prefix$sm_path/"
clear_local_git_env
# we make $path available to scripts ...
path=$sm_path
+
+ sm_eval() {
+ say "$message"
+ eval "$@" || die "$epitaph"
+ }
+
cd "$sm_path" &&
- eval "$@" &&
+ sm_eval "$@" &&
if test -n "$recursive"
then
- cmd_foreach "--recursive" "$@"
+ if test -n "$post_order"
+ then
+ # Tried keeping flags as a variable, but was
having difficulty
+ cmd_foreach --recursive --post-order
"$post_order" "$@"
+ else
+ cmd_foreach --recursive "$@"
+ fi
+ fi &&
+ if test -n "$post_order"
+ then
+ sm_eval "$post_order"
fi
) <&3 3<&- ||
die "$(eval_gettext "Stopping at '\$sm_path'; script
returned non-zero status.")"
--
1.8.2.rc1.24.g06d67b8.dirty
next prev parent reply other threads:[~2013-03-14 6:31 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-04 8:41 [PATCH/RFC] Changing submodule foreach --recursive to be depth-first, --parent option to execute command in supermodule as well Eric Cousineau
2013-03-04 22:15 ` Jens Lehmann
2013-03-04 23:00 ` Junio C Hamano
2013-03-05 5:37 ` Eric Cousineau
2013-03-05 7:59 ` Heiko Voigt
2013-03-05 16:09 ` Junio C Hamano
2013-03-05 16:42 ` Eric Cousineau
2013-03-05 18:34 ` Junio C Hamano
2013-03-05 20:51 ` Jens Lehmann
2013-03-05 21:17 ` Phil Hord
2013-03-09 18:18 ` Jens Lehmann
2013-03-11 16:46 ` Heiko Voigt
2013-03-12 16:01 ` Phil Hord
2013-03-14 6:30 ` Eric Cousineau [this message]
2013-03-18 21:25 ` Jens Lehmann
2013-03-26 4:03 ` Eric Cousineau
2013-04-02 20:14 ` Jens Lehmann
2013-04-13 4:04 ` [PATCH] submodule foreach: Added in --post-order=<command> and adjusted code per Jens Lehmann's suggestions eacousineau
[not found] ` <CA+aSAWuK9Yhvx-vO1fUteq-K=xOPgxkyeWeHG3UwZuDHsxLzAw@mail.gmail.com>
2013-04-13 4:11 ` Eric Cousineau
2013-04-14 18:52 ` Jens Lehmann
2013-03-18 21:10 ` [PATCH/RFC] Changing submodule foreach --recursive to be depth-first, --parent option to execute command in supermodule as well Jens Lehmann
2013-03-26 3:56 ` Eric Cousineau
2013-03-26 4:36 ` Eric Cousineau
2013-03-26 5:23 ` Junio C Hamano
2013-03-26 5:25 ` Junio C Hamano
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=51416E9F.7000604@gmail.com \
--to=eacousineau@gmail.com \
--cc=Jens.Lehmann@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hvoigt@hvoigt.net \
--cc=phil.hord@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.