]> git.ipfire.org Git - thirdparty/git.git/blame - git-filter-branch.sh
Eleventh batch
[thirdparty/git.git] / git-filter-branch.sh
CommitLineData
6f6826c5
JS
1#!/bin/sh
2#
3# Rewrite revision history
4# Copyright (c) Petr Baudis, 2006
5# Minimal changes to "port" it to core-git (c) Johannes Schindelin, 2007
6#
c401b33c
JS
7# Lets you rewrite the revision history of the current branch, creating
8# a new branch. You can specify a number of filters to modify the commits,
9# files and trees.
6f6826c5 10
16ed34ad
JS
11# The following functions will also be available in the commit filter:
12
13functions=$(cat << \EOF
03a7f388 14EMPTY_TREE=$(git hash-object -t tree /dev/null)
15
b5669a05 16warn () {
285c6cbf 17 echo "$*" >&2
b5669a05
SP
18}
19
6f6826c5
JS
20map()
21{
3520e1e8 22 # if it was not rewritten, take the original
c57a3494
JS
23 if test -r "$workdir/../map/$1"
24 then
25 cat "$workdir/../map/$1"
26 else
27 echo "$1"
28 fi
6f6826c5
JS
29}
30
f95eef15
JS
31# if you run 'skip_commit "$@"' in a commit filter, it will print
32# the (mapped) parents, effectively skipping the commit.
33
34skip_commit()
35{
36 shift;
37 while [ -n "$1" ];
38 do
39 shift;
40 map "$1";
41 shift;
42 done;
43}
44
d3240d93
PH
45# if you run 'git_commit_non_empty_tree "$@"' in a commit filter,
46# it will skip commits that leave the tree untouched, commit the other.
47git_commit_non_empty_tree()
48{
49 if test $# = 3 && test "$1" = $(git rev-parse "$3^{tree}"); then
50 map "$3"
03a7f388 51 elif test $# = 1 && test "$1" = $EMPTY_TREE; then
a582a82d 52 :
d3240d93
PH
53 else
54 git commit-tree "$@"
55 fi
56}
8c1ce0f4
JS
57# override die(): this version puts in an extra line break, so that
58# the progress is still visible
59
60die()
61{
62 echo >&2
63 echo "$*" >&2
64 exit 1
65}
16ed34ad
JS
66EOF
67)
68
69eval "$functions"
8c1ce0f4 70
3c730fab
JK
71finish_ident() {
72 # Ensure non-empty id name.
73 echo "case \"\$GIT_$1_NAME\" in \"\") GIT_$1_NAME=\"\${GIT_$1_EMAIL%%@*}\" && export GIT_$1_NAME;; esac"
74 # And make sure everything is exported.
75 echo "export GIT_$1_NAME"
76 echo "export GIT_$1_EMAIL"
77 echo "export GIT_$1_DATE"
78}
6f6826c5
JS
79
80set_ident () {
3c730fab
JK
81 parse_ident_from_commit author AUTHOR committer COMMITTER
82 finish_ident AUTHOR
83 finish_ident COMMITTER
6f6826c5
JS
84}
85
9df53c5d
EN
86if test -z "$FILTER_BRANCH_SQUELCH_WARNING$GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS"
87then
88 cat <<EOF
89WARNING: git-filter-branch has a glut of gotchas generating mangled history
90 rewrites. Hit Ctrl-C before proceeding to abort, then use an
91 alternative filtering tool such as 'git filter-repo'
92 (https://github.com/newren/git-filter-repo/) instead. See the
93 filter-branch manual page for more details; to squelch this warning,
94 set FILTER_BRANCH_SQUELCH_WARNING=1.
95EOF
96 sleep 10
97 printf "Proceeding with filter-branch...\n\n"
98fi
99
e336afdf 100USAGE="[--setup <command>] [--subdirectory-filter <directory>] [--env-filter <command>]
3b117f73
AH
101 [--tree-filter <command>] [--index-filter <command>]
102 [--parent-filter <command>] [--msg-filter <command>]
103 [--commit-filter <command>] [--tag-name-filter <command>]
e336afdf 104 [--original <namespace>]
bd2c79fb 105 [-d <directory>] [-f | --force] [--state-branch <branch>]
d612975e 106 [--] [<rev-list options>...]"
7e0f1704 107
8f321a39 108OPTIONS_SPEC=
7e0f1704
JS
109. git-sh-setup
110
a4661b01 111if [ "$(is_bare_repository)" = false ]; then
5347a50f 112 require_clean_work_tree 'rewrite branches'
a4661b01 113fi
46eb449c 114
6f6826c5 115tempdir=.git-rewrite
3b117f73 116filter_setup=
6f6826c5
JS
117filter_env=
118filter_tree=
119filter_index=
120filter_parent=
121filter_msg=cat
d3240d93 122filter_commit=
6f6826c5 123filter_tag_name=
685ef546 124filter_subdir=
bd2c79fb 125state_branch=
dfd05e38
JS
126orig_namespace=refs/original/
127force=
d3240d93 128prune_empty=
f2f3a6b8 129remap_to_ancestor=
822f7c73 130while :
6f6826c5
JS
131do
132 case "$1" in
133 --)
134 shift
135 break
136 ;;
dfd05e38
JS
137 --force|-f)
138 shift
139 force=t
140 continue
141 ;;
f2f3a6b8 142 --remap-to-ancestor)
7ec344d8 143 # deprecated ($remap_to_ancestor is set now automatically)
f2f3a6b8
TR
144 shift
145 remap_to_ancestor=t
146 continue
147 ;;
d3240d93
PH
148 --prune-empty)
149 shift
150 prune_empty=t
151 continue
152 ;;
6f6826c5
JS
153 -*)
154 ;;
155 *)
156 break;
157 esac
158
159 # all switches take one argument
160 ARG="$1"
161 case "$#" in 1) usage ;; esac
162 shift
163 OPTARG="$1"
164 shift
165
166 case "$ARG" in
167 -d)
168 tempdir="$OPTARG"
169 ;;
3b117f73
AH
170 --setup)
171 filter_setup="$OPTARG"
172 ;;
07c49845
DG
173 --subdirectory-filter)
174 filter_subdir="$OPTARG"
175 remap_to_ancestor=t
176 ;;
6f6826c5
JS
177 --env-filter)
178 filter_env="$OPTARG"
179 ;;
180 --tree-filter)
181 filter_tree="$OPTARG"
182 ;;
183 --index-filter)
184 filter_index="$OPTARG"
185 ;;
186 --parent-filter)
187 filter_parent="$OPTARG"
188 ;;
189 --msg-filter)
190 filter_msg="$OPTARG"
191 ;;
192 --commit-filter)
16ed34ad 193 filter_commit="$functions; $OPTARG"
6f6826c5
JS
194 ;;
195 --tag-name-filter)
196 filter_tag_name="$OPTARG"
197 ;;
dfd05e38 198 --original)
55ced83d 199 orig_namespace=$(expr "$OPTARG/" : '\(.*[^/]\)/*$')/
dfd05e38 200 ;;
bd2c79fb
IC
201 --state-branch)
202 state_branch="$OPTARG"
203 ;;
6f6826c5
JS
204 *)
205 usage
206 ;;
207 esac
208done
209
d3240d93
PH
210case "$prune_empty,$filter_commit" in
211,)
212 filter_commit='git commit-tree "$@"';;
213t,)
214 filter_commit="$functions;"' git_commit_non_empty_tree "$@"';;
215,*)
216 ;;
217*)
5da81713 218 die "Cannot set --prune-empty and --commit-filter at the same time"
d3240d93
PH
219esac
220
dfd05e38
JS
221case "$force" in
222t)
223 rm -rf "$tempdir"
224;;
225'')
226 test -d "$tempdir" &&
227 die "$tempdir already exists, please remove it"
228esac
97276019 229orig_dir=$(pwd)
af580e9c 230mkdir -p "$tempdir/t" &&
dfd05e38 231tempdir="$(cd "$tempdir"; pwd)" &&
af580e9c
JS
232cd "$tempdir/t" &&
233workdir="$(pwd)" ||
234die ""
6f6826c5 235
def16e71 236# Remove tempdir on exit
97276019 237trap 'cd "$orig_dir"; rm -rf "$tempdir"' 0
def16e71 238
88e38808
LN
239ORIG_GIT_DIR="$GIT_DIR"
240ORIG_GIT_WORK_TREE="$GIT_WORK_TREE"
241ORIG_GIT_INDEX_FILE="$GIT_INDEX_FILE"
7b1378bd
IC
242ORIG_GIT_AUTHOR_NAME="$GIT_AUTHOR_NAME"
243ORIG_GIT_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL"
244ORIG_GIT_AUTHOR_DATE="$GIT_AUTHOR_DATE"
245ORIG_GIT_COMMITTER_NAME="$GIT_COMMITTER_NAME"
246ORIG_GIT_COMMITTER_EMAIL="$GIT_COMMITTER_EMAIL"
247ORIG_GIT_COMMITTER_DATE="$GIT_COMMITTER_DATE"
248
88e38808
LN
249GIT_WORK_TREE=.
250export GIT_DIR GIT_WORK_TREE
251
dfd05e38 252# Make sure refs/original is empty
0ea29cce 253git for-each-ref > "$tempdir"/backup-refs || exit
dfd05e38
JS
254while read sha1 type name
255do
256 case "$force,$name" in
257 ,$orig_namespace*)
734cd572
JT
258 die "Cannot create a new backup.
259A previous backup already exists in $orig_namespace
260Force overwriting the backup with -f"
dfd05e38
JS
261 ;;
262 t,$orig_namespace*)
263 git update-ref -d "$name" $sha1
264 ;;
265 esac
266done < "$tempdir"/backup-refs
267
418fa3a5 268# The refs should be updated if their heads were rewritten
0ea29cce 269git rev-parse --no-flags --revs-only --symbolic-full-name \
f78ab355
YK
270 --default HEAD "$@" > "$tempdir"/raw-refs || exit
271while read ref
272do
273 case "$ref" in ^?*) continue ;; esac
274
275 if git rev-parse --verify "$ref"^0 >/dev/null 2>&1
276 then
277 echo "$ref"
278 else
279 warn "WARNING: not rewriting '$ref' (not a committish)"
280 fi
281done >"$tempdir"/heads <"$tempdir"/raw-refs
dfd05e38
JS
282
283test -s "$tempdir"/heads ||
69638939 284 die "You must specify a ref to rewrite."
dfd05e38 285
3addc94a
JS
286GIT_INDEX_FILE="$(pwd)/../index"
287export GIT_INDEX_FILE
6f6826c5 288
af580e9c
JS
289# map old->new commit ids for rewriting parents
290mkdir ../map || die "Could not create map/ directory"
6f6826c5 291
bd2c79fb
IC
292if test -n "$state_branch"
293then
294 state_commit=$(git rev-parse --no-flags --revs-only "$state_branch")
295 if test -n "$state_commit"
296 then
297 echo "Populating map from $state_branch ($state_commit)" 1>&2
298 perl -e'open(MAP, "-|", "git show $ARGV[0]:filter.map") or die;
299 while (<MAP>) {
300 m/(.*):(.*)/ or die;
301 open F, ">../map/$1" or die;
302 print F "$2" or die;
303 close(F) or die;
304 }
305 close(MAP) or die;' "$state_commit" \
306 || die "Unable to load state from $state_branch:filter.map"
307 else
308 echo "Branch $state_branch does not exist. Will create" 1>&2
309 fi
310fi
311
2c1d2d81
TR
312# we need "--" only if there are no path arguments in $@
313nonrevs=$(git rev-parse --no-revs "$@") || exit
7ec344d8
CH
314if test -z "$nonrevs"
315then
316 dashdash=--
317else
318 dashdash=
319 remap_to_ancestor=t
320fi
321
3361a548 322git rev-parse --revs-only "$@" >../parse
2c1d2d81 323
685ef546
JS
324case "$filter_subdir" in
325"")
2c1d2d81 326 eval set -- "$(git rev-parse --sq --no-revs "$@")"
685ef546
JS
327 ;;
328*)
2c1d2d81
TR
329 eval set -- "$(git rev-parse --sq --no-revs "$@" $dashdash \
330 "$filter_subdir")"
331 ;;
332esac
333
334git rev-list --reverse --topo-order --default HEAD \
3361a548 335 --parents --simplify-merges --stdin "$@" <../parse >../revs ||
2c1d2d81 336 die "Could not get the commits"
9d6f220c 337commits=$(wc -l <../revs | tr -d " ")
6f6826c5 338
0a0eb2e5 339test $commits -eq 0 && die_with_status 2 "Found nothing to rewrite"
6f6826c5 340
dfd05e38 341# Rewrite the commits
6a9d16a0
GB
342report_progress ()
343{
344 if test -n "$progress" &&
345 test $git_filter_branch__commit_count -gt $next_sample_at
346 then
71400d97
JH
347 count=$git_filter_branch__commit_count
348
349 now=$(date +%s)
350 elapsed=$(($now - $start_timestamp))
351 remaining=$(( ($commits - $count) * $elapsed / $count ))
352 if test $elapsed -gt 0
6a9d16a0 353 then
71400d97 354 next_sample_at=$(( ($elapsed + 1) * $count / $elapsed ))
6a9d16a0
GB
355 else
356 next_sample_at=$(($next_sample_at + 1))
357 fi
71400d97 358 progress=" ($elapsed seconds passed, remaining $remaining predicted)"
6a9d16a0 359 fi
71400d97 360 printf "\rRewrite $commit ($count/$commits)$progress "
6a9d16a0 361}
dfd05e38 362
d5b0c97d 363git_filter_branch__commit_count=0
6a9d16a0
GB
364
365progress= start_timestamp=
366if date '+%s' 2>/dev/null | grep -q '^[0-9][0-9]*$'
367then
368 next_sample_at=0
369 progress="dummy to ensure this is not empty"
370 start_timestamp=$(date '+%s')
371fi
372
348d4f2f
JK
373if test -n "$filter_index" ||
374 test -n "$filter_tree" ||
375 test -n "$filter_subdir"
376then
377 need_index=t
378else
379 need_index=
380fi
381
3b117f73
AH
382eval "$filter_setup" < /dev/null ||
383 die "filter setup failed: $filter_setup"
384
813b4734 385while read commit parents; do
d5b0c97d 386 git_filter_branch__commit_count=$(($git_filter_branch__commit_count+1))
6a9d16a0
GB
387
388 report_progress
709cfe84 389 test -f "$workdir"/../map/$commit && continue
6f6826c5 390
685ef546
JS
391 case "$filter_subdir" in
392 "")
348d4f2f
JK
393 if test -n "$need_index"
394 then
395 GIT_ALLOW_NULL_SHA1=1 git read-tree -i -m $commit
396 fi
685ef546
JS
397 ;;
398 *)
5b044ac3 399 # The commit may not have the subdirectory at all
83bd7437
JK
400 err=$(GIT_ALLOW_NULL_SHA1=1 \
401 git read-tree -i -m $commit:"$filter_subdir" 2>&1) || {
d69da76d 402 if ! git rev-parse -q --verify $commit:"$filter_subdir"
5b044ac3
JH
403 then
404 rm -f "$GIT_INDEX_FILE"
405 else
406 echo >&2 "$err"
407 false
408 fi
409 }
af580e9c 410 esac || die "Could not initialize the index"
6f6826c5 411
3addc94a
JS
412 GIT_COMMIT=$commit
413 export GIT_COMMIT
af580e9c
JS
414 git cat-file commit "$commit" >../commit ||
415 die "Cannot read commit $commit"
6f6826c5 416
3c730fab
JK
417 eval "$(set_ident <../commit)" ||
418 die "setting author/committer failed for commit $commit"
8c1ce0f4
JS
419 eval "$filter_env" < /dev/null ||
420 die "env filter failed: $filter_env"
6f6826c5
JS
421
422 if [ "$filter_tree" ]; then
af580e9c
JS
423 git checkout-index -f -u -a ||
424 die "Could not checkout the index"
6f6826c5
JS
425 # files that $commit removed are now still in the working tree;
426 # remove them, else they would be added again
6a589fda 427 git clean -d -q -f -x
8c1ce0f4
JS
428 eval "$filter_tree" < /dev/null ||
429 die "tree filter failed: $filter_tree"
430
1fe32cb9 431 (
4d2a3646 432 git diff-index -r --name-only --ignore-submodules $commit -- &&
1fe32cb9 433 git ls-files --others
0ea29cce
EK
434 ) > "$tempdir"/tree-state || exit
435 git update-index --add --replace --remove --stdin \
436 < "$tempdir"/tree-state || exit
6f6826c5
JS
437 fi
438
8c1ce0f4
JS
439 eval "$filter_index" < /dev/null ||
440 die "index filter failed: $filter_index"
6f6826c5
JS
441
442 parentstr=
813b4734 443 for parent in $parents; do
3520e1e8 444 for reparent in $(map "$parent"); do
79bc4ef3
CB
445 case "$parentstr " in
446 *" -p $reparent "*)
447 ;;
448 *)
449 parentstr="$parentstr -p $reparent"
450 ;;
451 esac
3520e1e8 452 done
6f6826c5
JS
453 done
454 if [ "$filter_parent" ]; then
8c1ce0f4
JS
455 parentstr="$(echo "$parentstr" | eval "$filter_parent")" ||
456 die "parent filter failed: $filter_parent"
6f6826c5
JS
457 fi
458
df062010 459 {
a5a4b3ff 460 while IFS='' read -r header_line && test -n "$header_line"
df062010
JK
461 do
462 # skip header lines...
463 :;
464 done
465 # and output the actual commit message
466 cat
467 } <../commit |
8c1ce0f4
JS
468 eval "$filter_msg" > ../message ||
469 die "msg filter failed: $filter_msg"
348d4f2f
JK
470
471 if test -n "$need_index"
472 then
473 tree=$(git write-tree)
474 else
1dc413eb 475 tree=$(git rev-parse "$commit^{tree}")
348d4f2f 476 fi
0906f6e1 477 workdir=$workdir @SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
348d4f2f 478 "$tree" $parentstr < ../message > ../map/$commit ||
0ea29cce 479 die "could not write rewritten commit"
6f6826c5
JS
480done <../revs
481
f2f3a6b8
TR
482# If we are filtering for paths, as in the case of a subdirectory
483# filter, it is possible that a specified head is not in the set of
484# rewritten commits, because it was pruned by the revision walker.
485# Ancestor remapping fixes this by mapping these heads to the unique
486# nearest ancestor that survived the pruning.
dfd05e38 487
f2f3a6b8 488if test "$remap_to_ancestor" = t
a0e46390
TR
489then
490 while read ref
dfd05e38 491 do
a0e46390
TR
492 sha1=$(git rev-parse "$ref"^0)
493 test -f "$workdir"/../map/$sha1 && continue
2c1d2d81 494 ancestor=$(git rev-list --simplify-merges -1 "$ref" "$@")
a0e46390
TR
495 test "$ancestor" && echo $(map $ancestor) >> "$workdir"/../map/$sha1
496 done < "$tempdir"/heads
497fi
dfd05e38
JS
498
499# Finally update the refs
500
501_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
502_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
dfd05e38
JS
503echo
504while read ref
505do
506 # avoid rewriting a ref twice
507 test -f "$orig_namespace$ref" && continue
508
509 sha1=$(git rev-parse "$ref"^0)
510 rewritten=$(map $sha1)
511
512 test $sha1 = "$rewritten" &&
513 warn "WARNING: Ref '$ref' is unchanged" &&
514 continue
515
516 case "$rewritten" in
517 '')
518 echo "Ref '$ref' was deleted"
519 git update-ref -m "filter-branch: delete" -d "$ref" $sha1 ||
520 die "Could not delete $ref"
98409060 521 ;;
dfd05e38
JS
522 $_x40)
523 echo "Ref '$ref' was rewritten"
261044e8
TR
524 if ! git update-ref -m "filter-branch: rewrite" \
525 "$ref" $rewritten $sha1 2>/dev/null; then
526 if test $(git cat-file -t "$ref") = tag; then
527 if test -z "$filter_tag_name"; then
528 warn "WARNING: You said to rewrite tagged commits, but not the corresponding tag."
529 warn "WARNING: Perhaps use '--tag-name-filter cat' to rewrite the tag."
530 fi
531 else
532 die "Could not rewrite $ref"
533 fi
534 fi
98409060 535 ;;
dfd05e38
JS
536 *)
537 # NEEDSWORK: possibly add -Werror, making this an error
538 warn "WARNING: '$ref' was rewritten into multiple commits:"
539 warn "$rewritten"
540 warn "WARNING: Ref '$ref' points to the first one now."
541 rewritten=$(echo "$rewritten" | head -n 1)
542 git update-ref -m "filter-branch: rewrite to first" \
543 "$ref" $rewritten $sha1 ||
544 die "Could not rewrite $ref"
545 ;;
546 esac
0ea29cce
EK
547 git update-ref -m "filter-branch: backup" "$orig_namespace$ref" $sha1 ||
548 exit
dfd05e38
JS
549done < "$tempdir"/heads
550
551# TODO: This should possibly go, with the semantics that all positive given
552# refs are updated, and their original heads stored in refs/original/
553# Filter tags
6f6826c5
JS
554
555if [ "$filter_tag_name" ]; then
5be60078 556 git for-each-ref --format='%(objectname) %(objecttype) %(refname)' refs/tags |
6f6826c5
JS
557 while read sha1 type ref; do
558 ref="${ref#refs/tags/}"
559 # XXX: Rewrite tagged trees as well?
560 if [ "$type" != "commit" -a "$type" != "tag" ]; then
561 continue;
562 fi
563
564 if [ "$type" = "tag" ]; then
565 # Dereference to a commit
566 sha1t="$sha1"
7bd93c1c 567 sha1="$(git rev-parse -q "$sha1"^{commit})" || continue
6f6826c5
JS
568 fi
569
570 [ -f "../map/$sha1" ] || continue
571 new_sha1="$(cat "../map/$sha1")"
3addc94a
JS
572 GIT_COMMIT="$sha1"
573 export GIT_COMMIT
8c1ce0f4
JS
574 new_ref="$(echo "$ref" | eval "$filter_tag_name")" ||
575 die "tag name filter failed: $filter_tag_name"
6f6826c5
JS
576
577 echo "$ref -> $new_ref ($sha1 -> $new_sha1)"
578
579 if [ "$type" = "tag" ]; then
a9da1663
JS
580 new_sha1=$( ( printf 'object %s\ntype commit\ntag %s\n' \
581 "$new_sha1" "$new_ref"
582 git cat-file tag "$ref" |
1bf6551e 583 sed -n \
9524cf29 584 -e '1,/^$/{
a9da1663
JS
585 /^object /d
586 /^type /d
587 /^tag /d
9524cf29 588 }' \
1bf6551e 589 -e '/^-----BEGIN PGP SIGNATURE-----/q' \
a9da1663 590 -e 'p' ) |
b2c1ca6b 591 git hash-object -t tag -w --stdin) ||
1bf6551e
BC
592 die "Could not create new tag object for $ref"
593 if git cat-file tag "$ref" | \
e1622bfc 594 sane_grep '^-----BEGIN PGP SIGNATURE-----' >/dev/null 2>&1
1bf6551e
BC
595 then
596 warn "gpg signature stripped from tag object $sha1t"
597 fi
6f6826c5
JS
598 fi
599
af580e9c
JS
600 git update-ref "refs/tags/$new_ref" "$new_sha1" ||
601 die "Could not write tag $new_ref"
6f6826c5
JS
602 done
603fi
604
9273b562 605unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE
7b1378bd
IC
606unset GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
607unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE
9273b562
EK
608test -z "$ORIG_GIT_DIR" || {
609 GIT_DIR="$ORIG_GIT_DIR" && export GIT_DIR
610}
611test -z "$ORIG_GIT_WORK_TREE" || {
612 GIT_WORK_TREE="$ORIG_GIT_WORK_TREE" &&
613 export GIT_WORK_TREE
614}
615test -z "$ORIG_GIT_INDEX_FILE" || {
616 GIT_INDEX_FILE="$ORIG_GIT_INDEX_FILE" &&
617 export GIT_INDEX_FILE
618}
7b1378bd
IC
619test -z "$ORIG_GIT_AUTHOR_NAME" || {
620 GIT_AUTHOR_NAME="$ORIG_GIT_AUTHOR_NAME" &&
621 export GIT_AUTHOR_NAME
622}
623test -z "$ORIG_GIT_AUTHOR_EMAIL" || {
624 GIT_AUTHOR_EMAIL="$ORIG_GIT_AUTHOR_EMAIL" &&
625 export GIT_AUTHOR_EMAIL
626}
627test -z "$ORIG_GIT_AUTHOR_DATE" || {
628 GIT_AUTHOR_DATE="$ORIG_GIT_AUTHOR_DATE" &&
629 export GIT_AUTHOR_DATE
630}
631test -z "$ORIG_GIT_COMMITTER_NAME" || {
632 GIT_COMMITTER_NAME="$ORIG_GIT_COMMITTER_NAME" &&
633 export GIT_COMMITTER_NAME
634}
635test -z "$ORIG_GIT_COMMITTER_EMAIL" || {
636 GIT_COMMITTER_EMAIL="$ORIG_GIT_COMMITTER_EMAIL" &&
637 export GIT_COMMITTER_EMAIL
638}
639test -z "$ORIG_GIT_COMMITTER_DATE" || {
640 GIT_COMMITTER_DATE="$ORIG_GIT_COMMITTER_DATE" &&
641 export GIT_COMMITTER_DATE
642}
9273b562 643
bd2c79fb
IC
644if test -n "$state_branch"
645then
646 echo "Saving rewrite state to $state_branch" 1>&2
647 state_blob=$(
648 perl -e'opendir D, "../map" or die;
649 open H, "|-", "git hash-object -w --stdin" or die;
650 foreach (sort readdir(D)) {
651 next if m/^\.\.?$/;
652 open F, "<../map/$_" or die;
653 chomp($f = <F>);
654 print H "$_:$f\n" or die;
655 }
656 close(H) or die;' || die "Unable to save state")
206a6ae0 657 state_tree=$(printf '100644 blob %s\tfilter.map\n' "$state_blob" | git mktree)
bd2c79fb
IC
658 if test -n "$state_commit"
659 then
206a6ae0 660 state_commit=$(echo "Sync" | git commit-tree "$state_tree" -p "$state_commit")
bd2c79fb 661 else
206a6ae0 662 state_commit=$(echo "Sync" | git commit-tree "$state_tree" )
bd2c79fb
IC
663 fi
664 git update-ref "$state_branch" "$state_commit"
665fi
666
d24813c4
IC
667cd "$orig_dir"
668rm -rf "$tempdir"
669
670trap - 0
671
a4661b01 672if [ "$(is_bare_repository)" = false ]; then
0ea29cce 673 git read-tree -u -m HEAD || exit
a4661b01 674fi
46eb449c 675
0ea29cce 676exit 0