Svn to Mercurial migration guide (Windows)

February 16, 2010 at 20:21 (Coding) (, , , , , )

I recently wanted to work on a project hosted at SourceForge (SVN), to which I didnt have commit access. Since I still wanted to have my work version controlled, I decided to take a stab at converting the source tree. I was reading this guide and this post documents my experince.

Setup

You need to install:

Then install hgsvn by running

    easy_install hgsvn

Import

    hgimportsvn https://dfhack.svn.sourceforge.net/svnroot/dfhack
    cd dfhack
    hgpullsvn
    hg update

hgpullsvn is going to take a while so go make yourself a cup of coffee. For me, I judged the average to be around 10 seconds per svn commit. Luckily, the project I converted only had 166 commits. During the import it failed a few times, but just running the command again seemed to make it pick up where it left off and just continue. The errors varied but always ended with that svn “couldnt connect to the sourceforge server”. Maybe I just hammered it to hard.

If you just installed mercurial you should set your username before your first commit. Open up notepad and save this to %USERPROFILE%\Mercurial.ini (obviously replaced with your own name):

    [ui]
    username = John Doe <john@example.com>

After the import, there is a local .hgignore file, just add it:

    hg add .hgignore
    hg ci -m "added ignore file generated by import"

When I first tried to push I got a authentication error so I went into my Bitbucket account settings and added my public ssh key. If you dont have one github has instructions on how to set one up, you can also use the git bash shell as a ssh agent.

The import is now done, after youve created a Bitbucket repos just push to it:

    hg push http://bitbucket.org/mizipzor/dfhack/

Pulling new changes from SVN

By the time my conversion was complete and I had pushed it to my own repos two new revisions had been commited to the SVN. Fetching them was suprisingly simple:

    hgpullsvn
    hg merge
    hg ci -m "merge from svn"
    hg push https://mizipzor@bitbucket.org/mizipzor/dfhack

But do note that since we dont track the .svn or .hgsvn folders, should ever you do a clean checkout from the Bitbucket repos, the hgpullsvn command will say this:

    C:\Code\dfhack-hg2>hgpullsvn
    Traceback (most recent call last):
      File "C:\Python26\Scripts\hgpullsvn-script.py", line 8, in <module>
        load_entry_point('hgsvn==0.1.8', 'console_scripts', 'hgpullsvn')()
      File "build/bdist.linux-i686/egg/hgsvn/run/hgpullsvn.py", line 315, in main
      File "build/bdist.linux-i686/egg/hgsvn/run/common.py", line 90, in locked_main

      File "build/bdist.linux-i686/egg/hgsvn/run/hgpullsvn.py", line 196, in real_main
      File "build/bdist.linux-i686/egg/hgsvn/svnclient.py", line 152, in get_svn_info
      File "build/bdist.linux-i686/egg/hgsvn/common.py", line 236, in run_svn
      File "build/bdist.linux-i686/egg/hgsvn/common.py", line 169, in run_command
      File "build/bdist.linux-i686/egg/hgsvn/common.py", line 142, in _run_raw_command
    hgsvn.errors.ExternalCommandFailed: External program failed (return code 1): C:\
    Program Files\SlikSvn\bin\svn.exe "info" "--xml" "."

Which is an ugly stack trace for simply stating that “this is not a working checkout of a svn repos”. I dont really like this. I wouldnt want those folders on my Bitbucket (the guide I read suggested it), but I really like the feeling of knowing that if I screw up I can just delete the folder and do a new checkout. With my current setup, I would have to run the svn import all over again. This issue alone might make me look into alternatives
but for now, this works well enough.

Advertisement

1 Comment

  1. 2010 in review « Mizipzor's Weblog said,

    [...] Svn to Mercurial migration guide (Windows) February 2010 4 [...]

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 )

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

Follow

Get every new post delivered to your Inbox.