Jun 22, 2012

Splitting a large SVN into multiple Hg repos


In my previous post on moving from SVN to Hg I gave the detailed steps on how to move a single project. This post doesn't have the same level of detail so I'm assuming you read that post. This post talks about the things you'll do differently that allow you to more easily extract many projects to their own Hg repos.

You'll want to start by creating a new directory for your full svn repo, so you'll svnadmin create just like before. This time though the svnsync init should be done to the root level of your svn repo. You'll then svnsync sync into your new full repo. Once you have a fully copy of your repo locally there are a few changes to the hg convert process.

First you'll need a mapping file for each project. The mapping file will instruct hg convert to extract just the project of interest and rename that project without the extra folders that were probably in your svn repo for organizational purposes.

For example, in my ProjectLocker svn repo I have the following path


I want to both extract just this project, and I want the files to end up directly in the folder I specify. For example let's assume I  convert to a folder called DataLayer. I don't want to end up with DataLayer/HarborShipSupply/HssDataLayer. I just want all the source files and directories that belong to the HssDataLayer project directly under the DataLayer folder.   I can achieve both of these goals with a file mapping text file  named DataLayerImport.txt that looks like this:

include "HarborShipSupply/HssDataLayer"     # gets just the project of interest
rename "HarborShipSupply/HssDataLayer" "."  # removes folder hierarchy

Now when I use the hg convert command I specify the filemap, the file that has my entire svn repo, and the destination folder.

hg convert –filemap DataLayerImport.txt file:///g:/test/full_project_locker g:/Test/DataLayer

When that's done I can use TortoiseHg to issue and Update and my project's in Hg ready for more coding.

Once I create multiple file maps. I can put all the hg convert commands in a .bat file and let all my svn projects convert while I go write some code.

About Me

My photo
Tod Gentille (@todgentille) is now a Curriculum Director for Pluralsight. He's been programming professionally since well before you were born and was a software consultant for most of his career. He's also a father, husband, drummer, and windsurfer. He wants to be a guitar player but he just hasn't got the chops for it.