Mercurial’s Web Interface

Funny how some things can turn out to be much easier than you fear. I’d been meaning to make some of my code accessible via a web interface. It turned out to be much easier than I expected.

Getting Apache Setup

I didn’t want to run Mercurial as .cgi script. I’d had some initial problems with mod_python and decided I wanted to try out the newer wsgi interface.

Installing mod_wsgi

mod_wsgi was not installed by default. I went to (software.opensuse.org)[http://software.opensuse.org/search?q=mod_wsgi] to find an RPM. I got it and installed it:

I then needed to activate the wsgi module in apache2:

Configuring Apache

The WSGIScriptAlias directive is similar to the Apache Alias directive in that it specifies either a directory as containg wsgi scripts or in this case that “/hg” should map to the script hgwebdir.wsgi.

Installing hgwebdir.wscgi

You’ll need to copy mercurial’s wsgi script to where you put it in the apache config

You then modify scripts/hgwebdir.wsgi and setup the absolute path to your repository. Something like:

It’s really the assignment to application that matters (as that’s what wsgi uses).

Setting up hgweb

The [web] section sets up defaults for all the repositories.

The [paths] directive combined with the “/**” means to find all mercurial repositories under that directory.

Setting up a project

You can clone any project you’d like to put it under the web interface. The web interface works on the underlying DB so it’s always up to date (wrt to the repository).

If you want people to be able to push to it, everything needs to be owned by the same as the web server. In the case of OpenSuse, that’s wwwrun:

Controlling who can access the project

Within each project. the .hg/hgrc controls who can access it. For example, the following allows a user “testuser” to push. I allow push to not happen over ssl. Probably not the best idea but this isn’t critical software.

The above uses apache’s authorization.