filter-branch: provide the convenience functions also for commit filters
Move the convenience functions to the top of git-filter-branch.sh, and return from the script when the environment variable SOURCE_FUNCTIONS is set. By sourcing git-filter-branch with that variable set automatically, all commit filters may access the convenience functions like "map". Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Aug 31, 2007 at 20:05 UTC
7e0f1704b837355d833d84d18a3811d145867b97
3 files changed
+25
-13
Documentation/git-filter-branch.txt
-3
@@ -112,9 +112,6 @@ OPTIONS
112
As a special extension, the commit filter may emit multiple
113
commit ids; in that case, ancestors of the original commit will
114
have all of them as parents.
115
-+
116
-Note that the 'map' function is not available in the commit filter yet.
117
-This will be changed in a future version.
115
116
--tag-name-filter <command>::
117
This is the filter for rewriting tag names. When passed,
git-filter-branch.sh
+15
-10
@@ -8,15 +8,6 @@
8
# a new branch. You can specify a number of filters to modify the commits,
9
# files and trees.
10
11
-USAGE="[--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
-[--original <namespace>] [-d <directory>] [-f | --force] \
16
-[<rev-list options>...]"
17
-
18
-. git-sh-setup
19
-
11
warn () {
12
echo "$*" >&2
13
}
@@ -75,6 +66,20 @@ set_ident () {
66
echo "[ -n \"\$GIT_${uid}_NAME\" ] || export GIT_${uid}_NAME=\"\${GIT_${uid}_EMAIL%%@*}\""
67
}
68
69
+# This script can be sourced by the commit filter to get the functions
70
+test "a$SOURCE_FUNCTIONS" = a1 && return
71
+this_script="$(cd "$(dirname "$0")"; pwd)"/$(basename "$0")
72
+export this_script
73
+
74
+USAGE="[--env-filter <command>] [--tree-filter <command>] \
75
+[--index-filter <command>] [--parent-filter <command>] \
76
+[--msg-filter <command>] [--commit-filter <command>] \
77
+[--tag-name-filter <command>] [--subdirectory-filter <directory>] \
78
+[--original <namespace>] [-d <directory>] [-f | --force] \
79
+[<rev-list options>...]"
80
+
81
+. git-sh-setup
82
+
83
tempdir=.git-rewrite
84
filter_env=
85
filter_tree=
@@ -131,7 +136,7 @@ do
136
filter_msg="$OPTARG"
137
;;
138
--commit-filter)
134
- filter_commit="$OPTARG"
139
+ filter_commit='SOURCE_FUNCTIONS=1 . "$this_script";'" $OPTARG"
140
;;
141
--tag-name-filter)
142
filter_tag_name="$OPTARG"
t/t7003-filter-branch.sh
+10
@@ -159,4 +159,14 @@ test_expect_success 'barf on invalid name' '
159
! git filter-branch -f HEAD^
160
'
161
162
+test_expect_success '"map" works in commit filter' '
163
+ git filter-branch -f --commit-filter "\
164
+ parent=\$(git rev-parse \$GIT_COMMIT^) &&
165
+ mapped=\$(map \$parent) &&
166
+ actual=\$(echo \"\$@\" | sed \"s/^.*-p //\") &&
167
+ test \$mapped = \$actual &&
168
+ git commit-tree \"\$@\";" master~2..master &&
169
+ git rev-parse --verify master
170
+'
171
+
172
test_done