Patchwork [1,of,3,V2] hook: small refactor to store hooks as dict instead of list

login
register
mail settings
Submitter Pierre-Yves David
Date April 16, 2016, 12:07 a.m.
Message ID <05a113291ff032b9ab98.1460765275@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/14664/
State Accepted
Headers show

Comments

Pierre-Yves David - April 16, 2016, 12:07 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1460626126 25200
#      Thu Apr 14 02:28:46 2016 -0700
# Node ID 05a113291ff032b9ab982761b8b80ca3cc886516
# Parent  8d398155bfda3a98e664af74096f0e405cc7dd09
# EXP-Topic hooks
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.

Patch

diff -r 8d398155bfda -r 05a113291ff0 mercurial/hook.py
--- a/mercurial/hook.py	Mon Feb 29 22:58:15 2016 +0900
+++ 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):