Sunday, December 31, 2006

Using tailor to move from hg to svn

First question, why would I want to do that? Actually I don't really want to do that but code.google.com uses SVN as its VCS and I want to host a project there. I originally used Mercurial (hg) for that project and so I need to get it out of hg and into svn. The ultimate goal is to use either Bazaar-NG (bzr) with it's svn plugin or svk, this is a step along that path.

Second question, isn't that straight forward? No, tailor's hg->svn support is busted. hg doesn't care about directories, svn does and this makes it impossible to move from hg to svn if you have any directories (I filed a bug). So instead I must move everything to bzr first and then to svn as the bzr->svn code seems to handle directories correctly. It seems that one of hg->bzr or bzr->svn makes the directories problem go away.

The following little bash script takes 3 arguments:

  • the path to the hg repo that you want to put into svn
  • the path to the svn repository
  • the name of the svn module that the code will live in
It uses these to output 2 tailor project files, hg2bzr.tailor and bzr2svn.tailor and then it runs tailor twice. #! /bin/bash source=$1 shift svn_repo=$1 shift svn_module=$1 shift # create 2 project files cat <<eof> hg2bzr.tailor [DEFAULT] verbose = True [project] target = bzr:temp start-revision = INITIAL root-directory = $PWD/working-bzr state-file = tailor.state source = hg:source subdir = . [hg:source] repository = $source [bzr:temp] # no details needed because eveything just ends up in working-bzr EOF cat <<eof> bzr2svn.tailor [DEFAULT] verbose = True [project] target = svn:target start-revision = INITIAL root-directory = $PWD/working-svn state-file = tailor.state source = bzr:temp subdir = . [bzr:temp] repository = $PWD/working-bzr [svn:target] module = $svn_module repository = $svn_repo EOF # convert from hg to bzr tailor --configfile hg2bzr.tailor # and then from bzr to svn tailor --configfile bzr2svn.tailor

I invoked it as

./hg_to_svn deep-hg https://python-deep.googlecode.com/svn/ trunk/
and the result is in the SVN repository. Yay!

It takes quite a while to push all the changes and I had to clear out the repo once as the svn command stalled and timed out (server problem I think). Then I made a mess of restarting the whole process (I think it also wasn't helped by me reusing a directory from my test run!). Speaking of the test run, I played around with svk and it seemed quite awkward in comparison to hg and bzr. Not having used any of them for heavy duty work I can't really speak with authority. It definitely seems that svk's branch and merge process (as described in a rather good tutorial) reuires typing more commands and typing more awkward paths than with bzr or hg.

No comments: