Mercurial > public > mercurial-scm > hg-stable
diff mercurial/hook.py @ 15896:30c34fde40cc
hooks: prioritize run order of hooks
As of Mercurial 1.3, hooks are sorted in the order they are read into
Mercurial. There are many instances when someone may want the hooks
sorted in a specific order; this patch allows prioritizing hooks, while
maintaining the existing enumeration for hooks without a priority.
author | Matt Zuba <matt.zuba@goodwillaz.org> |
---|---|
date | Sun, 15 Jan 2012 13:50:12 -0700 |
parents | 8b011ededfb2 |
children | 15d4d475de9e |
line wrap: on
line diff
--- a/mercurial/hook.py Sun Jan 15 18:00:01 2012 -0600 +++ b/mercurial/hook.py Sun Jan 15 13:50:12 2012 -0700 @@ -124,6 +124,14 @@ ui.warn(_('warning: %s hook %s\n') % (name, desc)) return r +def _allhooks(ui): + hooks = [] + for name, cmd in ui.configitems('hooks'): + if not name.startswith('priority'): + priority = ui.configint('hooks', 'priority.%s' % name, 0) + hooks.append((-priority, len(hooks), name, cmd)) + return [(k, v) for p, o, k, v in sorted(hooks)] + _redirect = False def redirect(state): global _redirect @@ -147,7 +155,7 @@ pass try: - for hname, cmd in ui.configitems('hooks'): + for hname, cmd in _allhooks(ui): if hname.split('.')[0] != name or not cmd: continue if util.safehasattr(cmd, '__call__'):