filter-branch: use git-sh-setup's ident parsing functions
This saves us some code, but it also reduces the number of processes we start for each filtered commit. Since we can parse both author and committer in the same sed invocation, we save one process. And since the new interface avoids tr, we save 4 processes. It also avoids using "tr", which has had some odd portability problems reported with from Solaris's xpg6 version. We also tweak one of the tests in t7003 to double-check that we are properly exporting the variables (because test-lib.sh exports GIT_AUTHOR_NAME, it will be automatically exported in subprograms. We override this to make sure that filter-branch handles it properly itself). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Oct 18, 2012 at 06:33 UTC
3c730fab2cae1bb52d34620af170a628b3b8c537
2 files changed
+16
-35
git-filter-branch.sh
+13
-33
@@ -64,37 +64,19 @@ EOF
64
65
eval "$functions"
66
67
-# When piped a commit, output a script to set the ident of either
68
-# "author" or "committer
67
+finish_ident() {
68
+ # Ensure non-empty id name.
69
+ echo "case \"\$GIT_$1_NAME\" in \"\") GIT_$1_NAME=\"\${GIT_$1_EMAIL%%@*}\" && export GIT_$1_NAME;; esac"
70
+ # And make sure everything is exported.
71
+ echo "export GIT_$1_NAME"
72
+ echo "export GIT_$1_EMAIL"
73
+ echo "export GIT_$1_DATE"
74
+}
75
76
set_ident () {
71
- lid="$(echo "$1" | tr "[A-Z]" "[a-z]")"
72
- uid="$(echo "$1" | tr "[a-z]" "[A-Z]")"
73
- pick_id_script='
74
- /^'$lid' /{
75
- s/'\''/'\''\\'\'\''/g
76
- h
77
- s/^'$lid' \([^<]*\) <[^>]*> .*$/\1/
78
- s/'\''/'\''\'\'\''/g
79
- s/.*/GIT_'$uid'_NAME='\''&'\''; export GIT_'$uid'_NAME/p
80
-
81
- g
82
- s/^'$lid' [^<]* <\([^>]*\)> .*$/\1/
83
- s/'\''/'\''\'\'\''/g
84
- s/.*/GIT_'$uid'_EMAIL='\''&'\''; export GIT_'$uid'_EMAIL/p
85
-
86
- g
87
- s/^'$lid' [^<]* <[^>]*> \(.*\)$/@\1/
88
- s/'\''/'\''\'\'\''/g
89
- s/.*/GIT_'$uid'_DATE='\''&'\''; export GIT_'$uid'_DATE/p
90
-
91
- q
92
- }
93
- '
94
-
95
- LANG=C LC_ALL=C sed -ne "$pick_id_script"
96
- # Ensure non-empty id name.
97
- echo "case \"\$GIT_${uid}_NAME\" in \"\") GIT_${uid}_NAME=\"\${GIT_${uid}_EMAIL%%@*}\" && export GIT_${uid}_NAME;; esac"
77
+ parse_ident_from_commit author AUTHOR committer COMMITTER
78
+ finish_ident AUTHOR
79
+ finish_ident COMMITTER
80
}
81
82
USAGE="[--env-filter <command>] [--tree-filter <command>]
@@ -320,10 +302,8 @@ while read commit parents; do
302
git cat-file commit "$commit" >../commit ||
303
die "Cannot read commit $commit"
304
323
- eval "$(set_ident AUTHOR <../commit)" ||
324
- die "setting author failed for commit $commit"
325
- eval "$(set_ident COMMITTER <../commit)" ||
326
- die "setting committer failed for commit $commit"
305
+ eval "$(set_ident <../commit)" ||
306
+ die "setting author/committer failed for commit $commit"
307
eval "$filter_env" < /dev/null ||
308
die "env filter failed: $filter_env"
309
t/t7003-filter-branch.sh
+3
-2
@@ -167,10 +167,11 @@ test_expect_success 'author information is preserved' '
167
test_tick &&
168
GIT_AUTHOR_NAME="B V Uips" git commit -m bvuips &&
169
git branch preserved-author &&
170
- git filter-branch -f --msg-filter "cat; \
170
+ (sane_unset GIT_AUTHOR_NAME &&
171
+ git filter-branch -f --msg-filter "cat; \
172
test \$GIT_COMMIT != $(git rev-parse master) || \
173
echo Hallo" \
173
- preserved-author &&
174
+ preserved-author) &&
175
test 1 = $(git rev-list --author="B V Uips" preserved-author | wc -l)
176
'
177