Patchwork [2,of,6,mergedriver] hook: factor out determination of hooks from running them

login
register
mail settings
Submitter Siddharth Agarwal
Date Oct. 14, 2015, 11:52 p.m.
Message ID <cac30541d1702220d373.1444866750@dev6666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/11086/
State Accepted
Commit a930d66a04af7105a546c6a340c1065d0130eebe
Delegated to: Pierre-Yves David
Headers show

Comments

Siddharth Agarwal - Oct. 14, 2015, 11:52 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1444864411 25200
#      Wed Oct 14 16:13:31 2015 -0700
# Node ID cac30541d1702220d3737fc85382ca136cec06d9
# Parent  2a42915e11423eaa1e127e12333a890655c8bb76
hook: factor out determination of hooks from running them

This will allow other code to run a predetermined series of hooks.

Patch

diff --git a/mercurial/hook.py b/mercurial/hook.py
--- a/mercurial/hook.py
+++ b/mercurial/hook.py
@@ -162,14 +162,19 @@  def hook(ui, repo, name, throw=False, **
     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()