hgwebdir fastcgi

general = { about, articles, links, projects }     meta = { date-posted: 2007-01-30 }

Pointless Background

I use Mercurial as my SCM. It works great.

Oh No!

One way to post a repository, is to use a cgi script. The setup of the script is outlined in the Mercurial Wiki on the HgWebDirStepByStep page.

That is all fine and good, but cgi can be a bit pokey. I wanted to use fastcgi!

I had previously installed Mercurial in my user home directory. I talked about that in installing-mercurial-on-dreamhost. I had also gotten the cgi version working well (reference the Wiki link above if needed).

What I did

  1. I ssh'd into my dreamhost account.

  2. I downloaded fcgi.py into my user python lib directory.
    wget http://svn.saddi.com/py-lib/trunk/fcgi.py

  3. I modified the hgwebdir.cgi, and created it as dispatch.fcgi.

    #!/usr/bin/env python
    import sys
    sys.path.insert(0, "/path/to/user/python/lib/directory/")
    from mercurial.hgweb.hgwebdir_mod import hgwebdir
    from mercurial.hgweb.request import wsgiapplication
    from fcgi import WSGIServer
    
    def make_web_app():
       return hgwebdir('/path/to/hgweb.config')
    
    WSGIServer(wsgiapplication(make_web_app)).run()
    
  4. I modified my .htaccess rewrite rules.

  5. Bob's your uncle.

Hidden Bonus

To help speed things up a bit more, I also moved the static files out of the mercurial template directory, and modified the template to point to the directory I placed them in on the webserver.

This means the webserver can send those files itself, without having to pull them through the fastcgi instance.