Patchwork [4,of,6,mergedriver] hook: for python hooks, also return whether an exception was raised

login
register
mail settings
Submitter Siddharth Agarwal
Date Oct. 14, 2015, 11:52 p.m.
Message ID <409747fc77917ef155c9.1444866752@dev6666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/11081/
State Accepted
Commit 8429369eeb850d1eb9243da3367bf1bd9d31f560
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 1444865230 25200
#      Wed Oct 14 16:27:10 2015 -0700
# Node ID 409747fc77917ef155c9c5d5c197056e40f63da9
# Parent  8052f94671f17c5de711949fe628a875e6c1632a
hook: for python hooks, also return whether an exception was raised

The hook code treats python hooks raising an exception and returning True as
the exact same. This is OK for hooks themselves, but other code that wants to
invoke external code using the same underlying code is a bit more interested in
making a distinction.

Patch

diff --git a/mercurial/hook.py b/mercurial/hook.py
--- a/mercurial/hook.py
+++ b/mercurial/hook.py
@@ -101,7 +101,7 @@  def _pythonhook(ui, repo, name, hname, f
         if throw:
             raise
         ui.traceback()
-        return True
+        return True, True
     finally:
         sys.stdout, sys.stderr, sys.stdin = old
         duration = time.time() - starttime
@@ -111,7 +111,7 @@  def _pythonhook(ui, repo, name, hname, f
         if throw:
             raise error.HookAbort(_('%s hook failed') % hname)
         ui.warn(_('warning: %s hook failed\n') % hname)
-    return r
+    return r, False
 
 def _exthook(ui, repo, name, cmd, args, throw):
     ui.note(_("running hook %s: %s\n") % (name, cmd))
@@ -170,7 +170,7 @@  def hook(ui, repo, name, throw=False, **
     res = runhooks(ui, repo, name, hooks, throw=throw, **args)
     r = False
     for hname, cmd in hooks:
-        r = res[hname] or r
+        r = res[hname][0] or r
     return r
 
 def runhooks(ui, repo, name, hooks, throw=False, **args):
@@ -193,7 +193,7 @@  def runhooks(ui, repo, name, hooks, thro
                     pass
 
             if callable(cmd):
-                r = _pythonhook(ui, repo, name, hname, cmd, args, throw)
+                r, raised = _pythonhook(ui, repo, name, hname, cmd, args, throw)
             elif cmd.startswith('python:'):
                 if cmd.count(':') >= 2:
                     path, cmd = cmd[7:].rsplit(':', 1)
@@ -208,11 +208,13 @@  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)
+                r, raised = _pythonhook(ui, repo, name, hname, hookfn, args,
+                                        throw)
             else:
                 r = _exthook(ui, repo, hname, cmd, args, throw)
+                raised = False
 
-            res[hname] = r
+            res[hname] = r, raised
 
             # The stderr is fully buffered on Windows when connected to a pipe.
             # A forcible flush is required to make small stderr data in the