Adding Revision Number to Mercurial Web

December 9, 2010

We wanted to be able to see the mercurial repository revision number in the list of commits using mercurial's repository viewer through a web browser.

We were using the gitweb theme, on a Fedora machine.

Finding Files

In /usr/lib/python2.6/site-packages/mercurial/templates are all the template files used by the web interface. As we're using the gitweb theme, we need to look at the files in the gitweb directory.

The key file to look at is map which links names of templates to files or inline html.

Looking through the file there's a template called shortlogentry which maps to some html. In here, we added {rev} which outputs the revision number. We did this at the start of the line, before the date:

shortlogentry = '
  <tr class="parity{parity}">
    <td class="age">{rev} <i>{date|age}</i></td>
    <td><i>{author|person}</i></td>
    <td>
      <a class="list" href="{url}rev/{node|short}{sessionvars%urlparameter}">
        <b>{desc|strip|firstline|escape|nonempty}</b>
       <span class="logtags">{inbranch%inbranchtag}{branches%branchtag}{tags%tagtag}</span>
      </a>
    </td>
    <td class="link" nowrap>
      <a href="{url}rev/{node|short}{sessionvars%urlparameter}">changeset</a> |
...

References

Tags: hg mercurial hgweb