diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt index 7b695dbb72..9e5169aa64 100644 --- a/Documentation/git-filter-branch.txt +++ b/Documentation/git-filter-branch.txt @@ -8,11 +8,11 @@ git-filter-branch - Rewrite branches SYNOPSIS -------- [verse] -'git filter-branch' [--env-filter ] [--tree-filter ] - [--index-filter ] [--parent-filter ] - [--msg-filter ] [--commit-filter ] - [--tag-name-filter ] [--subdirectory-filter ] - [--prune-empty] +'git filter-branch' [--setup ] [--env-filter ] + [--tree-filter ] [--index-filter ] + [--parent-filter ] [--msg-filter ] + [--commit-filter ] [--tag-name-filter ] + [--subdirectory-filter ] [--prune-empty] [--original ] [-d ] [-f | --force] [--] [...] @@ -82,6 +82,13 @@ multiple commits. OPTIONS ------- +--setup :: + This is not a real filter executed for each commit but a one + time setup just before the loop. Therefore no commit-specific + variables are defined yet. Functions or variables defined here + can be used or modified in the following filter steps except + the commit filter, for technical reasons. + --env-filter :: This filter may be used if you only need to modify the environment in which the commit will be performed. Specifically, you might diff --git a/git-filter-branch.sh b/git-filter-branch.sh index aafaf708da..3a74602ef3 100755 --- a/git-filter-branch.sh +++ b/git-filter-branch.sh @@ -81,12 +81,13 @@ set_ident () { finish_ident COMMITTER } -USAGE="[--env-filter ] [--tree-filter ] - [--index-filter ] [--parent-filter ] - [--msg-filter ] [--commit-filter ] - [--tag-name-filter ] [--subdirectory-filter ] - [--original ] [-d ] [-f | --force] - [...]" +USAGE="[--setup ] [--env-filter ] + [--tree-filter ] [--index-filter ] + [--parent-filter ] [--msg-filter ] + [--commit-filter ] [--tag-name-filter ] + [--subdirectory-filter ] [--original ] + [-d ] [-f | --force] + [--] [...]" OPTIONS_SPEC= . git-sh-setup @@ -96,6 +97,7 @@ if [ "$(is_bare_repository)" = false ]; then fi tempdir=.git-rewrite +filter_setup= filter_env= filter_tree= filter_index= @@ -148,6 +150,9 @@ do -d) tempdir="$OPTARG" ;; + --setup) + filter_setup="$OPTARG" + ;; --env-filter) filter_env="$OPTARG" ;; @@ -317,6 +322,9 @@ else need_index= fi +eval "$filter_setup" < /dev/null || + die "filter setup failed: $filter_setup" + while read commit parents; do git_filter_branch__commit_count=$(($git_filter_branch__commit_count+1))