From 963dfbb0538a21f0e834dac3395a2c89fd246a89 Mon Sep 17 00:00:00 2001 From: Patryk Obara Date: Sun, 15 Sep 2019 00:12:44 +0200 Subject: [PATCH] Add initial version of import script The script creates new Git repository with complete SVN history of DOSBox project, using correct authorship information and importing tags as real Git tags. --- scripts/import-from-svn/.gitignore | 1 + scripts/import-from-svn/copied-from.xslt | 11 ++ scripts/import-from-svn/import-from-svn.sh | 122 +++++++++++++++++++++ scripts/import-from-svn/svn-dosbox-authors | 9 ++ 4 files changed, 143 insertions(+) create mode 100644 scripts/import-from-svn/.gitignore create mode 100644 scripts/import-from-svn/copied-from.xslt create mode 100755 scripts/import-from-svn/import-from-svn.sh create mode 100644 scripts/import-from-svn/svn-dosbox-authors diff --git a/scripts/import-from-svn/.gitignore b/scripts/import-from-svn/.gitignore new file mode 100644 index 00000000..9d9c5001 --- /dev/null +++ b/scripts/import-from-svn/.gitignore @@ -0,0 +1 @@ +dosbox-git-svn-* diff --git a/scripts/import-from-svn/copied-from.xslt b/scripts/import-from-svn/copied-from.xslt new file mode 100644 index 00000000..407727ab --- /dev/null +++ b/scripts/import-from-svn/copied-from.xslt @@ -0,0 +1,11 @@ + + + + + +@ + + diff --git a/scripts/import-from-svn/import-from-svn.sh b/scripts/import-from-svn/import-from-svn.sh new file mode 100755 index 00000000..0e1448a9 --- /dev/null +++ b/scripts/import-from-svn/import-from-svn.sh @@ -0,0 +1,122 @@ +#!/bin/bash + +readonly svn_url=https://svn.code.sf.net/p/dosbox/code-0/dosbox + +echo_err () { + echo "$@" 1>&2 +} + +# SVN repository revision. By comparing repo revision we can detect if there +# was any activity on any svn path. +# +svn_get_repo_revision () { + svn info "$svn_url" | grep "Revision:" | cut -d' ' -f2 +} + +# Example usage: +# +# svn_get_copied_from branches/0_74_3 +# +svn_get_copied_from () { + local -r repo_path=$1 + svn log -v --stop-on-copy --xml "$svn_url/$repo_path" \ + | xsltproc copied-from.xslt - +} + +# Full import takes ~40 minutes +# +git_svn_clone_dosbox () { + local -r repo_name=$1 + + git svn init \ + --stdlayout \ + "$svn_url" \ + "$repo_name" + + local -r authors_file=$PWD/svn-dosbox-authors + git -C "$repo_name" svn fetch \ + --authors-file="$authors_file" +} + +# Remove UUID of SVN server to avoid issues in case SourceForge will change +# it's infrastructure. +# +git_rewrite_import_links () { + local -r repo_name=$1 + git -C "$repo_name" filter-branch \ + --msg-filter 'sed "s|git-svn-id: \([^ ]*\) .*|Imported-from: \1|"' \ + -- --all +} + +list_svn_branch_paths () { + echo trunk + for branch in $(svn ls "$svn_url/branches") ; do + echo "${branch///}" + done +} + +list_svn_tag_paths () { + for branch in $(svn ls "$svn_url/tags") ; do + echo "${branch///}" + done +} + +# Go through SVN "branches", that were not removed from SVN yet and create +# Git branches out of them using name prefix "svn/" in local repository. +# +name_active_branches () { + local -r repo_name=$1 + for path in $(list_svn_branch_paths) ; do + git -C "$repo_name" branch "svn/$path" "origin/$path" + done +} + +find_tagged_git_commit () { + git -C "$1" log \ + --grep="$svn_copied_path" \ + --branches=svn/* \ + --format=%H +} + +# Import SVN "tags" as proper Git tags +# +# Hopefully upstream never committed to tags… +# +import_svn_tagpaths_as_git_tags () { + local -r repo_name=$1 + local svn_copied_path + local svn_tagged_commit + for path in $(list_svn_tag_paths) ; do + svn_copied_path=$(svn_get_copied_from "tags/$path") + svn_tagged_commit=$(find_tagged_git_commit "$repo_name") + git_tag_name="svn/$path" + echo "$path: $svn_copied_path -> $svn_tagged_commit -> $git_tag_name" + git -C "$repo_name" tag \ + "$git_tag_name" \ + "$svn_tagged_commit" + done +} + +# Remove any unnecessary refs left behind in imported repo +# +cleanup () { + git -C "$1" checkout svn/trunk + git -C "$1" branch -D master +} + +# main +# +main () { + readonly repo=dosbox-git-svn-$(svn_get_repo_revision) + if [ -e "$repo" ] ; then + echo_err "Repository '$repo' exists already." + exit 1 + fi + git_svn_clone_dosbox "$repo" + git_rewrite_import_links "$repo" + name_active_branches "$repo" + import_svn_tagpaths_as_git_tags "$repo" + cleanup "$repo" +} + +main "$@" diff --git a/scripts/import-from-svn/svn-dosbox-authors b/scripts/import-from-svn/svn-dosbox-authors new file mode 100644 index 00000000..a7cb6486 --- /dev/null +++ b/scripts/import-from-svn/svn-dosbox-authors @@ -0,0 +1,9 @@ +qbix79 = Peter Veenstra +harekiet = Sjoerd van der Berg +finsterr = Ulf Wohlers +canadacow = Dean Beeler +yot = Felix Jakschitsch +c2woody = Sebastian Strohhäcker +h-a-l-9000 = Ralf Grillenberger +ripsaw8080 = ripsaw8080 +uid83799 = uid83799