{"thread":{"id":"11043","subject":"[PATCH] filter-branch: fix dirty way to provide the helpers to commit filters","startedAt":"2007-11-28T15:50:38Z","lastAt":"2007-11-28T15:50:38Z","messageCount":1,"participants":["Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"61222","messageId":"Pine.LNX.4.64.0711281549550.27959@racer.site","threadId":"11043","inReplyTo":null,"subject":"[PATCH] filter-branch: fix dirty way to provide the helpers to commit filters","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-11-28T15:50:38Z","receivedAt":"2007-11-28T15:50:38Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThe helper functions 'map' and 'skip_commit' were provided to commit\nfilters by sourcing filter-branch itself.  This was done with a certain\nenvironment variable set to indicate that only the functions should be\ndefined, and the script should return then.\n\nThis was really hacky, and it did not work all that well, since the\nfull path to git-filter-branch was not known at all times.\n\nAvoid that by putting the functions into a variable, and eval'ing\nthat variable.  The commit filter gets these functions by prepending\nthe variable to the specified commands.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tFrankly, I have no idea why this worked, but it did.  However,\n\twe had to replace the spawnvpe() function in msysGit with a\n\tcustom version (thanks Hannes!) to avoid cmd windows popping up\n\tall over the place, and the method to source the first part of\n\tthe script back in commit filters failed.\n\n\tIndependently, I think that this version is nicer.\n\n git-filter-branch.sh |   14 ++++++++------\n 1 files changed, 8 insertions(+), 6 deletions(-)\n\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex c9f515d..19cab5a 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -8,6 +8,9 @@\n # a new branch. You can specify a number of filters to modify the commits,\n # files and trees.\n \n+# The following functions will also be available in the commit filter:\n+\n+functions=$(cat << \\EOF\n warn () {\n         echo \"$*\" >&2\n }\n@@ -46,6 +49,10 @@ die()\n \techo \"$*\" >&2\n \texit 1\n }\n+EOF\n+)\n+\n+eval \"$functions\"\n \n # When piped a commit, output a script to set the ident of either\n # \"author\" or \"committer\n@@ -80,11 +87,6 @@ set_ident () {\n \techo \"[ -n \\\"\\$GIT_${uid}_NAME\\\" ] || export GIT_${uid}_NAME=\\\"\\${GIT_${uid}_EMAIL%%@*}\\\"\"\n }\n \n-# This script can be sourced by the commit filter to get the functions\n-test \"a$SOURCE_FUNCTIONS\" = a1 && return\n-this_script=\"$(cd \"$(dirname \"$0\")\"; pwd)\"/$(basename \"$0\")\n-export this_script\n-\n USAGE=\"[--env-filter <command>] [--tree-filter <command>] \\\n [--index-filter <command>] [--parent-filter <command>] \\\n [--msg-filter <command>] [--commit-filter <command>] \\\n@@ -156,7 +158,7 @@ do\n \t\tfilter_msg=\"$OPTARG\"\n \t\t;;\n \t--commit-filter)\n-\t\tfilter_commit='SOURCE_FUNCTIONS=1 . \"$this_script\";'\" $OPTARG\"\n+\t\tfilter_commit=\"$functions; $OPTARG\"\n \t\t;;\n \t--tag-name-filter)\n \t\tfilter_tag_name=\"$OPTARG\"\n-- \n1.5.3.6.2065.gd47ac\n"}]}