From patchwork Tue May 14 18:24:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1,of,5] summary: augment output with info from extensions From: Bryan O'Sullivan X-Patchwork-Id: 1636 Message-Id: <50703ffc65cfec6e37f3.1368555867@australite.thefacebook.com> To: mercurial-devel@selenic.com Date: Tue, 14 May 2013 11:24:27 -0700 # HG changeset patch # User Bryan O'Sullivan # Date 1368555795 25200 # Tue May 14 11:23:15 2013 -0700 # Node ID 50703ffc65cfec6e37f31c74da5e2acf22c9ac08 # Parent d77922fd8798acbf6daa0435eb7a7b1c13e3918b summary: augment output with info from extensions diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -2082,3 +2082,6 @@ def command(table): return decorator return cmd + +# a list of (ui, repo) functions called by commands.summary +summaryhooks = util.hooks() diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -5485,6 +5485,8 @@ def summary(ui, repo, **opts): ui.write(_('update: %d new changesets, %d branch heads (merge)\n') % (new, len(bheads))) + cmdutil.summaryhooks(ui, repo) + if opts.get('remote'): t = [] source, branches = hg.parseurl(ui.expandpath('default')) diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -1946,3 +1946,19 @@ def sizetoint(s): return int(t) except ValueError: raise error.ParseError(_("couldn't parse size: %s") % s) + +class hooks(object): + '''A collection of hook functions that can be used to extend a + function's behaviour. Hooks are called in lexicographic order, + based on the names of their sources.''' + + def __init__(self): + self._hooks = [] + + def add(self, source, hook): + self._hooks.append((source, hook)) + + def __call__(self, *args): + self._hooks.sort(key=lambda x: x[0]) + for source, hook in self._hooks: + hook(*args)