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>
Andreas Heiduk committed
Jun 10, 2017 at 10:54 UTC
3b117f730185ec8acdc8f1b680b9f0a9b647fc0f
2 files changed
+25
-10
Documentation/git-filter-branch.txt
+12
-5
@@ -8,11 +8,11 @@ git-filter-branch - Rewrite branches
8
SYNOPSIS
9
--------
10
[verse]
11
-'git filter-branch' [--env-filter <command>] [--tree-filter <command>]
12
- [--index-filter <command>] [--parent-filter <command>]
13
- [--msg-filter <command>] [--commit-filter <command>]
14
- [--tag-name-filter <command>] [--subdirectory-filter <directory>]
15
- [--prune-empty]
11
+'git filter-branch' [--setup <command>] [--env-filter <command>]
12
+ [--tree-filter <command>] [--index-filter <command>]
13
+ [--parent-filter <command>] [--msg-filter <command>]
14
+ [--commit-filter <command>] [--tag-name-filter <command>]
15
+ [--subdirectory-filter <directory>] [--prune-empty]
16
[--original <namespace>] [-d <directory>] [-f | --force]
17
[--] [<rev-list options>...]
18
@@ -82,6 +82,13 @@ multiple commits.
82
OPTIONS
83
-------
84
85
+--setup <command>::
86
+ This is not a real filter executed for each commit but a one
87
+ time setup just before the loop. Therefore no commit-specific
88
+ variables are defined yet. Functions or variables defined here
89
+ can be used or modified in the following filter steps except
90
+ the commit filter, for technical reasons.
91
+
92
--env-filter <command>::
93
This filter may be used if you only need to modify the environment
94
in which the commit will be performed. Specifically, you might
git-filter-branch.sh
+13
-5
@@ -81,11 +81,12 @@ set_ident () {
81
finish_ident COMMITTER
82
}
83
84
-USAGE="[--env-filter <command>] [--tree-filter <command>]
85
- [--index-filter <command>] [--parent-filter <command>]
86
- [--msg-filter <command>] [--commit-filter <command>]
87
- [--tag-name-filter <command>] [--subdirectory-filter <directory>]
88
- [--original <namespace>] [-d <directory>] [-f | --force]
84
+USAGE="[--setup <command>] [--env-filter <command>]
85
+ [--tree-filter <command>] [--index-filter <command>]
86
+ [--parent-filter <command>] [--msg-filter <command>]
87
+ [--commit-filter <command>] [--tag-name-filter <command>]
88
+ [--subdirectory-filter <directory>] [--original <namespace>]
89
+ [-d <directory>] [-f | --force]
90
[<rev-list options>...]"
91
92
OPTIONS_SPEC=
@@ -96,6 +97,7 @@ if [ "$(is_bare_repository)" = false ]; then
97
fi
98
99
tempdir=.git-rewrite
100
+filter_setup=
101
filter_env=
102
filter_tree=
103
filter_index=
@@ -148,6 +150,9 @@ do
150
-d)
151
tempdir="$OPTARG"
152
;;
153
+ --setup)
154
+ filter_setup="$OPTARG"
155
+ ;;
156
--env-filter)
157
filter_env="$OPTARG"
158
;;
@@ -317,6 +322,9 @@ else
322
need_index=
323
fi
324
325
+eval "$filter_setup" < /dev/null ||
326
+ die "filter setup failed: $filter_setup"
327
+
328
while read commit parents; do
329
git_filter_branch__commit_count=$(($git_filter_branch__commit_count+1))
330