From 5f8ff77b3ecd8af56fccbe30de00d7ca67306d97 Mon Sep 17 00:00:00 2001 From: Colin Guthrie Date: Thu, 13 Jun 2013 00:02:01 +0100 Subject: Create an SQL file of revisions to sha1s. This database will be used to provide redirection in weblinks etc. Note: I had to abandon the while look with git-foreach-ref as it meant the global variable was out of scope due to piping. --- scripts/mageia-reset-and-import.sh | 90 +++++++++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 5 deletions(-) diff --git a/scripts/mageia-reset-and-import.sh b/scripts/mageia-reset-and-import.sh index ce03394..d2d8d9d 100755 --- a/scripts/mageia-reset-and-import.sh +++ b/scripts/mageia-reset-and-import.sh @@ -64,6 +64,7 @@ git config svn-remote.svn.url $NEWSVNURL echo "done" echo -n "Updating Internal SVN metadata... " +OLDSVNUUID=$(grep "uuid = " .git/svn/.metadata | cut -d= -f2 | trim) sed -i "s,reposRoot = .*$,reposRoot = $NEWSVNURL,;s,uuid = .*$,uuid = $NEWSVNUUID," .git/svn/.metadata echo "done" @@ -120,6 +121,9 @@ else if [ $reftimestamp -gt $resettimestamp ]; then echo " Removing '$ref'" git update-ref -d $ref + + # Also trash the old revmap + rm -f .git/svn/$ref/.rev_map.* fi done echo "... done" @@ -244,7 +248,8 @@ Synthesized commit during git-svn import combining previous Mandriva history wit This commit consitsts of the following subversion commits: EOF -svn log -r 1:$revision $NEWSVNURL/$SOFTWARE >>$COMMITTXT +svn log -r 1:$revision $NEWSVNURL/$SOFTWARE/trunk >>$COMMITTXT +squashedrevs=$(svn log -r 1:$revision $NEWSVNURL/$SOFTWARE/trunk | grep -E "^r[0-9]+ \| " | cut -d' ' -f1 | xargs | sed 's/r//g') if [ -n "$morerevisions" ]; then for rev in $morerevisions; do @@ -323,9 +328,12 @@ git branch -D trunk git branch -D origin/master 2>/dev/null # 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 tag; do +# Keep a map of tags and their original sha1 for the SQL database cerated below +declare -A tagmap +tags=$(git for-each-ref --format='%(refname)' refs/heads/tags | cut -d / -f 4) +for tag in $tags; do ref="refs/heads/tags/$tag" + refsha1=$(git rev-parse "$ref") reftreesha1=$(git rev-parse "$ref":) # Find the oldest ancestor for which the tree is the same @@ -342,9 +350,11 @@ git for-each-ref --format='%(refname)' refs/heads/tags | cut -d / -f 4 | \ if [ "$merge" = "$parent" ]; then targetref=$parent else - targetref="$ref" + targetref=$refsha1 fi + tagmap[$refsha1]=$tag + # 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")" \ @@ -356,7 +366,77 @@ git for-each-ref --format='%(refname)' refs/heads/tags | cut -d / -f 4 | \ git tag -a -F - "$tag" "$targetref" git update-ref -d "$ref" - done +done git gc --aggressive popd + + +# And finally we create some SQL for creating a nice revision map database + +# CREATE TABLE refs (distro char(3) NOT NULL, soft varchar(255) NOT NULL, revision int(10) unsigned NOT NULL, sha1 char(40) NOT NULL, head varchar(255) NOT NULL); + +parsesvnrevmap() +{ + if [ ! -f "$1" ]; then + echo "No such file '$1'" >&2 + exit 1 + fi + for map in $(cat "$1" | xxd -c24 -g24 | cut -b 10-57); do + sha1=$(echo $map | cut -b 9-) + if [ "$sha1" = "0000000000000000000000000000000000000000" ]; then + continue + fi + if [ -n "$4" -a "$2" = "mga" -a "$sha1" = "$4" ]; then + continue + fi + rev=$(printf "%d" 0x$(echo $map | cut -b 1-8)) + + if [ -n "${tagmap[$sha1]}" ]; then + echo "INSERT INTO refs VALUES('$2', '$SOFTWARE', $rev, '', '${tagmap[$sha1]}');" + else + echo "INSERT INTO refs VALUES('$2', '$SOFTWARE', $rev, '$sha1', '$3');" + fi + + # Exit if we've reached our reset sha1 as any future revisions are not used + # by Mageia + if [ -n "$4" -a "$2" = "mdv" -a "$sha1" = "$4" ]; then + break + fi + done +} + +echo -n "Creating revision -> sha1 map SQL... " + +sql="../$SOFTWARE-revmap.sql" +rm -f "$sql" + +# First to the old (i.e. mdv) ones +revmap=".git/svn/refs/remotes/trunk/.rev_map.$OLDSVNUUID" +if [ -f "$revmap" ]; then + parsesvnrevmap "$revmap" "mdv" "" $resetsha1 >>"$sql" +fi +for revmap in $(find .git/svn/refs/remotes/{tags,branches} -name .rev_map.$OLDSVNUUID 2>/dev/null); do + parsesvnrevmap "$revmap" "mdv" "$(echo $revmap | cut -d'/' -f6)" >>"$sql" +done + +# Inject the squashed commits into the map +for rev in $squashedrevs $morerevisions; do + echo "INSERT INTO refs VALUES('mga', '$SOFTWARE', $rev, '$fakesha1', '');" >>"$sql" +done +if [ -n "$skiprevisions" ]; then + for rev in $skiprevisions; do + echo "INSERT INTO refs VALUES('mga', '$SOFTWARE', $rev, '', '');" >>"$sql" + done +fi + +# And the rest of the Mageia commits +revmap=".git/svn/refs/remotes/trunk/.rev_map.$NEWSVNUUID" +if [ -f "$revmap" ]; then + parsesvnrevmap "$revmap" "mga" "" $fakesha1 >>"$sql" +fi +for revmap in $(find .git/svn/refs/remotes/{tags,branches} -name .rev_map.$NEWSVNUUID 2>/dev/null); do + parsesvnrevmap "$revmap" "mga" "$(echo $revmap | cut -d'/' -f6)" >>"$sql" +done + +echo "done" -- cgit v1.2.1