comparison 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
comparison
equal deleted inserted replaced
19209:4b9e5b71dfa9 19211:3bfd7f1e7485
1944 if t.endswith(k): 1944 if t.endswith(k):
1945 return int(float(t[:-len(k)]) * u) 1945 return int(float(t[:-len(k)]) * u)
1946 return int(t) 1946 return int(t)
1947 except ValueError: 1947 except ValueError:
1948 raise error.ParseError(_("couldn't parse size: %s") % s) 1948 raise error.ParseError(_("couldn't parse size: %s") % s)
1949
1950 class hooks(object):
1951 '''A collection of hook functions that can be used to extend a
1952 function's behaviour. Hooks are called in lexicographic order,
1953 based on the names of their sources.'''
1954
1955 def __init__(self):
1956 self._hooks = []
1957
1958 def add(self, source, hook):
1959 self._hooks.append((source, hook))
1960
1961 def __call__(self, *args):
1962 self._hooks.sort(key=lambda x: x[0])
1963 for source, hook in self._hooks:
1964 hook(*args)