Converting Monotone To Mercurial
Today I had to convert a Monotone repository to Mercurial. Tailor is a tool that can convert changesets from one SCM into the format of another SCM. It currently supports many major SCM systems, including Monotone and Mercurial.
Tailor is written in Python and you can check out the latest version from their source repository:
$ darcs get --partial http://darcs.arstecnica.it/tailor
To do this, you will need to have darcs installed. Once you've got this, install tailor by running:
$ [sudo] python setup.py install
To be able to perform any conversions, you will need to have both the source and target systems installed in your environment. For this scenario, I needed to have both Monotone and Mecurial installed locally.
Using Tailor involves a two step process:
- Use Tailor to create a configuration file that describes the source and target repositories;
- Supply this configuration file to Tailor and tell it to run the conversion.
There is a good manual page that describes all of the options you can supply, but I just want to demonstrate how to convert all revisions of a particular branch in a Monotone repository to a Mercurial repository.
To do this, I ran Tailor with the following options, redirecting the output into a configuration file, which will be used in step two:
$ tailor -s monotone -t hg -R mtn.db \
-module com.acme.your_branchname \
target_dir --verbose > config.tailor
This indicates the location of the Monotone database and the particular branch to be converted. To perform the conversion, run the following:
$ tailor --configfile config.tailor
On the first attempt, the conversion was successful, apart from the way the commit comments had been migrated. Instead of copying the committer's actual comments, Tailor had produced comments that look this:
[project @ 4ff5bc70bed0ed59cbbc736d486044cb31047f6c]
To remedy this, there is an attribute called patch-name-format that you can set in the configuration file to tell Tailor to keep the original comments. You can see this option in the final version of my configuration file:
[DEFAULT]
verbose = True
[project]
target = hg:target
start-revision = INITIAL
root-directory = /tmp
state-file = tailor.state
source = monotone:source
subdir = target_dir
patch-name-format = ""
[hg:target]
[monotone:source]
module = com.acme.your_branchname
repository = /tmp/mtn.db
After adjusting this, I reran the conversion and everything was fine.
If you want to, you can skip step 1 and just use this configuration file, adjusting the paths and branch names where necessary.

Reader Comments (1)
Oddly, because darcs has a strange notion of "revision identifier", using the empty-string for patch-name-format when converting darcs to hg doesn't produce good results, at least with tailor 0.9.35 (and darcs 2.0.2 and hg 1.0.1).
Instead, using the line "patch-name-format = %(revision)s" gave good results for me.