Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 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 | # |
Johannes Schindelin | c401b33 | 2007-07-04 00:41:55 +0100 | [diff] [blame] | 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. |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 10 | |
Brian Gernhardt | 5876b8e | 2007-08-17 19:13:04 -0400 | [diff] [blame] | 11 | USAGE="git-filter-branch [-d TEMPDIR] [FILTERS] [REV-RANGE]" |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 12 | . git-sh-setup |
| 13 | |
Steffen Prohaska | b5669a0 | 2007-07-04 10:36:24 +0200 | [diff] [blame] | 14 | warn () { |
| 15 | echo "$*" >&2 |
| 16 | } |
| 17 | |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 18 | map() |
| 19 | { |
Johannes Sixt | 3520e1e | 2007-06-06 20:38:35 +0200 | [diff] [blame] | 20 | # if it was not rewritten, take the original |
Johannes Sixt | c57a349 | 2007-07-04 14:08:17 +0200 | [diff] [blame] | 21 | if test -r "$workdir/../map/$1" |
| 22 | then |
| 23 | cat "$workdir/../map/$1" |
| 24 | else |
| 25 | echo "$1" |
| 26 | fi |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 27 | } |
| 28 | |
Johannes Schindelin | 8c1ce0f | 2007-07-04 15:36:01 +0100 | [diff] [blame] | 29 | # override die(): this version puts in an extra line break, so that |
| 30 | # the progress is still visible |
| 31 | |
| 32 | die() |
| 33 | { |
| 34 | echo >&2 |
| 35 | echo "$*" >&2 |
| 36 | exit 1 |
| 37 | } |
| 38 | |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 39 | # When piped a commit, output a script to set the ident of either |
| 40 | # "author" or "committer |
| 41 | |
| 42 | set_ident () { |
| 43 | lid="$(echo "$1" | tr "A-Z" "a-z")" |
| 44 | uid="$(echo "$1" | tr "a-z" "A-Z")" |
| 45 | pick_id_script=' |
| 46 | /^'$lid' /{ |
| 47 | s/'\''/'\''\\'\'\''/g |
| 48 | h |
| 49 | s/^'$lid' \([^<]*\) <[^>]*> .*$/\1/ |
| 50 | s/'\''/'\''\'\'\''/g |
| 51 | s/.*/export GIT_'$uid'_NAME='\''&'\''/p |
| 52 | |
| 53 | g |
| 54 | s/^'$lid' [^<]* <\([^>]*\)> .*$/\1/ |
| 55 | s/'\''/'\''\'\'\''/g |
| 56 | s/.*/export GIT_'$uid'_EMAIL='\''&'\''/p |
| 57 | |
| 58 | g |
| 59 | s/^'$lid' [^<]* <[^>]*> \(.*\)$/\1/ |
| 60 | s/'\''/'\''\'\'\''/g |
| 61 | s/.*/export GIT_'$uid'_DATE='\''&'\''/p |
| 62 | |
| 63 | q |
| 64 | } |
| 65 | ' |
| 66 | |
| 67 | LANG=C LC_ALL=C sed -ne "$pick_id_script" |
| 68 | # Ensure non-empty id name. |
| 69 | echo "[ -n \"\$GIT_${uid}_NAME\" ] || export GIT_${uid}_NAME=\"\${GIT_${uid}_EMAIL%%@*}\"" |
| 70 | } |
| 71 | |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 72 | tempdir=.git-rewrite |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 73 | filter_env= |
| 74 | filter_tree= |
| 75 | filter_index= |
| 76 | filter_parent= |
| 77 | filter_msg=cat |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 78 | filter_commit='git commit-tree "$@"' |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 79 | filter_tag_name= |
Johannes Schindelin | 685ef54 | 2007-06-08 01:30:35 +0100 | [diff] [blame] | 80 | filter_subdir= |
Johannes Schindelin | dfd05e3 | 2007-07-23 18:34:13 +0100 | [diff] [blame] | 81 | orig_namespace=refs/original/ |
| 82 | force= |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 83 | while case "$#" in 0) usage;; esac |
| 84 | do |
| 85 | case "$1" in |
| 86 | --) |
| 87 | shift |
| 88 | break |
| 89 | ;; |
Johannes Schindelin | dfd05e3 | 2007-07-23 18:34:13 +0100 | [diff] [blame] | 90 | --force|-f) |
| 91 | shift |
| 92 | force=t |
| 93 | continue |
| 94 | ;; |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 95 | -*) |
| 96 | ;; |
| 97 | *) |
| 98 | break; |
| 99 | esac |
| 100 | |
| 101 | # all switches take one argument |
| 102 | ARG="$1" |
| 103 | case "$#" in 1) usage ;; esac |
| 104 | shift |
| 105 | OPTARG="$1" |
| 106 | shift |
| 107 | |
| 108 | case "$ARG" in |
| 109 | -d) |
| 110 | tempdir="$OPTARG" |
| 111 | ;; |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 112 | --env-filter) |
| 113 | filter_env="$OPTARG" |
| 114 | ;; |
| 115 | --tree-filter) |
| 116 | filter_tree="$OPTARG" |
| 117 | ;; |
| 118 | --index-filter) |
| 119 | filter_index="$OPTARG" |
| 120 | ;; |
| 121 | --parent-filter) |
| 122 | filter_parent="$OPTARG" |
| 123 | ;; |
| 124 | --msg-filter) |
| 125 | filter_msg="$OPTARG" |
| 126 | ;; |
| 127 | --commit-filter) |
| 128 | filter_commit="$OPTARG" |
| 129 | ;; |
| 130 | --tag-name-filter) |
| 131 | filter_tag_name="$OPTARG" |
| 132 | ;; |
Johannes Schindelin | 685ef54 | 2007-06-08 01:30:35 +0100 | [diff] [blame] | 133 | --subdirectory-filter) |
| 134 | filter_subdir="$OPTARG" |
| 135 | ;; |
Johannes Schindelin | dfd05e3 | 2007-07-23 18:34:13 +0100 | [diff] [blame] | 136 | --original) |
| 137 | orig_namespace="$OPTARG" |
| 138 | ;; |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 139 | *) |
| 140 | usage |
| 141 | ;; |
| 142 | esac |
| 143 | done |
| 144 | |
Johannes Schindelin | dfd05e3 | 2007-07-23 18:34:13 +0100 | [diff] [blame] | 145 | case "$force" in |
| 146 | t) |
| 147 | rm -rf "$tempdir" |
| 148 | ;; |
| 149 | '') |
| 150 | test -d "$tempdir" && |
| 151 | die "$tempdir already exists, please remove it" |
| 152 | esac |
Johannes Schindelin | af580e9 | 2007-07-18 14:17:43 +0100 | [diff] [blame] | 153 | mkdir -p "$tempdir/t" && |
Johannes Schindelin | dfd05e3 | 2007-07-23 18:34:13 +0100 | [diff] [blame] | 154 | tempdir="$(cd "$tempdir"; pwd)" && |
Johannes Schindelin | af580e9 | 2007-07-18 14:17:43 +0100 | [diff] [blame] | 155 | cd "$tempdir/t" && |
| 156 | workdir="$(pwd)" || |
| 157 | die "" |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 158 | |
Johannes Schindelin | dfd05e3 | 2007-07-23 18:34:13 +0100 | [diff] [blame] | 159 | # Make sure refs/original is empty |
| 160 | git for-each-ref > "$tempdir"/backup-refs |
| 161 | while read sha1 type name |
| 162 | do |
| 163 | case "$force,$name" in |
| 164 | ,$orig_namespace*) |
| 165 | die "Namespace $orig_namespace not empty" |
| 166 | ;; |
| 167 | t,$orig_namespace*) |
| 168 | git update-ref -d "$name" $sha1 |
| 169 | ;; |
| 170 | esac |
| 171 | done < "$tempdir"/backup-refs |
| 172 | |
Matthias Lederhofer | 9489d0f | 2007-06-06 09:16:56 +0200 | [diff] [blame] | 173 | export GIT_DIR GIT_WORK_TREE=. |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 174 | |
Johannes Schindelin | dfd05e3 | 2007-07-23 18:34:13 +0100 | [diff] [blame] | 175 | # These refs should be updated if their heads were rewritten |
| 176 | |
| 177 | git rev-parse --revs-only --symbolic "$@" | |
| 178 | while read ref |
| 179 | do |
| 180 | # normalize ref |
| 181 | case "$ref" in |
| 182 | HEAD) |
| 183 | ref="$(git symbolic-ref "$ref")" |
| 184 | ;; |
| 185 | refs/*) |
| 186 | ;; |
| 187 | *) |
| 188 | ref="$(git for-each-ref --format='%(refname)' | |
| 189 | grep /"$ref")" |
| 190 | esac |
| 191 | |
| 192 | git check-ref-format "$ref" && echo "$ref" |
| 193 | done > "$tempdir"/heads |
| 194 | |
| 195 | test -s "$tempdir"/heads || |
| 196 | die "Which ref do you want to rewrite?" |
| 197 | |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 198 | export GIT_INDEX_FILE="$(pwd)/../index" |
Johannes Schindelin | af580e9 | 2007-07-18 14:17:43 +0100 | [diff] [blame] | 199 | git read-tree || die "Could not seed the index" |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 200 | |
| 201 | ret=0 |
| 202 | |
Johannes Schindelin | af580e9 | 2007-07-18 14:17:43 +0100 | [diff] [blame] | 203 | # map old->new commit ids for rewriting parents |
| 204 | mkdir ../map || die "Could not create map/ directory" |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 205 | |
Johannes Schindelin | 685ef54 | 2007-06-08 01:30:35 +0100 | [diff] [blame] | 206 | case "$filter_subdir" in |
| 207 | "") |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 208 | git rev-list --reverse --topo-order --default HEAD \ |
Johannes Sixt | 813b473 | 2007-06-08 23:28:39 +0200 | [diff] [blame] | 209 | --parents "$@" |
Johannes Schindelin | 685ef54 | 2007-06-08 01:30:35 +0100 | [diff] [blame] | 210 | ;; |
| 211 | *) |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 212 | git rev-list --reverse --topo-order --default HEAD \ |
Johannes Sixt | cfabd6e | 2007-06-08 23:28:50 +0200 | [diff] [blame] | 213 | --parents --full-history "$@" -- "$filter_subdir" |
Johannes Schindelin | af580e9 | 2007-07-18 14:17:43 +0100 | [diff] [blame] | 214 | esac > ../revs || die "Could not get the commits" |
Josh Triplett | 9d6f220 | 2007-07-14 01:05:43 -0700 | [diff] [blame] | 215 | commits=$(wc -l <../revs | tr -d " ") |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 216 | |
| 217 | test $commits -eq 0 && die "Found nothing to rewrite" |
| 218 | |
Johannes Schindelin | dfd05e3 | 2007-07-23 18:34:13 +0100 | [diff] [blame] | 219 | # Rewrite the commits |
| 220 | |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 221 | i=0 |
Johannes Sixt | 813b473 | 2007-06-08 23:28:39 +0200 | [diff] [blame] | 222 | while read commit parents; do |
Johannes Schindelin | c12764b | 2007-06-06 16:24:07 +0100 | [diff] [blame] | 223 | i=$(($i+1)) |
Johannes Schindelin | 5efb48b | 2007-07-04 15:33:30 +0100 | [diff] [blame] | 224 | printf "\rRewrite $commit ($i/$commits)" |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 225 | |
Johannes Schindelin | 685ef54 | 2007-06-08 01:30:35 +0100 | [diff] [blame] | 226 | case "$filter_subdir" in |
| 227 | "") |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 228 | git read-tree -i -m $commit |
Johannes Schindelin | 685ef54 | 2007-06-08 01:30:35 +0100 | [diff] [blame] | 229 | ;; |
| 230 | *) |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 231 | git read-tree -i -m $commit:"$filter_subdir" |
Johannes Schindelin | af580e9 | 2007-07-18 14:17:43 +0100 | [diff] [blame] | 232 | esac || die "Could not initialize the index" |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 233 | |
| 234 | export GIT_COMMIT=$commit |
Johannes Schindelin | af580e9 | 2007-07-18 14:17:43 +0100 | [diff] [blame] | 235 | git cat-file commit "$commit" >../commit || |
| 236 | die "Cannot read commit $commit" |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 237 | |
Johannes Schindelin | 8c1ce0f | 2007-07-04 15:36:01 +0100 | [diff] [blame] | 238 | eval "$(set_ident AUTHOR <../commit)" || |
| 239 | die "setting author failed for commit $commit" |
| 240 | eval "$(set_ident COMMITTER <../commit)" || |
| 241 | die "setting committer failed for commit $commit" |
| 242 | eval "$filter_env" < /dev/null || |
| 243 | die "env filter failed: $filter_env" |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 244 | |
| 245 | if [ "$filter_tree" ]; then |
Johannes Schindelin | af580e9 | 2007-07-18 14:17:43 +0100 | [diff] [blame] | 246 | git checkout-index -f -u -a || |
| 247 | die "Could not checkout the index" |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 248 | # files that $commit removed are now still in the working tree; |
| 249 | # remove them, else they would be added again |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 250 | git ls-files -z --others | xargs -0 rm -f |
Johannes Schindelin | 8c1ce0f | 2007-07-04 15:36:01 +0100 | [diff] [blame] | 251 | eval "$filter_tree" < /dev/null || |
| 252 | die "tree filter failed: $filter_tree" |
| 253 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 254 | git diff-index -r $commit | cut -f 2- | tr '\n' '\0' | \ |
| 255 | xargs -0 git update-index --add --replace --remove |
| 256 | git ls-files -z --others | \ |
| 257 | xargs -0 git update-index --add --replace --remove |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 258 | fi |
| 259 | |
Johannes Schindelin | 8c1ce0f | 2007-07-04 15:36:01 +0100 | [diff] [blame] | 260 | eval "$filter_index" < /dev/null || |
| 261 | die "index filter failed: $filter_index" |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 262 | |
| 263 | parentstr= |
Johannes Sixt | 813b473 | 2007-06-08 23:28:39 +0200 | [diff] [blame] | 264 | for parent in $parents; do |
Johannes Sixt | 3520e1e | 2007-06-06 20:38:35 +0200 | [diff] [blame] | 265 | for reparent in $(map "$parent"); do |
| 266 | parentstr="$parentstr -p $reparent" |
| 267 | done |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 268 | done |
| 269 | if [ "$filter_parent" ]; then |
Johannes Schindelin | 8c1ce0f | 2007-07-04 15:36:01 +0100 | [diff] [blame] | 270 | parentstr="$(echo "$parentstr" | eval "$filter_parent")" || |
| 271 | die "parent filter failed: $filter_parent" |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 272 | fi |
| 273 | |
| 274 | sed -e '1,/^$/d' <../commit | \ |
Johannes Schindelin | 8c1ce0f | 2007-07-04 15:36:01 +0100 | [diff] [blame] | 275 | eval "$filter_msg" > ../message || |
| 276 | die "msg filter failed: $filter_msg" |
| 277 | sh -c "$filter_commit" "git commit-tree" \ |
| 278 | $(git write-tree) $parentstr < ../message > ../map/$commit |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 279 | done <../revs |
| 280 | |
Johannes Schindelin | dfd05e3 | 2007-07-23 18:34:13 +0100 | [diff] [blame] | 281 | # In case of a subdirectory filter, it is possible that a specified head |
| 282 | # is not in the set of rewritten commits, because it was pruned by the |
| 283 | # revision walker. Fix it by mapping these heads to the next rewritten |
| 284 | # ancestor(s), i.e. the boundaries in the set of rewritten commits. |
| 285 | |
| 286 | # NEEDSWORK: we should sort the unmapped refs topologically first |
| 287 | while read ref |
| 288 | do |
| 289 | sha1=$(git rev-parse "$ref"^0) |
| 290 | test -f "$workdir"/../map/$sha1 && continue |
| 291 | # Assign the boundarie(s) in the set of rewritten commits |
| 292 | # as the replacement commit(s). |
| 293 | # (This would look a bit nicer if --not --stdin worked.) |
René Scharfe | 24d0063 | 2007-07-24 23:29:29 +0200 | [diff] [blame] | 294 | for p in $( (cd "$workdir"/../map; ls | sed "s/^/^/") | |
Johannes Schindelin | dfd05e3 | 2007-07-23 18:34:13 +0100 | [diff] [blame] | 295 | git rev-list $ref --boundary --stdin | |
| 296 | sed -n "s/^-//p") |
| 297 | do |
| 298 | map $p >> "$workdir"/../map/$sha1 |
| 299 | done |
| 300 | done < "$tempdir"/heads |
| 301 | |
| 302 | # Finally update the refs |
| 303 | |
| 304 | _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' |
| 305 | _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40" |
| 306 | count=0 |
| 307 | echo |
| 308 | while read ref |
| 309 | do |
| 310 | # avoid rewriting a ref twice |
| 311 | test -f "$orig_namespace$ref" && continue |
| 312 | |
| 313 | sha1=$(git rev-parse "$ref"^0) |
| 314 | rewritten=$(map $sha1) |
| 315 | |
| 316 | test $sha1 = "$rewritten" && |
| 317 | warn "WARNING: Ref '$ref' is unchanged" && |
| 318 | continue |
| 319 | |
| 320 | case "$rewritten" in |
| 321 | '') |
| 322 | echo "Ref '$ref' was deleted" |
| 323 | git update-ref -m "filter-branch: delete" -d "$ref" $sha1 || |
| 324 | die "Could not delete $ref" |
Johannes Schindelin | 9840906 | 2007-06-05 16:58:13 +0100 | [diff] [blame] | 325 | ;; |
Johannes Schindelin | dfd05e3 | 2007-07-23 18:34:13 +0100 | [diff] [blame] | 326 | $_x40) |
| 327 | echo "Ref '$ref' was rewritten" |
| 328 | git update-ref -m "filter-branch: rewrite" \ |
| 329 | "$ref" $rewritten $sha1 || |
| 330 | die "Could not rewrite $ref" |
Johannes Schindelin | 9840906 | 2007-06-05 16:58:13 +0100 | [diff] [blame] | 331 | ;; |
Johannes Schindelin | dfd05e3 | 2007-07-23 18:34:13 +0100 | [diff] [blame] | 332 | *) |
| 333 | # NEEDSWORK: possibly add -Werror, making this an error |
| 334 | warn "WARNING: '$ref' was rewritten into multiple commits:" |
| 335 | warn "$rewritten" |
| 336 | warn "WARNING: Ref '$ref' points to the first one now." |
| 337 | rewritten=$(echo "$rewritten" | head -n 1) |
| 338 | git update-ref -m "filter-branch: rewrite to first" \ |
| 339 | "$ref" $rewritten $sha1 || |
| 340 | die "Could not rewrite $ref" |
| 341 | ;; |
| 342 | esac |
| 343 | git update-ref -m "filter-branch: backup" "$orig_namespace$ref" $sha1 |
| 344 | count=$(($count+1)) |
| 345 | done < "$tempdir"/heads |
| 346 | |
| 347 | # TODO: This should possibly go, with the semantics that all positive given |
| 348 | # refs are updated, and their original heads stored in refs/original/ |
| 349 | # Filter tags |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 350 | |
| 351 | if [ "$filter_tag_name" ]; then |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 352 | git for-each-ref --format='%(objectname) %(objecttype) %(refname)' refs/tags | |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 353 | while read sha1 type ref; do |
| 354 | ref="${ref#refs/tags/}" |
| 355 | # XXX: Rewrite tagged trees as well? |
| 356 | if [ "$type" != "commit" -a "$type" != "tag" ]; then |
| 357 | continue; |
| 358 | fi |
| 359 | |
| 360 | if [ "$type" = "tag" ]; then |
| 361 | # Dereference to a commit |
| 362 | sha1t="$sha1" |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 363 | sha1="$(git rev-parse "$sha1"^{commit} 2>/dev/null)" || continue |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 364 | fi |
| 365 | |
| 366 | [ -f "../map/$sha1" ] || continue |
| 367 | new_sha1="$(cat "../map/$sha1")" |
| 368 | export GIT_COMMIT="$sha1" |
Johannes Schindelin | 8c1ce0f | 2007-07-04 15:36:01 +0100 | [diff] [blame] | 369 | new_ref="$(echo "$ref" | eval "$filter_tag_name")" || |
| 370 | die "tag name filter failed: $filter_tag_name" |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 371 | |
| 372 | echo "$ref -> $new_ref ($sha1 -> $new_sha1)" |
| 373 | |
| 374 | if [ "$type" = "tag" ]; then |
| 375 | # Warn that we are not rewriting the tag object itself. |
| 376 | warn "unreferencing tag object $sha1t" |
| 377 | fi |
| 378 | |
Johannes Schindelin | af580e9 | 2007-07-18 14:17:43 +0100 | [diff] [blame] | 379 | git update-ref "refs/tags/$new_ref" "$new_sha1" || |
| 380 | die "Could not write tag $new_ref" |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 381 | done |
| 382 | fi |
| 383 | |
| 384 | cd ../.. |
| 385 | rm -rf "$tempdir" |
Johannes Schindelin | dfd05e3 | 2007-07-23 18:34:13 +0100 | [diff] [blame] | 386 | echo |
| 387 | test $count -gt 0 && echo "These refs were rewritten:" |
| 388 | git show-ref | grep ^"$orig_namespace" |
Johannes Schindelin | 6f6826c | 2007-06-03 01:31:28 +0100 | [diff] [blame] | 389 | |
| 390 | exit $ret |