[PATCH] interhg: extension for hyperlink to BTS in changeset and changelog

Matt Mackall mpm at selenic.com
Sun Jun 17 18:48:12 CDT 2007


On Mon, Jun 18, 2007 at 12:59:42AM +0900, OHASHI Hideya wrote:
> --- a/mercurial/hgweb/hgweb_mod.py	Wed Jun 13 13:15:53 2007 -0500
> +++ b/mercurial/hgweb/hgweb_mod.py	Mon Jun 18 00:57:09 2007 +0900
> @@ -11,7 +11,7 @@ from mercurial.node import *
>  from mercurial.node import *
>  from mercurial.i18n import gettext as _
>  from mercurial import mdiff, ui, hg, util, archival, streamclone, patch
> -from mercurial import revlog, templater
> +from mercurial import revlog, templater, extensions
>  from common import get_mtime, staticfile, style_map, paritygen
>  
>  def _up(p):
> @@ -78,6 +78,11 @@ class hgweb(object):
>          self.templatepath = self.config("web", "templates",
>                                          templater.templatepath(),
>                                          untrusted=False)
> +        self.interhg = None
> +        try:
> +            self.interhg = extensions.find('interhg')
> +        except KeyError:
> +            pass

This is backwards. No part of Mercurial should know about a particular
extension! The extension instead needs to find a way to modify the
behaviour of Mercurial without Mercurial's help.

For instance, the extension can do something like:

from mercurial.hgweb import hgweb_mod

origfunc = hgweb_mod.hgweb.changelog

def myfilter(self, ctx, shortlog):
    res = origfunc(self, ctx, shortlog)
    # change the result
    ...

hgweb_mod.hgweb.changelog = origfunc

If that doesn't work, you can subclass and replace hgweb_mod.hgweb and
override the relevant functions.

Or you can wrap the templater and detect when it's processing the
"changelog" or "changeset" templates.

-- 
Mathematics is the supreme nostalgia of our time.


More information about the Mercurial-devel mailing list