changeset 26737:a930d66a04af

hook: factor out determination of hooks from running them This will allow other code to run a predetermined series of hooks.
author Siddharth Agarwal <sid0@fb.com>
date Wed, 14 Oct 2015 16:13:31 -0700
parents 143b52fce68e
children 9abc2c921bbd
files mercurial/hook.py
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hook.py	Tue Mar 10 13:19:17 2015 +0100
+++ b/mercurial/hook.py	Wed Oct 14 16:13:31 2015 -0700
@@ -162,14 +162,19 @@
     if not ui.callhooks:
         return False
 
+    hooks = []
+    for hname, cmd in _allhooks(ui):
+        if hname.split('.')[0] == name and cmd:
+            hooks.append((hname, cmd))
+
+    return runhooks(ui, repo, name, hooks, throw=throw, **args)
+
+def runhooks(ui, repo, name, hooks, throw=False, **args):
     r = False
     oldstdout = -1
 
     try:
-        for hname, cmd in _allhooks(ui):
-            if hname.split('.')[0] != name or not cmd:
-                continue
-
+        for hname, cmd in hooks:
             if oldstdout == -1 and _redirect:
                 try:
                     stdoutno = sys.__stdout__.fileno()