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

login
register
mail settings
Submitter Pierre-Yves David
Date April 16, 2016, 12:07 a.m.
Message ID <621b96947ee7b411d635.1460765276@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/14665/
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 1460678629 25200
#      Thu Apr 14 17:03:49 2016 -0700
# Node ID 621b96947ee7b411d6353f9281e4419097944b91
# Parent  05a113291ff032b9ab982761b8b80ca3cc886516
# 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.

Patch

diff -r 05a113291ff0 -r 621b96947ee7 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,12 +162,18 @@ 
     return r
 
 def _allhooks(ui):
+    """return a list of (hook-id, cmd) pair sorted by priority"""
+    hooks = _hookitems(ui)
+    return [(k, v) for p, o, k, v in sorted(hooks.values())]
+
+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), name, cmd)
-    return [(k, v) for p, o, k, v in sorted(hooks.values())]
+    return hooks
 
 _redirect = False
 def redirect(state):