Patchwork [2,of,3] hook: split config reading further

login
register
mail settings
Submitter Pierre-Yves David
Date April 15, 2016, 7:50 a.m.
Message ID <41e1d17cdc4943805d5e.1460706621@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/14637/
State Superseded
Headers show

Comments

Pierre-Yves David - April 15, 2016, 7:50 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1460678629 25200
#      Thu Apr 14 17:03:49 2016 -0700
# Node ID 41e1d17cdc4943805d5e7a6e7c131367eb94e8d3
# Parent  063993ec1c63c22ff616609001b50292668bd92e
# EXP-Topic hooks
hook: split config reading further

We want an easy way to fetch the hook config with and without honoring
"trusted" so that we can compare the values. So we extra the part retriving raw
hook data from the config to be able to call it twice in the next patch.
timeless - April 15, 2016, 1:11 p.m.
> So we extra the part retriving raw

Err extract retrieving

Patch

diff -r 063993ec1c63 -r 41e1d17cdc49 mercurial/hook.py
--- a/mercurial/hook.py	Thu Apr 14 02:28:46 2016 -0700
+++ b/mercurial/hook.py	Thu Apr 14 17:03:49 2016 -0700
@@ -162,13 +162,19 @@ 
     return r
 
 def _allhooks(ui):
+    """return a list of (hook-id, cmd) pair sorted by priority"""
+    hooks = _hookitems(ui)
+    order = sorted(hooks, key=lambda x: hooks[x][:2] + (x,))
+    return [(k, hooks[k][2]) for k in order]
+
+def _hookitems(ui):
+    """return all hooks items ready to be sorted"""
     hooks = {}
     for name, cmd in ui.configitems('hooks'):
         if not name.startswith('priority'):
             priority = ui.configint('hooks', 'priority.%s' % name, 0)
             hooks[name] = (-priority, len(hooks), cmd)
-    order = sorted(hooks, key=lambda x: hooks[x][:2] + (x,))
-    return [(k, hooks[k][2]) for k in order]
+    return hooks
 
 _redirect = False
 def redirect(state):