@matheusbsbs / matheus-bagliano / commits / 16ed34ad35
Fork 0

filter-branch: fix dirty way to provide the helpers to commit filters

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Nov 28, 2007 at 15:50 UTC 16ed34ad35d9a991a72b2db420ff95bc260990cc
1 file changed +8 -6
git-filter-branch.sh
+8 -6
@@ -8,6 +8,9 @@
8 # a new branch. You can specify a number of filters to modify the commits,
9 # files and trees.
10
11 +# The following functions will also be available in the commit filter:
12 +
13 +functions=$(cat << \EOF
14 warn () {
15 echo "$*" >&2
16 }
@@ -46,6 +49,10 @@ die()
49 echo "$*" >&2
50 exit 1
51 }
52 +EOF
53 +)
54 +
55 +eval "$functions"
56
57 # When piped a commit, output a script to set the ident of either
58 # "author" or "committer
@@ -80,11 +87,6 @@ set_ident () {
87 echo "[ -n \"\$GIT_${uid}_NAME\" ] || export GIT_${uid}_NAME=\"\${GIT_${uid}_EMAIL%%@*}\""
88 }
89
83 -# This script can be sourced by the commit filter to get the functions
84 -test "a$SOURCE_FUNCTIONS" = a1 && return
85 -this_script="$(cd "$(dirname "$0")"; pwd)"/$(basename "$0")
86 -export this_script
87 -
90 USAGE="[--env-filter <command>] [--tree-filter <command>] \
91 [--index-filter <command>] [--parent-filter <command>] \
92 [--msg-filter <command>] [--commit-filter <command>] \
@@ -156,7 +158,7 @@ do
158 filter_msg="$OPTARG"
159 ;;
160 --commit-filter)
159 - filter_commit='SOURCE_FUNCTIONS=1 . "$this_script";'" $OPTARG"
161 + filter_commit="$functions; $OPTARG"
162 ;;
163 --tag-name-filter)
164 filter_tag_name="$OPTARG"