# HG changeset patch # User Bryan O'Sullivan # Date 1368555795 25200 # Node ID 3bfd7f1e7485d81477a52be101c52c94601132d1 # Parent 4b9e5b71dfa9b427bc73b15ebbcad51c1145b548 summary: augment output with info from extensions diff -r 4b9e5b71dfa9 -r 3bfd7f1e7485 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Thu May 16 16:20:10 2013 -0500 +++ b/mercurial/cmdutil.py Tue May 14 11:23:15 2013 -0700 @@ -2082,3 +2082,6 @@ return decorator return cmd + +# a list of (ui, repo) functions called by commands.summary +summaryhooks = util.hooks() diff -r 4b9e5b71dfa9 -r 3bfd7f1e7485 mercurial/commands.py --- a/mercurial/commands.py Thu May 16 16:20:10 2013 -0500 +++ b/mercurial/commands.py Tue May 14 11:23:15 2013 -0700 @@ -5489,6 +5489,8 @@ 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 -r 4b9e5b71dfa9 -r 3bfd7f1e7485 mercurial/util.py --- a/mercurial/util.py Thu May 16 16:20:10 2013 -0500 +++ b/mercurial/util.py Tue May 14 11:23:15 2013 -0700 @@ -1946,3 +1946,19 @@ 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)