Skip to content

Commit 3b117f7

Browse files
asheidukgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 41dd433 commit 3b117f7

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

Documentation/git-filter-branch.txt

+12-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ git-filter-branch - Rewrite branches
88
SYNOPSIS
99
--------
1010
[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]
1616
[--original <namespace>] [-d <directory>] [-f | --force]
1717
[--] [<rev-list options>...]
1818

@@ -82,6 +82,13 @@ multiple commits.
8282
OPTIONS
8383
-------
8484

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+
8592
--env-filter <command>::
8693
This filter may be used if you only need to modify the environment
8794
in which the commit will be performed. Specifically, you might

git-filter-branch.sh

+13-5
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ set_ident () {
8181
finish_ident COMMITTER
8282
}
8383

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]
8990
[<rev-list options>...]"
9091

9192
OPTIONS_SPEC=
@@ -96,6 +97,7 @@ if [ "$(is_bare_repository)" = false ]; then
9697
fi
9798

9899
tempdir=.git-rewrite
100+
filter_setup=
99101
filter_env=
100102
filter_tree=
101103
filter_index=
@@ -148,6 +150,9 @@ do
148150
-d)
149151
tempdir="$OPTARG"
150152
;;
153+
--setup)
154+
filter_setup="$OPTARG"
155+
;;
151156
--env-filter)
152157
filter_env="$OPTARG"
153158
;;
@@ -317,6 +322,9 @@ else
317322
need_index=
318323
fi
319324

325+
eval "$filter_setup" < /dev/null ||
326+
die "filter setup failed: $filter_setup"
327+
320328
while read commit parents; do
321329
git_filter_branch__commit_count=$(($git_filter_branch__commit_count+1))
322330

0 commit comments

Comments
 (0)