Moving from ClearCase to Mercurial
By brian. Filed in Uncategorized |My workplace (which shall remain nameless) uses Clear Case for its main source control repository. Unfortunately, due to the network, and physical locations of things, it is exceedingly slow to do anything with. I actually lose my train of though while I wait for files to check out. And don’t even get me started on how long it takes to add any significant number of files (greater than 10) or do a re base and deliver action. It actually means I avoid integrating with my fellow team members as I loathe the time it takes.
To get around this problem, I am in the process of setting up a different source control system, which pushes into clear case. It is quite important for all code to be in the one repository for regulatory reasons. I respect that a lot, but as long as the code get in there on a daily basis, I don’t have any reason not to use something different on my own PC.
There are a number of other teams around the organisation that use Mercurial (or HG), I’m quite happy to try a distributed version control system for a number of reasons, I like trying out shiny new things (even if they aren’t really shiny), I like the idea of consistency across the workplace (for people that move teams), and I like what I’ve seen so far.
So the plan is as follows:
- Setup a Mercurial server on Windows using IIS or SSH
- Setup a CI build that uses Mercurial
- Setup a clear case import that runs daily which also runs the full CI build to validate the clear case import
Today I’m exploring the first option in the Mercurial server on windows. That is via IIS using HGWebDir.cgi.
Install Software
- Install Mercurial 1.3.1 (TortoiseHG is not enough)
- Install Python 2.5.4
(note this needs to be the same as the version that Mercurial was compiled with, or you will receive a “Bad Magic Number” error) - Get a copy of hgwebdir.cgi from the mercurial repository here
http://selenic.com/repo/hg
Put the above file into a directory [hg web root] - Unzip the library.zip (from the mercurial install directory) into
[hg web root]/lib
Note# the zip doesn’t play nice with win zip, try win rar or other zipping tool - Copy the templates directory (from the mercurial install directory) into
[hg web root]/lib/ - Create a file named hgweb.config in the [hg web root] directory
Configure IIS
You need to setup a virtual directory, or IIS website which points to the [hg web root] directory. If you dont know how to do this, search on the net. Its pretty easy in IIS manager. The important thing about this IIS application (weather directory or site) is that it needs to
- default file of “hgwebdir.cgi”
- allow scripts and executables
Once that’s complete, you need to add an application extension for python for cgi files. This varies in different versions of windows. In Server 2003, you need to
- In IIS Manager
- right click the website or virtual directory, and click properties
- go to the “home directory” tab
- click the “configuration” button
- click add under “application extensions” list on the “mappings tab
- The executable should be exactly this
C:\Python25\python.exe -u “%s %s”
Unless you changed the default install directory of python, if so you will need to adjust this - The extension should be .cgi
- Click “script engine”, and unclick “verify that file exists”
- Click OK.
You also need to add the web server extension
- Click “web server extensions” (below websites on the left)
- Right click and hit “Add new web service extension”
- Extension name can be anything I made it “Python 2.4″
- Add a required file of
C:\Python25\python.exe -u “%s %s”Click “Set extension status to Allowed” - Click OK
At this point you can hit your website directory, however you will probably get a CGI error.
Configure HGWebDir.config configuration file
You need to create a [repositories root] directory. I made it C:/Repositories
Update the [hg web root]/hgweb.config file with the following code
[paths] ReposGroup1 = [repositories root]/ReposGroup1/** [web] style = monoblue
This will find all repositorys in the sub directories of [repositories root]/ReposGroup1. You can specify more groups too. I plan to setup one group per project, so my group name is the project, and each branch or version is a hg repository under that.
You can also change the sytle to any style in the [hg web root]/lib/templates directory. Each to his own on this one.
Configure HGWebDir.cgi file
You need to edit [hg web root]/hgwebdir.cgi file.
You need to uncomment and update the following lines (which are in the first few lines)
import sys sys.path.insert(0, "[hg web root]\lib")
Make sure you update the path to point to your [hg web root] directory. So in my case it was
import sys sys.path.insert(0, "C:\Inetpub\mercurial\lib")
Finishing Up
That’s it.
When you this the URL in a web browser, you should get a nice web interface with lots of repository information for all the repositories that are setup in the [repositories root] directory.
If you have trouble, try looking at some of this:
- Ensure you have a valid path in the hgwebdir.config
- Ensure you have installed the correct python version
- Ensure you have the permissions to execute the cgi script, and access the repositories
- http://mercurial.selenic.com/wiki/HgWebDirStepByStep
- http://serverfault.com/questions/9348/how-to-setup-a-mercurial-central-repository-on-a-windows-2008-server
- http://stackoverflow.com/questions/818571/how-to-setup-mercurial-and-hgwebdir-on-iis
To connect in something like TortoiseHg, you use the following style of URL replacing the necessary parts:
http://[server name]/hgwebdir.cgi/[Group]/[RepositoryName]/
Of course once in IIS, you can use SSL to secure it, and I believe there are some native username/password hooks in mercurial itself which allow you to specify who can push changes which work over this kind of server setup. However, you have to use http basic authentication for this to be useful. That’s easier in apache than IIS using the .htaccess system I believe. I didn’t have a need for security for this install.
If security was a concern, you should probably look at installing it under Apache instead, or using SSH, which works quite nicely.
Cheers


