The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream

    20140508-Delphi-2007--Project-Options--Cannot-Edit-Application-Title-HelpFile-Icon-Theming

    20140430-Fiddler-Filter-Actions-Button-Run-Filterset-now

    20140424-Windows-7-free-disk-space

    More Photos
  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,757 other followers

Moving a Subversion/SVN including history to Mercurial/HG using TortoiseHG or HG command-line tools

Posted by jpluimers on 2014/11/17

This blog entry shows how I moved my BeSharp.net repository from SVN at BeSharp.codeplex.com to mercurial.

I develop most of my software using Windows, so if you want to perform the steps below (except TortoiseHG) on a *nix or Mac machine, you have to do some backslash to slash replacement, and find out where the mercurial settings file is stored.

The rest is pretty much the same.

Note the aim was to do a one time conversion. If you want to use both SVN and HG at the same time, then HgSubVersion definitely worth looking at.

Step zero: enable the convert extension (once per client machine)


Mercurial/HG uses the convert extension to convert repositories in potentially different formats

Enable the convert extension using TortoiseHg

Enable the convert extension using TortoiseHg (click to enlarge)

What this does is add one line containing convert = to your %UserProfile%\mercurial.ini file in the [extensions] section, making my file look like this:

# Generated by TortoiseHg settings dialog
[ui]
username = jeroen.example@example.com
[extensions]
convert =

 

That small change now allows you to run hg convert commands from your commandline.
It is a once per client machine step, so if you’ve already done it before, there is no need to do it again.

Step one: find out the SVN users

The easiest way to find out the SVN users is to dump the whole log, then use a text editor to scan for checkins.

After figuring out the SVN url for BeSharp.CodePlex.com, I could start the conversion:

C:\Users\Developer\SVN\BeSharp.codeplex.com>svn log > %temp%\BeSharp.codeplex.com-svn-log.txt

 

Look for lines formatted like this:

r102134 | SND\jeroenp_cp | 2013-08-01 20:28:29 +0200 (Thu, 01 Aug 2013) | 1 line

 

A grep command like this will find them. A find command for this is virtually impossible (:

grep ^r\d*.*line[s]?$ %temp%\BeSharp.codeplex.com-svn-log.txt

 

Apart from SND\jeroenp_cp there were only two system users. Based in that I could create an –authormap author mapping file (I named it %temp%\BeSharp.codeplex.com-svn-hg-autor-map.txt) like this:

SND\jeroenp_cp=jeroen.example@example.com
RNO\_MCLWEB=jeroen.example@example.com
vstfs:///Framework/IdentityDomain/2327b42d-5241-43d6-9e2a-de5ac946f064\Project Collection Service Accounts=jeroen.example@example.com

 

Step two: converting SVN to HG

Note: be prepared for a LONG wait. It is possible to speed this up by using an svnsync intermediate step as explained at creave.dk | Migrating a large SVN repository to Mercurial on Windows. That basically mirrors your complete SVN repository locally using svnsync, then converts from there. There is another page describing the same process.

C:\Users\Developer\HG\bitbucket.org\jeroenp>hg convert --authormap %temp%\BeSharp.codeplex.com-svn-hg-autor-map.txt https://besharp.svn.codeplex.com/svn BeSharp.net-hg

 

If you do not want everything in your SVN repository converted to HG, there are ways to filter as explained in Converting from SVN to Mercurial.

When you filter files, it is also a good idea to create a .hgignore file describing what files you don’t want to be in your HG repository in the future.

The above command results in a log that shows 1 change per line starting with the number of changesets to go (the log below is an excerpt, the full log is at https://gist.github.com/jpluimers/6219861).

C:\Users\Developer\HG\bitbucket.org\jeroenp>hg convert --authormap BeSharp.codeplex.com-svn-hg-autor-map.txt https://besharp.svn.codeplex.com/svn BeSharp.net-hg

initializing destination BeSharp.net-hg repository
svn: cannot probe remote repository, assume it could be a subversion repository. Use --source-type if you know better.
scanning source...
sorting...
converting...
108 Created team project folder $/besharp via the Team Project Creation Wizard
107 first publication
106 Base folder structure
105 WordPressGenerateCategoriesHtmlConsoleApplication first draft.
104 Cleaned up code for publication at https://wiert.me/2012/08/22/generating-a-wordpress-posting-categories-page-part-2
103 Towards a category cloud
102 EmptyVisualStudioSolution, see https://wiert.me/2012/09/05/creating-a-blank-visual-studio-solution-without-a-directory-and-sln-format-version-numbers
101 NumberVerificationTestProject: Bankrekeningnummer
100 BSN/SofiNummer and BankrekeningNummer complete.
...
9 Delphi: update to Delphi XE4 of TemporaryCursorDemo.dproj
8 Delphi: update to Delphi XE4 of HResultTests.dproj
7 Delphi: update to Delphi XE4 of HResultTests.dproj
6 Delphi added Library/RTL/WIN directory.
5 Reorganizing the location and name for i18n support in StringResourcesUnit.pas
4 Final location and name for i18n support in StringResourcesUnit.pas
3 Delphi: added LoadStringResource/LoadStringResourceProject.dpr demo with StringResourcesUnit.pas.
2 Delphi: updated AllDelphiNativeBeSharpNet.groupproj to Delphi XE4
1 Delphi: VCLLoggingTests application.
0 SVN: batch files to parse local svn working directories to get repository root URL  or switched directories.
writing author map file C:\Users\Developer\HG\bitbucket.org\jeroenp\BeSharp.net-hg\.hg\authormap

C:\Users\Developer\HG\bitbucket.org\jeroenp>

 

Step three: pushing HG to BitBucket

The first step is to create an empty HG repository at BitBucket. I created min at https://bitbucket.org/jeroenp/besharp.net

After that, it is very simple to put your HG repository on BitBucket. You can push both GIT and HG to empty repositoiees on BitBucket.

This was much faster: The hg convert took a couple of hours. The hg push less than a minute.

Note that jeroenp@bitbucket.org is not my email address. It is part of http basic authentication.

C:\Users\Developer\HG\bitbucket.org\jeroenp\BeSharp.net-hg>hg push https://jeroenp@bitbucket.org/jeroenp/besharp.net
pushing to https://jeroenp@bitbucket.org/jeroenp/besharp.net
searching for changes
http authorization required
realm: Bitbucket.org HTTP
user: jeroenp (fixed in .hg/hgrc)
password:
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 109 changesets with 636 changes to 506 files

 

Step six: update your `hgrc` file with the BitBucket URL

One of the most important files for Mercurial/HG is the .hg\hgrc settings file.

You should at least edit the [paths] section to contain your BitBucket repository URL (the one you pushed it to, see the previous section).

You can edit it like this (let Notepad create a new file if it does not yet exist):

C:\Users\Developer\HG\bitbucket.org\jeroenp\BeSharp.net-hg>notepad .hg\hgrc

 

And make it look like this (the jeroenp@ sets the username for http basic authentication which is secure as the protocol is https):

[paths]
default = https://jeroenp@bitbucket.org/jeroenp/besharp.net

 

Step five: checkout (nah, update!) and get to work

The final step is to checkout your working directory (in hg terms this is called hg update) from within the hg repository then start to work:

C:\Users\Developer\HG\bitbucket.org\jeroenp\BeSharp.net-hg>hg update
460 files updated, 0 files merged, 0 files removed, 0 files unresolved

 

Conclusion

Though there was a long wait for the hg convert to complete, this went a lot smoother than I anticipated.

For bigger repositories, this is not suited, on the other hand the fast alternative (svnsync) does not work with CodePlex, and rsvndump needs patches. I might try hgsubversion in the future, but for now, the above worked.

Time will tell (:

–jeroen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: