Online Book Reader

Home Category

Mercurial_ The Definitive Guide - Bryan O'Sullivan [49]

By Root 947 0
the Apache section). I first had to edit the mod_access section of its config file to enable mod_cgi and mod_userdir, both of which were disabled by default on my system. I then added a few lines to the end of the config file, to configure these modules.

userdir.path = "public_html"

cgi.assign = (".cgi" => "" )

With this done, lighttpd ran immediately for me. If I had configured lighttpd before Apache, I’d almost certainly have run into many of the same system-level configuration problems as I did with Apache. However, I found lighttpd to be noticeably easier to configure than Apache, even though I’ve used Apache for over a decade, and this was my first exposure to lighttpd.

Sharing Multiple Repositories with One CGI Script

The hgweb.cgi script only lets you publish a single repository, which is an annoying restriction. If you want to publish more than one without wracking yourself with multiple copies of the same script, each with a different name, a better choice is to use the hgwebdir.cgi script.

The procedure to configure hgwebdir.cgi is only a little more involved than for hgweb.cgi. First, you must obtain a copy of the script. If you don’t have one handy, you can download a copy from the master Mercurial repository at http://www.selenic.com/repo/hg/raw-file/tip/hgwebdir.cgi.

You’ll need to copy this script into your public_html directory, and ensure that it’s executable.

cp .../hgwebdir.cgi ~/public_html

chmod 755 ~/public_html ~/public_html/hgwebdir.cgi

With basic configuration out of the way, try to visit http://myhostname/~myuser/hgwebdir.cgi in your browser. It should display an empty list of repositories. If you get a blank window or error message, try walking through the list of potential problems described in What could possibly go wrong?.

The hgwebdir.cgi script relies on an external configuration file. By default, it searches for a file named hgweb.config in the same directory as itself. You’ll need to create this file, and make it world-readable. The format of the file is similar to a Windows “ini” file, as understood by Python’s ConfigParser module.

The easiest way to configure hgwebdir.cgi is with a section named collections. This will automatically publish every repository under the directories you name. The section should look like this:

[collections]

/my/root = /my/root

Mercurial interprets this by looking at the directory name on the right-hand side of the equals sign, finding repositories in that directory hierarchy, and using the text on the left-hand side to strip off matching text from the names it will actually list in the web interface. The remaining component of a path after this stripping has occurred is called a “virtual path.”

Given the example above, if we have a repository whose local path is /my/root/this/repo, the CGI script will strip the leading /my/root from the name, and publish the repository with a virtual path of this/repo. If the base URL for our CGI script is http://myhostname/~myuser/hgwebdir.cgi, the complete URL for that repository will be http://myhostname/~myuser/hgwebdir.cgi/this/repo.

If we replace /my/root on the left-hand side of this example with /my, then hgwebdir.cgi will only strip off /my from the repository name, and will give us a virtual path of root/this/repo instead of this/repo.

The hgwebdir.cgi script will recursively search each directory listed in the collections section of its configuration file, but it will not recurse into the repositories it finds.

The collections mechanism makes it easy to publish many repositories in a “fire and forget” manner. You only need to set up the CGI script and configuration file one time. Afterwards, you can publish or unpublish a repository at any time by simply moving it into, or out of, the directory hierarchy in which you’ve configured hgwebdir.cgi to look.

Explicitly specifying which repositories to publish

In addition to the collections mechanism, the hgwebdir.cgi script allows you to publish a specific list of repositories. To do so, create a paths section, with contents of

Return Main Page Previous Page Next Page

®Online Book Reader