def svnlook(self, info):
return do("svnlook %s %s --revision %s" % (shellquote(info), shellquote(self.repository), shellquote(self.id)))
+class HgExtractor(GenericExtractor):
+ "Metadata extraction for the Mercurial version control system."
+ def __init__(self, arguments):
+ # This fiddling with arguments is necessary since the Mercurial hook can
+ # be run in two different ways: either directly via Python (in which
+ # case hg should be pointed to the hg_hook function below) or as a
+ # script (in which case the normal __main__ block at the end of this
+ # file is exercised). In the first case, we already get repository and
+ # ui objects from Mercurial, in the second case, we have to create them
+ # from the root path.
+ if arguments and type(arguments[0]) == type(()):
+ # Called from hg_hook function
+ ui, repo, self.node = arguments[0]
+ arguments = [] # Should not be processed further by do_overrides
+ else:
+ # Called from command line: create repo/ui objects
+ from mercurial import hg, ui as uimod
+
+ repopath = '.'
+ commit = '-1' # i.e. tip
+ for tok in arguments:
+ if tok.startswith('--repository='):
+ repopath = tok[13:]
+ elif tok.startswith('--commit='):
+ commit = tok[9:]
+ ui = uimod.ui()
+ ui.readconfig(os.path.join(repopath, '.hg', 'hgrc'), repopath)
+ repo = hg.repository(ui, repopath)
+ node = repo.lookup(commit)
+
+ GenericExtractor.__init__(self, arguments)
+
+ # Using local imports; not pretty but necessary here
+ from mercurial.node import short
+ from mercurial.templatefilters import person
+
+ if arguments and type(arguments[0]) == type(()):
+ # Called from hg_hook function
+ ui, repo, self.node = arguments[0]
+
+ # Extract global values from the hg configuration file(s)
+ self.project = ui.config('irker', 'project')
+ self.repo = ui.config('irker', 'repo')
+ self.server = ui.config('irker', 'server')
+ self.channels = ui.config('irker', 'channels')
+ self.tcp = str(ui.configbool('irker', 'tcp')) # converted to bool again in do_overrides
+ self.template = '%(bold)s%(project)s:%(reset)s %(green)s%(author)s%(reset)s %(repo)s:%(yellow)s%(branch)s%(reset)s * %(bold)s%(rev)s%(reset)s / %(bold)s%(files)s%(reset)s: %(logmsg)s %(brown)s%(url)s%(reset)s'
+ self.color = str(ui.configbool('irker', 'color'))
+ self.urlprefix = (ui.config('irker', 'urlprefix') or
+ ui.config('web', 'baseurl') or '')
+ if self.urlprefix:
+ self.urlprefix = self.urlprefix.rstrip('/') + '/rev'
+ # self.commit is appended to this by do_overrides
+ if not self.project:
+ self.project = os.path.basename(repo.root.rstrip('/'))
+
+ # Extract commit-specific values from a "context" object
+ ctx = repo.changectx(node)
+ self.commit = short(node)
+ self.rev = '%d:%s' % (ctx.rev(), self.commit)
+ self.branch = ctx.branch()
+ self.author = person(ctx.user())
+ self.logmsg = ctx.description()
+
+ st = repo.status(ctx.p1().node(), ctx.node())
+ self.files = ' '.join(st[0] + st[1] + st[2])
+
+ self.do_overrides()
+
+def hg_hook(ui, repo, _hooktype, node=None, _url=None, **_kwds):
+ # To be called from a Mercurial "commit" or "incoming" hook. Example
+ # configuration:
+ # [hooks]
+ # incoming.irker = python:/path/to/irkerhook.py:hg_hook
+ extractor = HgExtractor([(ui, repo, node)])
+ generate_and_send(extractor)
+
if __name__ == "__main__":
notify = True
repository = None
</refsect2>
+<refsect2 id="hg"><title>Mercurial</title>
+
+<para>NOTE: Mercurial support is currently broken. It is expected
+this will be fixed in the next release.</para>
+
+<para>Under Mercurial, <application>irkerhook.py</application> can be
+invoked in two ways: either as a Python hook (preferred) or as a
+script. As for git, in both cases all variables may be set in the repo
+<filename>hgrc</filename> file in an [irker] section. Command-line
+variable=value arguments are accepted but not required for script
+invocation. No attempt is made to interpret an
+<filename>irker.conf</filename> file.</para>
+
+<para>The default value of the "project" variable is the basename
+of the repository directory. The default value of the "urlprefix"
+variable is the value of the "web.baseurl" config value, if it
+exists.</para>
+
+</refsect2>
+
</refsect1>
<refsect1 id='options'><title>OPTIONS</title>