From fb08698cc9120cc364084a78e74394798bf4a8a9 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 2 Oct 2012 13:51:27 -0400 Subject: [PATCH] First step in merging in the Mercurial support. --- irkerhook.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ irkerhook.xml | 20 +++++++++++++ 2 files changed, 97 insertions(+) diff --git a/irkerhook.py b/irkerhook.py index ab38de4..5ed90e1 100755 --- a/irkerhook.py +++ b/irkerhook.py @@ -256,6 +256,83 @@ class SvnExtractor(GenericExtractor): 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 diff --git a/irkerhook.xml b/irkerhook.xml index f58c665..b09a745 100644 --- a/irkerhook.xml +++ b/irkerhook.xml @@ -256,6 +256,26 @@ that would have unhappy results. +Mercurial + +NOTE: Mercurial support is currently broken. It is expected +this will be fixed in the next release. + +Under Mercurial, irkerhook.py 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 +hgrc 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 +irker.conf file. + +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. + + + OPTIONS -- 2.26.2