Converting a Subversion repository to Mercurial

1/19/2012 10:34:54 PM

At work we recently decided to make the jump to working with a DVCS and Mercurial was what we decided to go with.  We had some Subversion repositories that we wanted to migrate to Mercurial and after some poking around the interwebs, here is what I've come up with to get things migrated.

  1. Open command prompt into parent folder where Hg repo should be created
  2. Use command: hg convert <repo url>  (e.g. hg convert https://some.repo.url/ )
  3. Hg repo will be created as <repo name>-hg  (e.g. MyRepo-hg) 
     - set destination by using hg convert <source repo url> <destination repo url>
     - optionally set user names to get better conversion --authors 
Convert can also remap author names during conversion, if the --authors option is provided. The argument should be a simple text file that maps each source commit author to a destination commit author. It is handy for source SCMs that use UNIX logins to identify authors (eg: CVS). Example:
 
john=John Smith <John.Smith@someplace.net>
tom=Tom Johnson <Tom.Johnson@bigcity.com>
 
To convert subfolders of a repo into a new Mercurial repo just add the --filemap option. The argument should be a simple text file that lists which directories to exclude and which to rename as the root. The conversion will need to be run once for each subdirectory you want to split out, with appropriate settings in the filemap file. This is best done from a local SVN mirror if the repo is large. 
Sample filemap file (note the . to set the new root with rename):
 
exclude Blog
rename Core .
exclude KN
 
With all of the options tacked on, this is what you'll end up with:
 
hg convert <svn_repo> <local_hg_repo_path> --authors <author map file> --filemap <repo map file>
e.g. hg convert https://remote.repo.url NewRepo --authors authors.txt --filemap repomap.txt
 
I had a fairly difficult time finding a good example of how to accomplish all of these things together so hopefully this will save some time for the next person.
Tags:Mercurial
fe89038d-50d8-4993-8c4b-d7316f18dda1

Comments:

No comments yet
Name:
Email: (Your email will not be displayed or distributed in any way)
Comment:
  • © brentman.com 2009-2012 | This site licensed under a Creative Commons license
  • The opinions expressed on this site are my own and not those of my employer.
Log In
 
 
login