Migrating from Subversion to Mercurial
As a relatively new Perforce employee, I’m still in the process of migrating all my old code from other tools. So this is part one of a little blog series covering the various tools in the chain I’ll be using to ultimately get all of my code into the Perforce Versioning Engine.
Recently, I needed code from projects still in Subversion, and integrating them with the rest of my code (the majority of which is in Mercurial) seemed like a good first step. It also provided an opportunity to evaluate how well Mercurial handles imports from Subversion.
Happily, it was simpler than I anticipated. The entire process can be described by three steps:
- Get the extension to let Mercurial work with Subversion
- Configure the extension as needed to connect with Subversion
- Import the files from Subversion into a new Mercurial repository
The first step requires only getting the code for the extension. To do this, choose a place on your hard drive (extensionpath) where you want it to live and issue the following command:
hg clone http://bitbucket.org/durin42/hgsubversion/ extensionpath
The second step is all about configuring Mercurial to use it. To do this, open the Mercurial configuration file (.hgrc) in your home directory and include the extension as follows:1
[extensions] hgsubversion = extensionpath/hgsubversion
This will make sure the extension is loaded. If the source Subversion repository is secured, then the easiest way to make sure your credentials get passed properly is to add the following section as well:
[hgsubversion] username = UserId password = Password
This gives the extension credentials to use when authenticating with Subversion. There are other ways, but I’ve personally found this to be most reliable. Now you’re good to go! You can clone a new, local Mercurial repository directly from a Subversion remote path with a command like the following:
hg clone svn://remotepath localpath
If your server uses HTTPS, simply replace the Subversion protocol in the above URL (svn://) with svn+https:// instead. And of course, the remote path should be chosen to clone only the branch or other portion you wish. In my particular case it took roughly an hour to import 1,100+ commits, and when it was done I had a Mercurial repository already configured to push new work back to Subversion if needed.
In later entries in the series, I’ll discuss the next steps in my migration process from Visual SourceSafe to Mercurial and from Mercurial to the Perforce Versioning Engine. Read part two in this series on migrating from Visual SourceSafe to Mercurial.
You can find migration tools and utilities in the Perforce Migration Center.
1 For Windows users, Mercurial will look in the root of your user profile or the %userprofile% directory. You can use that environment variable in the location bar of Windows Explorer or in a command prompt.