24

Due to lack of Mercurial support in several tools, and managerial oppression it has become necessary to convert several trial Mercurial repositories to Subversion in order to conform with the company standard.

Are there any tools or suggestions for how to achieve this without a loss of revision history and the like?

Jonik
  • 80,077
  • 70
  • 264
  • 372
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
  • For the next wonderer who finds Mercurial strange and is pining for Subversion, you may find this link useful: [Subversion Re-education](http://hginit.com/00.html) – noelicus Sep 30 '14 at 08:46
  • For the next wanderer who finds Mercurial repugnant, please do not "re-educate" yourself using the link above unless you believe that a vendor which sells Mercurial-based tools has an unbiased opinion. Maybe try respecting preferences and opinions about VCS vs DVCS tools. Many people have tried both -- or were forced to -- and have perfectly valid opinions about what *they* prefer, and why. – JoGusto Dec 15 '17 at 19:28

3 Answers3

29

The convert extension that ships with mercurial can use mercurial as a src and subversion as a dest.

hg convert --dest-type svn hgreponame svnreponame

Make sure to enable it in your .hgrc file.

If you want to keep using mercurial on the sly, then hgsubversion will allow you to do bidirectional sync.

Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
  • 1
    this fails after 2 revisions with `abort: svn exited with status 256` – Matt Joiner Dec 14 '09 at 06:03
  • 1
    I've not used the svn dest stuff, but I have seen it change a lot lately on the mailing list. Make sure you're using the latest mercurial (1.4.1) and the latest swig bindings for the latest svn. Then start using some combination of --debug --traceback and maybe even strace. It may be necessary to start out with an entirely linear mercurial history, which is easily achieved with 'hg clone http://src -r tip'. I think I've heard that svn's repo format isn't up for storing mercurial merge revisions cleanly. – Ry4an Brase Dec 14 '09 at 21:59
  • 4
    Just a further note on this, abortions were occurring due to file-system shortcomings of some kind (ntfs3g). Just keep trying. – Matt Joiner Apr 18 '10 at 02:17
  • I am having issues running this on windows. Have you managed this in a win64 environment? D:\work\horizon>hg convert --dest-type svn src horizon-svn --debug initializing svn repository 'horizon-svn' running: "svnadmin" "create" "D:\work\horizon\horizon-svn" < NUL: abort: svnadmin exited with status 1 D:\work\horizon>svnadmin --help – mikelong Nov 27 '12 at 01:46
  • Sorry @mikelong if it's a one time thing you're better off bringing up a linux VM and doing the conversion there. It looks like the answer below from nitwit came to that conclusion too. – Ry4an Brase Nov 28 '12 at 02:22
  • This worked for me when the input and output were subdirectories of the same directory. When I specified the input on a different drive it gave an error. Make sure the destination directory does not exist. – Andomar Mar 27 '13 at 11:13
  • I ran a command in windows machine and it works great. However, in SVN all dates are wrong - they are times when conversion took place instead of when mercurial checkins were made. Is there a way to fix this? – Arek May 26 '17 at 13:07
  • One note. You have to be in one director above the mercurial repository root to execute this command. So if you start HG Terminal (for example from TortoiseHg), you have to make `cd ..` first. – Arek May 26 '17 at 13:08
  • 2017 Update: On Windows 7 x64, using Mercurial v4.4.2 (TortoiseHg) and SVN v1.9.7, the command line as stated verbatim in Ry4an's answer worked perfectly for me, specifying the directory (not the SVN URL!) of the subversion conversion target. The exported changesets appear in the SVN repo tree root dir, not off some /projectpath/trunk node, so beware, this may not be exactly what you want. Try it out first using a test SVN repo target created specifically as a throw away test case. – JoGusto Dec 15 '17 at 19:22
9

Ry4an's answer above does the trick exactly; some more detailed instructions for anyone (like me) who's having trouble:

  1. Do yourself a favor and don't try this on Windows. You'll have to install a very specific version of SVN, and even then certain things will fail with assorted error messages. My solution was to boot a clean AWS instance, yum-get the latest versions of mercurial and svn onto it, clone the HG repo, and run the convert there.

  2. Add this to your .hgrc file to enable the convert extension:

    [extensions]
    hgext.convert=
    
  3. Run this command:

    hg convert --dest-type svn <hg_directory> <directory_for_svn_output>
    
  4. You might get the following error:

    abort: svn exited with status 256
    

    Don't give up! Just run the same command again and it'll continue where it left off.

    If you continue to run into trouble, add --debug --traceback to the command line to get more details on what went wrong.

nitwit
  • 1,745
  • 2
  • 17
  • 20
  • Erm, what does Windows have to do with any of that? – Billy ONeal Nov 23 '11 at 20:17
  • @BillyONeal It's been too long, so I don't remember exactly, but under Windows my convert failed due to some syntax issues (I think it was due to some problem with formatting command-line parameters to svn.exe). Searching those errors on Google, you'll find you need a very specific version of SVN for it to work. After some time tinkering with it, I chose to just do it on AWS and it worked the first time around. – nitwit Nov 27 '11 at 10:04
  • I failed to manage this on both windows and linux. On linux the error messages are mike@mike-virtual-machine ~/repos $ hg convert --dest-type svn ~/Horizon ~/HorizonToSvn initializing svn working copy 'HorizonToSvn-wc' scanning source... sorting... converting... 6655 baseline 30357 abort: svn exited with status 32512 mike@mike-virtual-machine ~/repos $ – mikelong Nov 29 '12 at 08:25
  • This command worked fine on Windows with the TortoiseHg 4.6 and TortoiseSVN 1.11.1 CLI tools installed. – PitaJ Feb 14 '19 at 21:13
  • I also had good experience with Windows using TortoiseHG and TortoiseSVN, echoing PitaJ's comment above. My only gripe is that the revision history log dates are not the original dates, but are set to the time the conversion was performed. This could be improved, perhaps. Thanks to the FOSS community for this great software! – JoGusto Apr 02 '19 at 23:28
3

Tailor should be able to do what you want.

Mikael S
  • 5,206
  • 2
  • 23
  • 21
  • @ChrisFreeman: Unfortunately it seems arstecnica.it is down. Debian still has the files in their package database: http://http.debian.net/debian/pool/main/t/tailor/tailor_0.9.35+darcs20090615.orig.tar.gz – Mikael S May 11 '16 at 19:39