Using Mercurial (and Lightppd)

08 April 2010
This is a follow-on from my previous article where I discussed distributed revision control and basically panned Git for being baroque. I have now tried Mercurial, and although it is not as sophisticated as Git, it is a lot easier to get started with. Main thing seems to be that Git has better support for experimental (i.e. throwaway) branches, whereas Mercurial expects you to clone the repository and push/pull the changes if you want to keep them.

Lighttpd setup

Although I find Lighty not quite flexible enough for production web-servers, I still use it for my internal development web-server due to ease of setup. I put Mercurial on its own virtual-host as it results in shorter URLs and a more self-contained setup (my LAN has an internal name-server, but you could also use /etc/hosts). This setup is simpler than that in the Lighty Wiki..

$HTTP["host"] == "hg.filestore.lan" { dir-listing.activate = "disable" dir-listing.encoding = "utf-8" server.document-root = "/home/www/hg/" cgi.assign += ( ".cgi" => "" ) auth.require = ( "" => ( "method" => "basic", "realm" => "Maus", "require" => "valid-user" ) ) auth.backend = "htpasswd" auth.backend.htpasswd.userfile = "/home/www/hg/htpasswd.txt" url.rewrite-once = ( "^/hgwebdir\.cgi/(.*)" => "/hgwebdir.cgi/$1", "^/(.*)" => "/hgwebdir.cgi/$1" ) }

Authentication is needed for all access, rather than just repository pushes, and I have also rigged it so that if hgwebdir.cgi is missing from the URL it is transparently added.

Cloning repositories from the central store

As a result of the rewrite-once above, both the following work:

hg clone http://hg.filestore.lan/hgwebdir.cgi/project1 project1 hg clone http://hg.filestore.lan/project1 project1

Adding local repositories to the central store

If you want to add a local repository to the central store, you can run these two commands (watch out for the line wrap):

hg clone . ssh://remy@filestore.lan//home/www/hg/projectx ssh root@mausoleum.lan "echo -e '\n[web]\npush_ssl = false\nallow_push = *\n' >> /home/www/hg/projectx/.hg/hgrc"

The second command creates the .hg/hgrc entries needed for pushes via (non-SSL) HTTP for anyone who can get past Lighty's authentication. In practice you might want to give specific username(s) rather than ‘*’.


Although for now I am sticking with Subversion for my existing software projects, I would definitely use Mercurial for any new projects involving other people. I have also started using it for some of my websites. Unlike Subversion, Mercurial also supports proper tags, but I have not tried them out.