git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: git@vger.kernel.org, gitster@pobox.com
Subject: [PATCH] filter-branch: fix dirty way to provide the helpers to commit filters
Date: Wed, 28 Nov 2007 15:50:38 +0000 (GMT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0711281549550.27959@racer.site> (raw)


The helper functions 'map' and 'skip_commit' were provided to commit
filters by sourcing filter-branch itself.  This was done with a certain
environment variable set to indicate that only the functions should be
defined, and the script should return then.

This was really hacky, and it did not work all that well, since the
full path to git-filter-branch was not known at all times.

Avoid that by putting the functions into a variable, and eval'ing
that variable.  The commit filter gets these functions by prepending
the variable to the specified commands.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---

	Frankly, I have no idea why this worked, but it did.  However,
	we had to replace the spawnvpe() function in msysGit with a
	custom version (thanks Hannes!) to avoid cmd windows popping up
	all over the place, and the method to source the first part of
	the script back in commit filters failed.

	Independently, I think that this version is nicer.

 git-filter-branch.sh |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index c9f515d..19cab5a 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -8,6 +8,9 @@
 # a new branch. You can specify a number of filters to modify the commits,
 # files and trees.
 
+# The following functions will also be available in the commit filter:
+
+functions=$(cat << \EOF
 warn () {
         echo "$*" >&2
 }
@@ -46,6 +49,10 @@ die()
 	echo "$*" >&2
 	exit 1
 }
+EOF
+)
+
+eval "$functions"
 
 # When piped a commit, output a script to set the ident of either
 # "author" or "committer
@@ -80,11 +87,6 @@ set_ident () {
 	echo "[ -n \"\$GIT_${uid}_NAME\" ] || export GIT_${uid}_NAME=\"\${GIT_${uid}_EMAIL%%@*}\""
 }
 
-# This script can be sourced by the commit filter to get the functions
-test "a$SOURCE_FUNCTIONS" = a1 && return
-this_script="$(cd "$(dirname "$0")"; pwd)"/$(basename "$0")
-export this_script
-
 USAGE="[--env-filter <command>] [--tree-filter <command>] \
 [--index-filter <command>] [--parent-filter <command>] \
 [--msg-filter <command>] [--commit-filter <command>] \
@@ -156,7 +158,7 @@ do
 		filter_msg="$OPTARG"
 		;;
 	--commit-filter)
-		filter_commit='SOURCE_FUNCTIONS=1 . "$this_script";'" $OPTARG"
+		filter_commit="$functions; $OPTARG"
 		;;
 	--tag-name-filter)
 		filter_tag_name="$OPTARG"
-- 
1.5.3.6.2065.gd47ac

                 reply	other threads:[~2007-11-28 15:51 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=Pine.LNX.4.64.0711281549550.27959@racer.site \
    --to=johannes.schindelin@gmx.de \
    --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).