Migrating from Subversion to git

06 Feb 2015 . tech . Comments

#git #subversion

Scholars’ Lab not only writes software and mentors graduate students, it also manages a lot of software projects that have been going on at the University of Virginia since the 90s. One of the things you need to do every so often is shift platforms that you use in your infrastructure.

When I arrived at the Scholars’ Lab six years ago, one of the big projects that was underway was dealing with all of the text that had accumulated various servers. To help get a handle on the projects, lots of people started using source control management software to start keeping track of changes (and recover more quickly if files were accidently deleted). At the time, Subversion was the best option, so a big push was made to convert all of these projects in to Subversion repositories.

While Subversion is really great in a lot of ways, it did have some issues that often made working with the tool quite painful. It was even worse for people who did not use the tool every day and could often get in to situations where a project would languish for months for an obscure issue with a SVN client or server.

As software development shifted to using git (which I attribute mainly to the rise in the utility of GitHub), Scholars’ Lab staff pretty much started using git exclusively.

Migrating the Repo

The first step in this migration was to grab a list of authors who had worked on the project since git and svn have different methods of mapping author attribution.

$ cd path/to/svn_repo
$ svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors.txt

Next, you need to edit the authors.txt file a bit to expand the username mappings. In the file, you’ll see username = username <username>. You just need to use the person’s real name and email address.

wsg4w = Wayne Graham <wsg4w@uva.edu>

Clone the Repo

This is where things got interesting. The git svn tool is generally where I go to do this thing, but the repository I’m dealing with is really big, and has a non-standard layout. The first thing I tried was this:

$ mkdir ~/temp
$ cd path/to/svn_repo
$ git svn clone https://subversion.lib.virginia.edu/repos/salem --username wsg4w --no-metadata -A authors.txt --stdlayout ~/temp

However, this failed after the server threw a 500 error. Ok, so rethink this. I can create a local sync of the SVN repo which should allow me to recover from a server failure.

$ mkdir -p /tmp/salem
$ svnadmin create /tmp/salem/
$ echo "exit 0;" > /tmp/test-svn/hooks/pre-revprop-change
$ chmod +x /tmp/salem/hooks/pre-revprop-change
$ svnsync init file:///tmp/salem https://subversion.lib.virginia.edu/repos/salem
$ svnsync sync file:///tmp/salem