filter-branch: add --setup step

A `--setup` step in `git filter-branch` makes it much easier to
define the initial values of variables used in the real filters.
Also sourcing/defining utility functions here instead of
`--env-filter` improves performance and minimizes clogging the
output in case of errors.

Signed-off-by: Andreas Heiduk <asheiduk@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Andreas Heiduk
2017-06-10 10:54:44 +02:00
committed by Junio C Hamano
parent 41dd4330a1
commit 3b117f7301
2 changed files with 25 additions and 10 deletions

View File

@@ -8,11 +8,11 @@ git-filter-branch - Rewrite branches
SYNOPSIS SYNOPSIS
-------- --------
[verse] [verse]
'git filter-branch' [--env-filter <command>] [--tree-filter <command>] 'git filter-branch' [--setup <command>] [--env-filter <command>]
[--index-filter <command>] [--parent-filter <command>] [--tree-filter <command>] [--index-filter <command>]
[--msg-filter <command>] [--commit-filter <command>] [--parent-filter <command>] [--msg-filter <command>]
[--tag-name-filter <command>] [--subdirectory-filter <directory>] [--commit-filter <command>] [--tag-name-filter <command>]
[--prune-empty] [--subdirectory-filter <directory>] [--prune-empty]
[--original <namespace>] [-d <directory>] [-f | --force] [--original <namespace>] [-d <directory>] [-f | --force]
[--] [<rev-list options>...] [--] [<rev-list options>...]
@@ -82,6 +82,13 @@ multiple commits.
OPTIONS OPTIONS
------- -------
--setup <command>::
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 <command>:: --env-filter <command>::
This filter may be used if you only need to modify the environment This filter may be used if you only need to modify the environment
in which the commit will be performed. Specifically, you might in which the commit will be performed. Specifically, you might

View File

@@ -81,11 +81,12 @@ set_ident () {
finish_ident COMMITTER finish_ident COMMITTER
} }
USAGE="[--env-filter <command>] [--tree-filter <command>] USAGE="[--setup <command>] [--env-filter <command>]
[--index-filter <command>] [--parent-filter <command>] [--tree-filter <command>] [--index-filter <command>]
[--msg-filter <command>] [--commit-filter <command>] [--parent-filter <command>] [--msg-filter <command>]
[--tag-name-filter <command>] [--subdirectory-filter <directory>] [--commit-filter <command>] [--tag-name-filter <command>]
[--original <namespace>] [-d <directory>] [-f | --force] [--subdirectory-filter <directory>] [--original <namespace>]
[-d <directory>] [-f | --force]
[<rev-list options>...]" [<rev-list options>...]"
OPTIONS_SPEC= OPTIONS_SPEC=
@@ -96,6 +97,7 @@ if [ "$(is_bare_repository)" = false ]; then
fi fi
tempdir=.git-rewrite tempdir=.git-rewrite
filter_setup=
filter_env= filter_env=
filter_tree= filter_tree=
filter_index= filter_index=
@@ -148,6 +150,9 @@ do
-d) -d)
tempdir="$OPTARG" tempdir="$OPTARG"
;; ;;
--setup)
filter_setup="$OPTARG"
;;
--env-filter) --env-filter)
filter_env="$OPTARG" filter_env="$OPTARG"
;; ;;
@@ -317,6 +322,9 @@ else
need_index= need_index=
fi fi
eval "$filter_setup" < /dev/null ||
die "filter setup failed: $filter_setup"
while read commit parents; do while read commit parents; do
git_filter_branch__commit_count=$(($git_filter_branch__commit_count+1)) git_filter_branch__commit_count=$(($git_filter_branch__commit_count+1))