# HG changeset patch # User Siddharth Agarwal # Date 1444865230 25200 # Node ID 8429369eeb850d1eb9243da3367bf1bd9d31f560 # Parent 9abc2c921bbd7e0a47503b980e7a2e296d0fd67f 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. diff -r 9abc2c921bbd -r 8429369eeb85 mercurial/hook.py --- a/mercurial/hook.py Wed Oct 14 16:19:47 2015 -0700 +++ b/mercurial/hook.py Wed Oct 14 16:27:10 2015 -0700 @@ -101,7 +101,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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