hook: small refactor to store hooks as dict instead of list
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Thu, 14 Apr 2016 02:28:46 -0700
changeset 28936 44bd37af54e5
parent 28935 a4c5c23de1d3
child 28937 3112c5e18835
hook: small refactor to store hooks as dict instead of list We are about to take untrusted hooks into account (to report them as failures) so we need to rearrange the code a bit to allow config overwriting each other in a later patch.
mercurial/hook.py
--- a/mercurial/hook.py	Fri Apr 15 17:43:47 2016 +0000
+++ b/mercurial/hook.py	Thu Apr 14 02:28:46 2016 -0700
@@ -162,12 +162,12 @@
     return r
 
 def _allhooks(ui):
-    hooks = []
+    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)]
+            hooks[name] = (-priority, len(hooks), name, cmd)
+    return [(k, v) for p, o, k, v in sorted(hooks.values())]
 
 _redirect = False
 def redirect(state):