- Source Control – Part 1 – Introduction
- Source Control – Part 2 – Installing a Mercurial Client
- Source Control – Part 3 – Installing a local Mercurial Server
If you are going to work as part of a development team that requires its own private repository you will need to install the Mercurial server components. There are a few options for this but my personal choice for a windows development team is to server the Mercurial repository via an IIS web server. This guide assumes you already have IIS installed.
As Mercurial is written in Python you will first need to install Python on your server. To see which version of Python you need you take a look at the available windows download packages at http://bitbucket.org/tortoisehg/thg-winbuild/downloads/. The windows builds come in a number of flavours, some with a standalone version of Python which won’t work as we need to install a number of dependant Python site packages for IIS to serve Mercurial.
Most of the installation information below was found on Matt Hawley’s blog here and is by no means my own, I have added some alternate steps and information at the end as to how I configured my setup.
- Look for the latest Mercurial download ending in win32-pyX.X.exe, in this case mercurial-1.5.4.win32-py2.6.exe meaning Python 2.6 is required. Download the appropriate Mercurial package to use later.
- Now download the appropriate Python version from http://www.python.org/download/releases/ in this case Python 2.6.5.
- Install Python by running the installer and leaving the default directory of c:\Python26\. Make sure you add c:\Python26 to your path.
- Download the PyWin32 a package required to call win32 functions from Python from sourceforge. Run the installer and let it decide the default installation paths for you.
- Install the mercurial-1.5.4.win32-py2.6.exe package we downloaded in the first step and again let the installer decide on the appropriate install paths.
- Download the isapi-wsgi package from http://code.google.com/p/isapi-wsgi/, the appropriate download at this time is isapi_wsgi-0.4.2.win32.exe. Install by running the installer and letting it once again decide the installation paths.
- Next you need to get the Python script hgwebdir_wsgi.py however this is only available in the source package of Mercurial. The simplest way to get it is to point your web browser at http://selenic.com/repo/hg-stable/then click browse on left menu and then choose the contrib directory, followed by the win32 directory, you should be at a page as below.
right click the hgwebdir_wsgi.py file and save it to your local machine.
- Create a directory for your website which will host your Mercurial website in IIS such as c:\inetpub\wwwroot\hg
- Copy hgwebdir_wsgi.py into this directory.
- Create a directory where you will store your Mercurial code repositories such as c:\repositories\
Create a file called hgweb.config in a text editor with the following content
c:\repositories\ = c:\repositories\
and save it in your Mercurial website directory (c:\inetpub\wwwroot\hg in the example).
- Open the hgwebdir_wsgi.py file in a text editor and find the following substituting your own path# Configuration file location
hgweb_config = r’C:\inetpub\wwwroot\hg\hgweb.config’
- Open a command prompt and change to your Mercurial website directory and run the following command python hgwebdir_wsgi.py which will generate a DLL shim called _hgwebdir_wsgi.dll.
- Open the IIS management console and create a new application pool called Mercurial, set the .Net Framework Version to “No Managed Code”, leave the pipeline as Integrated Mode. If you are running a 64bit operating system be sure to open the advanced properties and set Enable 32-Bit Applications to True.
- Browse to your hg directory (or whatever you called your Mercurial website) under the Default Web Site Node and right click and choose convert to application. Be sure to select your newly created Mercurial App Pool as the applications default.
- Open the Handler Mappings for you new application (not the default web sites mappings!).
- Add a new “Wildcard Script Map” with the executable location pointing to the _hgwebdir_wsgi.dll in your Mercurial web directory, calling it something like Mercurial-ISAPI.
- Click OK and when it prompts you to allow this ISAPI extension, click “Yes”
- If you now browse to your Mercurial website at http://localhost/hgyou should see the following
- Now lets add a Mercurial repository, we will add the Mercurial source itself as an example using TortoiseHg. Using windows explorer browse to c:\Repositories (or whatever you chose as your repository location in step 10), right click and choose TortoiseHg –> clone. Enter the source and destination paths as below and click clone.
- Once done browse to your Mercurial website at http://localhost/hgyou should now see the hg-stable repository visible, which you can browse deeper into by clicking the hg-stable link.
While being able to browse your repositories visually is pretty cool the main reason for setting up the local Mercurial server was to allow pushing and pulling code to a central local repository, At this stage you will be able to pull code over http from your repository by specifying http://localhost/hg/hg-stable in the source path of the TortoiseHg Clone dialog but would not yet be able to commit back. We will cover the configuration steps required for this in part 4 of this article.
As I mentioned before most of these steps are shown in Matt Hawley’s blog post with a few modifications that I made along the way to suit my own preferences.