Publishing Mercurial Repositories (2/3)
To publish repositories you need the adequate version of Mercurial installed: the one that adds modules to the Python installation. This version is on the regular download page (http://mercurial.selenic.com/downloads/) under the name "source install". It is also here: http://mercurial.selenic.com/wiki/Download#Windows. Because these are Python modules you need to make sure that you have a compatible Python installed i.e. the same version of Python that was used to build the Mercurial modules. In this tutorial we will use Mercurial-2.8 (64-bit py2.7) with Python 2.7.5.
So if you use the machine both to work with repositories and publish them you will have two version of Mercurial installed. There is no problem with that.
Some familiarity with IIS will be a big help during the setup. We do have a basic IIS tutorial here but we will also point you at the particularly relevant pages of this tutorial if you don't want to go through it all.
First you need to create a new website to host the Mercurial repositories or use an existing one (even the default website if you wish). In this tutorial we will use a dedicated website for Mercurial because I think it helps to keep everything well organized and reduces the possibility of a conflict between the configuration required by Mercurial and whatever another website may require. You can find steps about how to add a website to IIS here. Figure 1 shows the settings we have chosen for the website: its name is HgWeb, its contents are in C:\inetpub\hgweb and we used port 8010 to access it (we have the default website running on port 80). Using the port is the easiest way to do it for our example but in practice you would of course use whatever your setup requires.
|Figure 1: Settings for HgWeb website creation|
Figure 2 shows the new website in IIS Manager. Of course the screen will vary depending on your exact IIS setup.
|Figure 2: HgWeb website|
Mercurial relies on the *.cgi extension being associated with Python scripts. Details on how to set this up can be found on this page. Afterwards the handler mapping should looks like the ones on figure 3.
|Figure 3: HgWeb website handler mappings|
Everything is now in place to setup the Mercurial script that publishes repositories and the associated configuration file.
First we need to get the hgweb.cgi script which is harder to find than it should. The easiest way is to go to the Mercurial source code repository at http://selenic.com/repo/hg/tags and select the tag for your particular version of Mercurial (in our case that is 2.8). The hgweb.cgi script is found in the root directory of each Mercurial version. Copy this file to "c:\inetpub\hgweb". For the version of Mecurial used in this tutorial this script looks like this.File: hgweb.cgi
#!/usr/bin/env python # # An example hgweb CGI script, edit as necessary # See also http://mercurial.selenic.com/wiki/PublishingRepositories # Path to repo or hgweb config to serve (see 'hg help hgweb') config = "c:\inetpub\hgweb\hgweb.config" # Uncomment and adjust if Mercurial is not installed system-wide # (consult "installed modules" path from 'hg debuginstall'): #import sys; sys.path.insert(0, "/path/to/python/lib") # Uncomment to send python tracebacks to the browser if an error occurs: #import cgitb; cgitb.enable() from mercurial import demandimport; demandimport.enable() from mercurial.hgweb import hgweb, wsgicgi application = hgweb(config) wsgicgi.launch(application)
In this file I have highlighted the only line we need to customize. It needs to point to the configuration file for your site which in our case is the file "/inetpub/hgweb/hgweb.config". We will discuss the contents of hgweb.config but for now we just create that file and leave it empty. So at the moment the HgWeb website contains two files: hgweb.cgi and hgweb.config. If we open the http://localhost:8010/hgweb.cgi page in a web browser we should see something similar to what is shown in figure 4.
|Figure 4: HgWeb website without any repositories|
No repositories are shown because we didn't tell the hgbweb.cgi script where our repositories are located. This is what we need to add to the configuration file. This is of course assumes that we do have a Mercurial repository somewhere. For this example we will assume we have a repository located in "c:\MercurialRepositories\MyFirstRepository". To create it you can follow the steps in this tutorial. Here is what the configuration file should look like.File: c:\inetpub\hgweb\hgweb.config
[paths] MyFirstRepository = c:\MercurialRepositories\MyFirstRepository
The meaning is straightforward. We just give a list of projects with a chosen display name before the '=' sign and the path of the repository after it. If we navigate to http://localhost:8010/hgweb.cgi again we now should see something similar to figure 5.
|Figure 5: HgWeb website with MyFirstRepository set up|
We are not done yet. The next important step is to review who can access the published repository. We investigate this in the next page of this tutorial.http://mercurial.selenic.com/wiki/HgWebInIisOnWindows
blog comments powered by Disqus