Braindump

Mirror Svn Repo With Hg

How to mirror a svn repository using hg

Directory layout

The directory layout I want to achieve is this:

/path/to/project        root for the project (empty, apart from maybe scripts, automating the syncing)
  |
  +- svn-mirror         local mirror of the svn repo
  |
  +- hg-mirror          local hg version of ../svn-mirror (don't ever 'hg push' to here!)
  |
  +- project-bug-4711   local hg branch (clone) for working on bug 4711
  |
  +- project-feature1   local hg branch (clone) for feature 1
  ...
  |
  `- project-featureN   local hg branch (clone) for feature N

Instructions

The detailed description is in the Mercurial book: http://hgbook.red-bean.com/read/migrating-to-mercurial.html

Linux/Unix

$ cd /path/to/project/
$ svnadmin create svn-mirror
$ echo '#!/bin/sh' > svn-mirror/hooks/pre-revprop-change
$ chmod +x svn-mirror/hooks/pre-revprop-change
$ svnsync init file://$(pwd)/svn-mirror http://svn.example.com/svn/project    # this should be the repo root, i.e. not trunk
$ svnsync sync file://$(pwd)/svn-mirror
$ hg convert svn-mirror hg-mirror
$ hg clone hg-mirror project-feature1

Windows

C:\>cd path\to\project
C:\path\to\project>svnadmin create svn-mirror
C:\path\to\project>echo. > svn-mirror\hooks\pre-revprop-change.bat
C:\path\to\project>svnsync init file:///c:/path/to/project/svn-mirror http://svn.example.com/svn/project
C:\path\to\project>svnsync sync file:///c:/path/to/project/svn-mirror
C:\path\to\project>hg convert svn-mirror hg-mirror
C:\path\to\project>hg clone hg-mirror project-feature1

Improving the hg log regarding user names

Subversion and Mercurial user names differ. Typically with hg you rather use information resembling an email address than a system login name. To map Subversion user names to Mercurial user names you can provide a simple text file (let's name it authors.txt) with content like that:

jdoe = John Doe <john@example.org>
jdoe2 = Jane Doe <jane@example.org>

Then add this when converting from Subversion, like that: hg convert --authors authors.txt svn-mirror hg-mirror

Pushing/publishing the hg mirror

You can now publish the hg mirror like this:

$ cd /path/to/project/hg-mirror
$ hg push ssh://someuser@hg.example.com/path/to/project

If you always push to the same location, you can save some typing. Edit /path/to/project/hg-mirror/.hg/hgrc and add a value for default-push under section [paths]:

[paths]
default-push = ssh://someuser@hg.example.com/path/to/project