Patchwork [3,of,6,mergedriver] hook.runhooks: return a dict of result values

login
register
mail settings
Submitter Siddharth Agarwal
Date Oct. 14, 2015, 11:52 p.m.
Message ID <8052f94671f17c5de711.1444866751@dev6666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/11082/
State Accepted
Commit 9abc2c921bbd7e0a47503b980e7a2e296d0fd67f
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 1444864787 25200
#      Wed Oct 14 16:19:47 2015 -0700
# Node ID 8052f94671f17c5de711949fe628a875e6c1632a
# Parent  cac30541d1702220d3737fc85382ca136cec06d9
hook.runhooks: return a dict of result values

This will be useful to other calling code that would be interested in what the
individual hooks return.

Patch

diff --git a/mercurial/hook.py b/mercurial/hook.py
--- a/mercurial/hook.py
+++ b/mercurial/hook.py
@@ -167,10 +167,14 @@  def hook(ui, repo, name, throw=False, **
         if hname.split('.')[0] == name and cmd:
             hooks.append((hname, cmd))
 
-    return runhooks(ui, repo, name, hooks, throw=throw, **args)
+    res = runhooks(ui, repo, name, hooks, throw=throw, **args)
+    r = False
+    for hname, cmd in hooks:
+        r = res[hname] or r
+    return r
 
 def runhooks(ui, repo, name, hooks, throw=False, **args):
-    r = False
+    res = {}
     oldstdout = -1
 
     try:
@@ -189,7 +193,7 @@  def runhooks(ui, repo, name, hooks, thro
                     pass
 
             if callable(cmd):
-                r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r
+                r = _pythonhook(ui, repo, name, hname, cmd, args, throw)
             elif cmd.startswith('python:'):
                 if cmd.count(':') >= 2:
                     path, cmd = cmd[7:].rsplit(':', 1)
@@ -204,9 +208,11 @@  def runhooks(ui, repo, name, hooks, thro
                     hookfn = getattr(mod, cmd)
                 else:
                     hookfn = cmd[7:].strip()
-                r = _pythonhook(ui, repo, name, hname, hookfn, args, throw) or r
+                r = _pythonhook(ui, repo, name, hname, hookfn, args, throw)
             else:
-                r = _exthook(ui, repo, hname, cmd, args, throw) or r
+                r = _exthook(ui, repo, hname, cmd, args, throw)
+
+            res[hname] = r
 
             # The stderr is fully buffered on Windows when connected to a pipe.
             # A forcible flush is required to make small stderr data in the
@@ -217,4 +223,4 @@  def runhooks(ui, repo, name, hooks, thro
             os.dup2(oldstdout, stdoutno)
             os.close(oldstdout)
 
-    return r
+    return res