How to move from remote SVN to Mercurial

I was working with SVN quite a long time and was happy about it. But number of active projects increased and some of them were needed to be supported even while travels. Since that time I moved to decentralised version control system and have control over my code-sources even when I’m travelling and without internet connection.

For code hosting I use SourceForge.net for opencource projects and BitBucket.org for private projects. BitBucket.org supports both Git and Mercurial and allows 5 repo users for free. I prefer to work with Mercurial.

How to move a code repository from remote SVN server to Mercurial BitBucket?

First of all we need to SVN command line utilities called svnrdump and svnadmin.They are installed together with TortoiseSVN, if an option was checked in the installer.

If we access SVN through SSH then we need following:

  • PuTTY utilities pageant.exe and plink.exe must be in PATH
  • It is probably needed a system variable SVN_SSH with full path to plink.exe. I have for example SVN_SSH = “C://Program Files (x86)//PuTTY//plink.exe” Note double slashes here.
  • In the file ..\AppData\Roaming\Subversion\config in section [tunnels] we should uncomment line ssh = $SVN_SSH ssh -q
  • pageant.exe should be started with a private key
    "C:\Program Files (x86)\PuTTY\pageant.exe" c:\key_private.ppk

This is probably the most difficult part to make SVN work through SSH.

And now we are ready to move the repository.

1. Make a dump of the remote SVN repo to local file repo.dmp (this works with SVN from version 1.7)

svnrdump dump http://example.com/svn-repo/ > repo.dump

2. Create a new local SVN repo and restore data from dump into it

svnadmin create c:\svn-repo
svnadmin load c:\svn-repo < repo.dump

3. Convert local SVN repo to Mercurial repo

hg convert c:\svn-repo c:\hg-repo

If hg convert command does not work it means convert hg extension is not enabled. To enable it open Hg Workbench and go to File->Settings->Extensions check convert option there.

4. Transfer the created Mercurial repo to BitBucket
First create a new repo on BitBucket service. Then just push into it.

cd /path/to/my/new-local-repo
hg push ssh://hg@bitbucket.org/username/new-repo

This is the longest operation and it is nice to have a fast Internet connection to complete it fast.
If we do this push in Hg Workbench there is a progress there on how many files are pushed.

5. Make the BitBucket repo default.
There is a file .hg/hgrc in repo folder, it has a [paths] section. Write the following line there:
[paths]
default = ssh://hg@bitbucket.org/username/new-repo

If plink complains about server’s host key is not cached in the registry:

The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 хх:хх:хх:хх:хх:хх:хх:хх:хх
Connection abandoned

Then we need to run plink directly in command line and confirm the key caching:

plink -agent bitbucket.org
The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 97:8c:1b:f2:6f:14:6b:5c:3b:ec:aa:46:46:74:7c:40
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n) y