Engineer in Tokyo

Importing an svn repository into mercurial

Recently I’ve been forking svn repositories by converting them to mercurial repositories and uploading them to bitbucket. It’s fairly easy with the mercurial convert extension. Convert is distributed with mercurial so if you have a recent version all you should have to do is put the following in your hgrc.

[extensions]
hgext.convert=

Converting a repository over http by running convert using the repository url can be very slow so it’s generally much faster to sync the svn repository locally and then convert it to hg. First you need to use svnsync to copy the repository.

$ svnadmin create foomirror
$ echo '#!/bin/sh' > foomirror/hooks/pre-revprop-change   # make insecure dummy hook
$ chmod +x foomirror/hooks/pre-revprop-change
$ svnsync init --username svnsync file://`pwd`/foomirror https://foo.svn.sourceforge.net/svnroot/foo
Copied properties for revision 0.
$ svnsync sync file://`pwd`/foomirror
Committed revision 1.
Copied properties for revision 1.
Committed revision 2.
Copied properties for revision 2.
...

Once the mirror is set up you can run hg convert on the local mirror. This turns out to be much faster than trying to convert the svn repository remotely.

$ hg convert foomirror   # convert directly from repo mirror to foomirror-hg
...