Interface Trac to multiple Hg repositories

Notice: This plugin is deprecated in favor of t:TracMercurial.

Now that TracMercurial supports multiple repositories, this plugin is obsolete. We currently use the following plugin to preserve HgTimelinePlugin-style wiki links:

from genshi.builder import tag

from trac.core import *
from trac.util.datefmt import utc
from trac.util.text import to_unicode, shorten_line
from import format_to_html
from import IWikiSyntaxProvider
from trac.versioncontrol.api import RepositoryManager, NoSuchChangeset

# The component

class MultiRepoWikiFormatting(Component):


    def __init__(self):
        self.rm = RepositoryManager(self.env)
        self.repos = self.rm.get_all_repositories().keys()

    # IWikiSyntaxProvider methods

    def get_wiki_syntax(self):
        return []

    def get_link_resolvers(self):
        for repo in self.repos:
            self.log.debug('Link resolver for %s added' % repo)
            yield repo, self._format_link

    def _format_link(self, formatter, repo, rev, label):
        repo = self.rm.get_repository(repo)
        href = '/changeset/%s/%s' % (rev, repo.reponame)
            cset = repo.get_changeset(rev)
            text = shorten_line(cset.message)
            return tag.a(label, class_='changeset', href=href, title=text)
        except NoSuchChangeset as e:
            text = to_unicode('No such changeset: %s' % rev)
            return tag.a(label, class_='missing changeset', rel='nofollow',
                         href=href, title=text)

If you still use this plugin, I'm happy to field pull requests on Bitbucket (including the above plugin, which I've added to the repository).


HgTimeline is an alternative to the TracMercurial plugin, which makes Mercurial repositories accessible from Trac. TracMercurial provides a very well-done plugin that tries to emulate the standard Subversion interface where it makes sense and diverges from it where Mercurial requires a different feature set. The way Trac currently works, though, means that you can only provide an interface to one Mercurial repository at a time.

This plugin tries to provide access from Trac to several different Mercurial clones (whether they belong to one or more projects). This is done by not using the default Trac browser anymore, and instead linking to external hgweb instances (the web interface provided with Mercurial) from the timeline and through wiki syntax.

Therefore, only use this plugin if you want to connect your Trac to multiple Mercurial clones or projects or if you prefer to use hgweb rather than Trac's own source browser. Additionally, the plugin can be useful for keeping track of Mercurial repositories alongside an existing Subversion repository.

Bugs/Feature Requests

Existing bugs and feature requests for HgTimelinePlugin are here.

If you have any issues, create a new ticket.

Download and Source

This plugin now lives on Bitbucket. It requires Trac 0.11 (and probably some older version of Mercurial).


Sample configuration needed in trac.ini:

trac.versioncontrol.* = disabled
hgtl.* = enabled

web.href =
proj1-user = /home/user/src/proj1
proj2-user = /home/user/src/proj2
proj1-jdoe = /home/jdoe/src/proj1


Author: Dirkjan Ochtman

Last modified 5 years ago Last modified on Mar 4, 2017, 6:13:53 AM