Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
15895:933b9ff73750 | 15896:30c34fde40cc |
---|---|
122 if throw: | 122 if throw: |
123 raise util.Abort(_('%s hook %s') % (name, desc)) | 123 raise util.Abort(_('%s hook %s') % (name, desc)) |
124 ui.warn(_('warning: %s hook %s\n') % (name, desc)) | 124 ui.warn(_('warning: %s hook %s\n') % (name, desc)) |
125 return r | 125 return r |
126 | 126 |
127 def _allhooks(ui): | |
128 hooks = [] | |
129 for name, cmd in ui.configitems('hooks'): | |
130 if not name.startswith('priority'): | |
131 priority = ui.configint('hooks', 'priority.%s' % name, 0) | |
132 hooks.append((-priority, len(hooks), name, cmd)) | |
133 return [(k, v) for p, o, k, v in sorted(hooks)] | |
134 | |
127 _redirect = False | 135 _redirect = False |
128 def redirect(state): | 136 def redirect(state): |
129 global _redirect | 137 global _redirect |
130 _redirect = state | 138 _redirect = state |
131 | 139 |
145 except AttributeError: | 153 except AttributeError: |
146 # __stdout/err__ doesn't have fileno(), it's not a real file | 154 # __stdout/err__ doesn't have fileno(), it's not a real file |
147 pass | 155 pass |
148 | 156 |
149 try: | 157 try: |
150 for hname, cmd in ui.configitems('hooks'): | 158 for hname, cmd in _allhooks(ui): |
151 if hname.split('.')[0] != name or not cmd: | 159 if hname.split('.')[0] != name or not cmd: |
152 continue | 160 continue |
153 if util.safehasattr(cmd, '__call__'): | 161 if util.safehasattr(cmd, '__call__'): |
154 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r | 162 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r |
155 elif cmd.startswith('python:'): | 163 elif cmd.startswith('python:'): |