My favorites | Sign in
Google
             
Search
for
Updated May 27, 2009 by sussman
Labels: Mercurial
ConvertingSvnToHg  
Moving a project from using Subversion for code hosting to Mercurial

Convert your project from Subversion to Mercurial

Follow the following instructions to switch your project from Subversion to Mercurial:

  1. Go to your existing open source project, choose the Administer tab, and then choose the Source sub-tab.
  2. Change the repository type to Mercurial
  3. Import your code into the Hg code repository as described in the 'How to Convert Subversion History to Mercurial' section below
  4. In the same manner you imported your code, import your wiki into the Hg wiki repository. Make sure to use the path of the wiki in your subversion repository (e.g. http://projectname.googlecode.com/svn/wiki) and the Hg wiki repository (http://wiki.projectname.googlecode.com/hg/)

Your old Subversion project will still be accessible after you switch your project to using Mercurial, so you will not need to back up your repository before switching. Your Subversion repository will remain accessible at: https://projectname.googlecode.com/svn/

How to Convert Subversion History to Mercurial

Option 1: Top-Skimming

If you don't care about your project's history, then you can simply "top skim" the latest trunk code or wiki from Subversion and put it into Mercurial. Assuming your googlecode Mercurial repository is empty, it's as easy as:

  $ hg clone https://projectname.googlecode.com/hg hg-client
  $ cd hg-client
  $ svn export --force http://projectname.googlecode.com/svn/trunk .
  $ hg add .
  $ hg commit -m "Initial import of source."
  $ hg push

Option 2: Full History Conversion

If want to migrate your whole history, the process is much more involved. You'll need these special tools installed first.

Install tools

This already ships with recent Mercurial distributions; just make sure you're running hg version 1.1 or 1.2. ("hg --version").
Enable the extension by adding to your .hgrc:
         [extensions]
         hgext.convert=
Make sure you have a recent Subversion installed (1.5 or 1.6). Many distributions of Subversion ship with the python bindings, or offer "extra" binary packages of them.
You can check that your svn-python bindings are installed correctly by running:
        $ python -c "import svn.core; print svn.core.SVN_VER_MINOR"
        5
If this fails, or if you get a minor version less than 5, then something is wrong.
If you have no binary package available and are desperate, you can build them from Subversion's own source tree:
        $ svn checkout http://svn.collab.net/repos/svn/tags/1.6.0 svn
        $ cd svn
        $ ./autogen.sh && ./configure
        $ make
        $ sudo make install
        $ make swig-py  # make sure you have swig 1.3 installed already
        $ make check-swig-py
        $ sudo make install-swig-py
If you're on the Hardy version of Ubuntu, you can find version 1.5 of python-subversion in hardy-backports:
http://packages.ubuntu.com/hardy-backports/python-subversion
This may also require installing backports of the libsvn1, subversion, mercurial-common, and mercurial packages.

Doing the Conversion

Now we do the conversion -- branches, tags and all:

  $ mkdir hg-client
  $ hg convert http://projectname.googlecode.com/svn hg-client

Once the conversion is done, you can push the new history up to your Google Code project (which presumably has an empty Mercurial repository):

  $ cd hg-client
  $ hg push https://projectname.googlecode.com/hg

Comment by OliverJohnReeves, May 05, 2009

There is a much simpler way of migrating the content of the SVN repository using the hgsvn set of tools.

Information on where to find it and how to use it can be found at http://www.oreillynet.com/onlamp/blog/2007/08/dipping_my_toes_into_mercurial.html

Comment by sussman, May 08, 2009

I wouldn't trust the hgsvn toolset much. It's a script which shells-out to both the 'hg' and 'svn' commandline binaries... which means it's very brittle and likely to be less accurate than either 'hg convert' or the 'hgsubversion' project, which use the real low-level library APIs of both systems.

Comment by szemereszemere, May 22, 2009

Works a treat! Took 10mins to get it working.

2 minor notes: "svn help" to check the version for subversion. "python-subversion" is the extras package on Ubuntu Jaunty 9.04

Szemere

Comment by nick.bolton.uk, May 28, 2009

In response to the email, "New Mercurial wiki repository for your Mercurial projects" from Google... I just tried to migrate our wiki to our hg repository, but I'm getting a "abort: HTTP Error 404: Not Found" error. I assume this is because they haven't begun the migrations yet. I will migrate when our wiki pages dissappear.

Comment by arvindht, May 29, 2009

'hg convert' over http was too slow in my case, probably due to the huge changesets. using 'svnsync' to create a local mirror and then running 'hg convert' on it was much faster.

Comment by brauliobo, Jun 02, 2009
Comment by Zoom.Quiet, Jun 15, 2009

zq4wk0laptop:~/0penproj.s/ZQs/hg-client> python -c "import svn.core; print svn.core.SVN_VER_MINOR" 5 BUT! unknown exception encountered, details follow ... svn.core.SubversionException?: ("PROPFIND of '/svn/!svn/vcc/default': Could not read status line: Connection reset by peer (http://zqlib.googlecode.com)", 175002)

Comment by rogerbinns, Jun 30, 2009

One gotcha that may affect other people. If you have the http_proxy environment variable set then the hg command obeys that. I use Squid and it was returning all sorts of errors (eg HTTP Error 501: Not Implemented and HTTP Error 504: Gateway Time-out) which from the command line look like the Google servers are broken or the instructions are wrong.

Comment by janne.liljeblad, Jul 30, 2009

I didn't quite get step 4., but got wikis out by doing: svn checkout http://projectname.googlecode.com/svn/wiki and than copy pasting text back into new wikis.

Comment by msgilli...@gmail.com, Aug 05, 2009

If anyone has decent up-to-date instructions for getting the python paths setup with the Collabnet version of Hg on OS X, please post a link here...

Comment by markwbmx, Aug 15, 2009

To do a full history conversion on Windows using Cygwin see http://memoryleak.me.uk/2009/08/converting-subversion-to-mercurial-svn.html

Comment by mi...@sorl.net, Aug 18, 2009

hg convert - fail hgsubversion - success!

Comment by chemoele...@chemoelectric.org, Oct 20, 2009

The process was trivial on my Gentoo setup; the warning was misleading! All the difficulty would have been from having to install software that for me was already installed.


Sign in to add a comment