Mercurial: Import Subversion Project

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:
    [extensions]
    convert =
    
  3. 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
    
  4. 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.

13 thoughts on “Mercurial: Import Subversion Project

  1. I have been beating my head against the proverbial wall for hours trying to get the convert to work. I reinstalled Python 2.6 and its bindings umpteen times, trying to make that noxious error disappear. And as soon as I switched from using the basic Hg command to the Hg included with the TortoiseHg package, as you suggest, my repositories imported cleanly on the first try. Thanks so much for your post!

    Like

  2. Hi friend I need your help Im learning the use of HG, and Ineed convert a repo from SVN to HG.

    ok I configure all…. but when I run “hg convert” I have this error.

    “”
    d:\repos\repotest> hg convert s- svn D:\test\reposvn reposvn-hg
    initializating destination reposvn-hg repository
    scanning source…
    sorting…
    converting…
    0

    d:\repos\repotest>
    “”
    I have 3 floders in the svn repo (trunk,branches,tags)

    But after the convertion I don’t see any folder in the converted repo.

    I don’t understand what happening…

    Can you help me?

    Thanks in advance.

    Like

    1. Sergio: The repository layout of Mercurial differs from Subversion. There are no trunk, branches and tags directories in Mercurial. Instead, you will find a default branch (similar to trunk) and the branches and tags should be visible if you use the “hg -branches” and “hg -tags” commands.

      Like

  3. We are planning to move to mercurial from subversion. We have the usual Branches/Tags/Trunk structure. We are on Windows. Do you know if the same techniques you mentioned work for it. Also, do you know if there are other links that talk about the various collaboration models that mercurial supports. Right now we have a single repository but we are in the process of figuring out what best works for us.

    Like

    1. Thank you very much. When I import the subversion project into mercurial will I loose my ability to use the subversion project as is if needed.

      Like

  4. Hi there,

    I am trying to convert just a trunk branch to mercurial. I have tried to execute
    $ “C:\Program Files\TortoiseHg\hg.exe” convert file:///C:/SVNRep/Proj-Trunk and it errors out saying C:/SVNRep/Proj-Trunk does not look like a subversion repository. Any help will be great as I am stuck with this for quite sometime now.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.