summary: augment output with info from extensions
authorBryan O'Sullivan <bryano@fb.com>
Tue, 14 May 2013 11:23:15 -0700
changeset 19211 3bfd7f1e7485
parent 19209 4b9e5b71dfa9
child 19212 d0ba7022c13b
summary: augment output with info from extensions
mercurial/cmdutil.py
mercurial/commands.py
mercurial/util.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()
--- 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'))
--- 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)