Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Mercurial: Import Subversion Project

📅 2010-Mar-01 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ mercurial, subversion, windows ⬩ 📚 Archive

Mercurial is a distributed VCS (DVCS). If you are planning to migrate from Subversion to Mercurial, it might be better to do this on a per-project basis. Due to the nature of a DVCS, it is better to spin off each of your Subversion projects in the repository as separate Mercurial repositories. Here is how:

  1. If you have not already done so, make a copy of the Mercurial configuration file (Mercurial.ini) and add your username. See this post on how to do this.

  2. The command to convert repositories is hg convert. It will not work unless the convert extension is enabled. To do this, open your Mercurial.ini and in the [extensions] section uncomment the convert = line. It should read:

convert =
  1. The default Windows binaries of Mercurial cannot import from Subversion. If you attempt a hg convert using this binary, you will see an error:
$ hg convert file:///C:/SVNRep/FoobarProject
Subversion python bindings could not be loaded

You will need the Python bindings of Subversion and Mercurial installed on top of a standalone Python to be able to do this. That is too messy! But, there is an easier alternative to this. Install TortoiseHg, the Explorer extension to Hg. Its hg.exe has been built with all the necessary bindings. Issue the convert command using its hg.exe:

$ "C:\Program Files\TortoiseHg\hg.exe" convert file:///C:/SVNRep/FoobarProject

This should work. If your Subversion project has been cleanly maintained with the canonical trunks, branches and tags structure hg convert can import all of that correctly into the Mercurial structure of tags.

© 2023 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧