X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-filter-branch.sh;h=674a25d27e50b421e516e8ca6e1190d04e323e9c;hb=f2dc849e9c5fe363ad089f6c3f2b7b3d79fd6a6f;hp=a12f6c2d4c7ad3c4f69a783f7255b3010224d0c3;hpb=15eda0202aa3c63fa7b8f9f72df86f4e50eb1d2b;p=git.git diff --git a/git-filter-branch.sh b/git-filter-branch.sh index a12f6c2d4..674a25d27 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 ] [--tree-filter ] \ [--index-filter ] [--parent-filter ] \ [--msg-filter ] [--commit-filter ] \ @@ -92,8 +94,13 @@ USAGE="[--env-filter ] [--tree-filter ] \ [--original ] [-d ] [-f | --force] \ [...]" +OPTIONS_SPEC= . git-sh-setup +git diff-files --quiet && + git diff-index --cached --quiet HEAD -- || + die "Cannot rewrite branch(es) with a dirty working directory." + tempdir=.git-rewrite filter_env= filter_tree= @@ -151,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" @@ -196,6 +203,9 @@ do esac done < "$tempdir"/backup-refs +ORIG_GIT_DIR="$GIT_DIR" +ORIG_GIT_WORK_TREE="$GIT_WORK_TREE" +ORIG_GIT_INDEX_FILE="$GIT_INDEX_FILE" export GIT_DIR GIT_WORK_TREE=. # These refs should be updated if their heads were rewritten @@ -413,4 +423,12 @@ echo test $count -gt 0 && echo "These refs were rewritten:" git show-ref | grep ^"$orig_namespace" +unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE +test -z "$ORIG_GIT_DIR" || GIT_DIR="$ORIG_GIT_DIR" && export GIT_DIR +test -z "$ORIG_GIT_WORK_TREE" || GIT_WORK_TREE="$ORIG_GIT_WORK_TREE" && + export GIT_WORK_TREE +test -z "$ORIG_GIT_INDEX_FILE" || GIT_INDEX_FILE="$ORIG_GIT_INDEX_FILE" && + export GIT_INDEX_FILE +git read-tree -u -m HEAD + exit $ret