Mercurial > public > mercurial-scm > hg
diff mercurial/util.py @ 19211:3bfd7f1e7485
summary: augment output with info from extensions
author | Bryan O'Sullivan <bryano@fb.com> |
---|---|
date | Tue, 14 May 2013 11:23:15 -0700 |
parents | 1d08df65cd3c |
children | 78501209488a |
line wrap: on
line diff
--- 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)