Converting a Subversion repository to Mercurial

This snippet will guide you through the process of converting a Subversion repository on to a Mercurial repository on


You need to have either have Subversion 1.5 (or later) installed along with either Subvertpy 0.7.3 (or later) or the Subversion SWIG Python bindings. You need Mercurial 1.3 or later.

Installation of hgsubversion

You need to have mercurial installed and an extension called hgsubversion as well. You can get it from bitbucked:

$ hg clone

You need to be sure that hgsubversion is in your python path, so just install it using the

$ cd hgsubversion
$ sudo python install

hgsubversion depends on a python package called subvertpy, to build this you need the development headers for svn and apache (apr), so on Ubuntu run:

$ sudo apt-get install libsvn-dev libapr1-dev

Next, we need to enable the extension, so open the ~/.hgrc file and add the following:

hgsubversion =

Check that hgsubversion is in the enabled extensions list:

$ hg help extensions


When the conversion starts, hgsubversion will convert the tags directory from svn to tags in Mercurial. However, in many projects this directory is called tag instead of tags. You can tell hgsubversion how the tag folder is called, in your ~/.hgrc configuration file

tagpaths = tag

Cloning a Subversion repository in Mercurial

All you have to do is clone the Subversion repository from Mercurial:

$ hg clone svn:

When the cloning is finished, go in to the new mercurial repository:

$ hg tags

You should now see a list of all the tags from the project.

You can copy all the svn:ignore properties from svn by running the following command:

$ hg svn genignore

This should produce a file called .hgignore with all the ignores in it.

Cloning the branches is a bit problematic, you need to copy the branch directory in subversion to branches. You can also specify a branchmap in the configuration file to rename the branches to something more sensible. See the hgsubversion help for more options:

$ hg help hgsubversion

Creating the centralized Mercurial repository

Now that we have a local Mercurial repository we can verify that the conversion went okay, and push the repository to our centralized repository (

To do this we first need to log in to the titan server to add the repository with the script

$ ssh
$ cd /home/infrae/mercurial/repositories
$ sudo -u www-data ./ <repo name>

Look at the output of the script, it will show you a couple of lines that can be copied to the trac configuration, so your project becomes visible at

Now, in our local mercurial project, we need to change the default push path, so open the .hg/hgrc file, and change the following lines:

-default = svn+
+default =

Last step is to do the actual push in the local repository:

$ hg push
blog comments powered by Disqus