From 09816159211b1f6d5526b32441e43b08f2b0afee Mon Sep 17 00:00:00 2001 From: Colin Guthrie Date: Wed, 12 Jun 2013 09:54:52 +0100 Subject: Attempt to resolve tags into proper annotated tags. The git-svn import stage doesn't automatically handle tags as well as it could. In order to make tags show up properly on master, we inspect each tag and try and find the first commit where it actually changes. We can then tag it via an annotated tag. Much nicer. --- scripts/mageia-reset-and-import.sh | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/mageia-reset-and-import.sh b/scripts/mageia-reset-and-import.sh index 8a301c3..e7787cc 100755 --- a/scripts/mageia-reset-and-import.sh +++ b/scripts/mageia-reset-and-import.sh @@ -321,10 +321,41 @@ git push origin master 'refs/remotes/*:refs/heads/*' pushd ../$SOFTWARE.git git branch -D trunk git branch -D origin/master + +# Tagging logic inspired by https://github.com/nothingmuch/git-svn-abandon/blob/master/git-svn-abandon-fix-refs git for-each-ref --format='%(refname)' refs/heads/tags | cut -d / -f 4 | \ - while read ref; do - git tag "$ref" "refs/heads/tags/$ref" - git branch -D "tags/$ref" + while read tag; do + ref="refs/heads/tags/$tag" + refsha1=$(git rev-parse "$ref":) + + # Find the oldest ancestor for which the tree is the same + parentref="$ref" + while [ $(git rev-parse --quiet --verify "$parentref"^:) = "$refsha1" ]; do + parentref="$parentref"^ + done + parent=$(git rev-parse "$parentref") + + # If this ancestor is in master then we can just tag it + # otherwise the tag has diverged from master and it's actually more like a + # branch than a tag + merge=$(git merge-base master $parent) + if [ "$merge" = "$parent" ]; then + targetref=$parent + else + targetref="$ref" + fi + + # create an annotated tag based on the last commit in the tag, and delete the "branchy" ref for the tag + git show -s --pretty='format:%s%n%n%b' "$ref" | \ + env GIT_COMMITTER_NAME="$(git show -s --pretty='format:%an' "$ref")" \ + GIT_COMMITTER_EMAIL="$(git show -s --pretty='format:%ae' "$ref")" \ + GIT_COMMITTER_DATE="$(git show -s --pretty='format:%ad' "$ref")" \ + GIT_AUTHOR_NAME="$(git show -s --pretty='format:%an' "$ref")" \ + GIT_AUTHOR_EMAIL="$(git show -s --pretty='format:%ae' "$ref")" \ + GIT_AUTHOR_DATE="$(git show -s --pretty='format:%ad' "$ref")" \ + git tag -a -F - "$tag" "$targetref" + + git update-ref -d "$ref" done git gc --aggressive -- cgit v1.2.1