[PATCH] hooks: use python 2.4 compatible exception handling
Lee Cantey
lcantey at gmail.com
Fri Jul 22 10:05:40 CDT 2011
# HG changeset patch
# User Lee Cantey <lcantey at gmail.com>
# Date 1311347027 25200
# Node ID 1084477376d46f698251de19a9a04e95935b4a0f
# Parent 86873110bac10010a6563835fa3b87f3aa1b85fe
hooks: use python 2.4 compatible exception handling
diff -r 86873110bac1 -r 1084477376d4 mercurial/hook.py
--- a/mercurial/hook.py Fri Jul 22 07:53:08 2011 -0700
+++ b/mercurial/hook.py Fri Jul 22 08:03:47 2011 -0700
@@ -65,26 +65,27 @@
'("%s" is not callable)') %
(hname, funcname))
try:
- # redirect IO descriptors the the ui descriptors so hooks that write
- # directly to these don't mess the command protocol when running through
- # the command server
- old = sys.stdout, sys.stderr, sys.stdin
- sys.stdout, sys.stderr, sys.stdin = ui.fout, ui.ferr, ui.fin
+ try:
+ # redirect IO descriptors the the ui descriptors so hooks
+ # that write directly to these don't mess up the command
+ # protocol when running through the command server
+ old = sys.stdout, sys.stderr, sys.stdin
+ sys.stdout, sys.stderr, sys.stdin = ui.fout, ui.ferr, ui.fin
- r = obj(ui=ui, repo=repo, hooktype=name, **args)
- except KeyboardInterrupt:
- raise
- except Exception, exc:
- if isinstance(exc, util.Abort):
- ui.warn(_('error: %s hook failed: %s\n') %
- (hname, exc.args[0]))
- else:
- ui.warn(_('error: %s hook raised an exception: '
- '%s\n') % (hname, exc))
- if throw:
+ r = obj(ui=ui, repo=repo, hooktype=name, **args)
+ except KeyboardInterrupt:
raise
- ui.traceback()
- return True
+ except Exception, exc:
+ if isinstance(exc, util.Abort):
+ ui.warn(_('error: %s hook failed: %s\n') %
+ (hname, exc.args[0]))
+ else:
+ ui.warn(_('error: %s hook raised an exception: '
+ '%s\n') % (hname, exc))
+ if throw:
+ raise
+ ui.traceback()
+ return True
finally:
sys.stdout, sys.stderr, sys.stdin = old
if r:
More information about the Mercurial-devel
mailing list