Mercurial > hg
changeset 26739:8429369eeb85
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.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Wed, 14 Oct 2015 16:27:10 -0700 |
parents | 9abc2c921bbd |
children | f4a27c05c43f |
files | mercurial/hook.py |
diffstat | 1 files changed, 8 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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