Skip to content

Commit

Permalink
filter-branch: fix dirty way to provide the helpers to commit filters
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Nov 28, 2007
1 parent aa4f31d commit 16ed34a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions git-filter-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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>] \
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 16ed34a

Please sign in to comment.