Skip to end of metadata
Go to start of metadata

Intention

You prefer to use Mercurial yourself, but the pristine source code (let's call it upstream) of the project you are working on is kept in Subversion restraints?

Then this article is for you! I'm going to explain how to:

  • aquire a local, synchronised copy of the upstream SVN repository
  • convert it to Mercurial
  • drag new pristine source changes in from upstream
  • easily merge the changes into Mercurial

All you need to do this, is the command line tools for Subversion (svn, svnadmin, svnsync) and Mercurial (hg).

Acquiring an upstream clone (SVN)

In a terminal window, create a new SVN repository (we assume /tmp/upstream here, but in a real-world scenario you may want to put it in a more appropriate location):

svnadmin create /tmp/upstream

The next step is to allow property changes. Create the file /tmp/upstream/hooks/pre-revprop-change with this content:

#!/bin/bash
exit 0

Make it executable:

chmod 755 /tmp/upstream/hooks/pre-revprop-change

Now you've got an empty repository, which allows property manipulations (necessary for the sync process).
Let's prepare it for synchronisation. You can either use the upstream's entire repository (probably not desired), or any branch or tag (which is in fact a subdirectory in the SVN url).

Let's say we want to use http://arbitrary.upstream.org/svn/trunk – the trunk only.

svnsync init file:///tmp/upstream http://arbitrary.upstream.org/svn/trunk

And then, finally, you are ready to kick off:

svnsync sync file:///tmp/upstream 

This will take a while for repositories with many revisions. Grab a coffee

Pull in new revisions
Whenever you want to pull in subsequent commits, just run the command again:
svnsync sync file:///tmp/upstream

Preparing Mercurial

You need to have a ~/.hgrc file with at least this content:

[extensions]
hg.convert=

As convert is an extension, which is part of Mercurial, we don't need to specify more here. It will know where to find it and how to use it.

Importing into Mercurial

This is so simple that a whole section is hardly justified:

hg convert /tmp/upstream /where/ever/you/want/upstream-copy

Then it takes a while (mostly depending on the size of the old repo, of course), and that's it.

Keeping theirs and yours in sync

This section has yet to be written. But as the conversion part itself may be useful for some, I published that bit already.

Soon you can read more about re-syncing the svn-converted clone, and using Mercurial Patch Queues to manage your changes. Watch this space.

Shortcuts



Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.