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.
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:
www# wget http://download.opensuse.org/repositories/Apache:/Modules/openSUSE_11.1/i586/apache2-mod_wsgi-2.5-1.1.i586.rpm
www# rpm -i apache2-mod_wsgi-2.5-1.1.i586.rpm
I then needed to activate the wsgi module in apache2:
www# a2enmod wsgi
www# /etc/init.d/apache restart
WSGIScriptAlias /hg /path-to-repository/scripts/hgwebdir.wsgi
Allow from all
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.
You’ll need to copy mercurial’s wsgi script to where you put it in the apache config
cp path-to-mercurial-source/mercurial-1.2.1/contrib/hgwebdir.wsgi /path-to-repository/scripts
You then modify scripts/hgwebdir.wsgi and setup the absolute path to your repository. Something like:
CONFIG = '/path-to-repository/hgweb.config'
application = hgwebdir(CONFIG)
It’s really the assignment to application that matters (as that’s what wsgi uses).
Setting up hgweb
style = gitweb
contact = Pete Ware
/ = /path-to-repository/**
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).
# cd /path-to-repository
# hg clone /orig-repository project
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:
# cd /path-to-repository/
# chown -R wwwrun project
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.
allow_push = testuser
push_ssl = false
The above uses apache’s authorization.