Source Control – Part 3 – Installing a local Mercurial Server

This entry is part 3 of 3 in the series Source Control

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 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.

    1. 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.
    2. Now download the appropriate Python version from in this case Python 2.6.5.
    3. Install Python by running the installer and leaving the default directory of c:\Python26\. Make sure you add c:\Python26 to your path.
    4. 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.
    5. 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.
    6. Download the isapi-wsgi package from, 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.
    7. Next you need to get the Python script however this is only available in the source package of Mercurial. The simplest way to get it is to point your web browser at click browse on left menu and then choose the contrib directory, followed by the win32 directory, you should be at a page as below.image
      right click the file and save it to your local machine.
    8. Create a directory for your website which will host your Mercurial website in IIS such as c:\inetpub\wwwroot\hg
    9. Copy into this directory.
    10. 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 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 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!).image
  • 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.image
  • Click OK and when it prompts you to allow this ISAPI extension, click “Yes”image
  • If you now browse to your Mercurial website at http://localhost/hgyou should see the followingimage
  • 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.image
  • 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.image


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.

Series Navigation<< Source Control – Part 2 – Installing a Mercurial Client
This entry was posted in enterprise-basics and tagged , , . Series: . Bookmark the permalink. Trackbacks are closed, but you can post a comment.


  1. Harry
    Posted August 12, 2010 at 4:24 pm | Permalink

    I have followed this tutorial and when I browse to the site I see the Mercurial Repositories page, but I cannot get any of the Repositories to show up.
    Any ideas on what I missed or did wrong?

    The only difference between mine and yours is that I set the path_prefix=0 as mentioned in Matt’s post.

    Any help would be appreciated.


    • Posted August 12, 2010 at 5:11 pm | Permalink

      Hi Harry, as far as I know for the example I gave where my was located at localhost/hg setting path_prefix=1 would be correct. If your repositories are not showing up I would check the following: 1) That you do indeed have initialised repositories (i.e. they have .hg files in the root of their directories. 2) That those directories are directly beneath the directory you specified in your hgweb.config. 3) That the security user that owns the app pool you are running your mercurial website under has read permissions on your repositories.

      If you still can’t get it working after checking these please send me a message via the contact form and I’ll try help you out via email.

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Skip to toolbar