comparison mercurial/hook.py @ 14916:58f97dcbd550 stable

hooks: use python 2.4 compatible exception handling
author Lee Cantey <lcantey@gmail.com>
date Fri, 22 Jul 2011 08:03:47 -0700
parents a59058fd074a
children 4a28cb4df1f8 e5b2ee5157ae
comparison
equal deleted inserted replaced
14915:28edd65000d9 14916:58f97dcbd550
63 if not hasattr(obj, '__call__'): 63 if not hasattr(obj, '__call__'):
64 raise util.Abort(_('%s hook is invalid ' 64 raise util.Abort(_('%s hook is invalid '
65 '("%s" is not callable)') % 65 '("%s" is not callable)') %
66 (hname, funcname)) 66 (hname, funcname))
67 try: 67 try:
68 # redirect IO descriptors the the ui descriptors so hooks that write 68 try:
69 # directly to these don't mess the command protocol when running through 69 # redirect IO descriptors the the ui descriptors so hooks
70 # the command server 70 # that write directly to these don't mess up the command
71 old = sys.stdout, sys.stderr, sys.stdin 71 # protocol when running through the command server
72 sys.stdout, sys.stderr, sys.stdin = ui.fout, ui.ferr, ui.fin 72 old = sys.stdout, sys.stderr, sys.stdin
73 sys.stdout, sys.stderr, sys.stdin = ui.fout, ui.ferr, ui.fin
73 74
74 r = obj(ui=ui, repo=repo, hooktype=name, **args) 75 r = obj(ui=ui, repo=repo, hooktype=name, **args)
75 except KeyboardInterrupt: 76 except KeyboardInterrupt:
76 raise
77 except Exception, exc:
78 if isinstance(exc, util.Abort):
79 ui.warn(_('error: %s hook failed: %s\n') %
80 (hname, exc.args[0]))
81 else:
82 ui.warn(_('error: %s hook raised an exception: '
83 '%s\n') % (hname, exc))
84 if throw:
85 raise 77 raise
86 ui.traceback() 78 except Exception, exc:
87 return True 79 if isinstance(exc, util.Abort):
80 ui.warn(_('error: %s hook failed: %s\n') %
81 (hname, exc.args[0]))
82 else:
83 ui.warn(_('error: %s hook raised an exception: '
84 '%s\n') % (hname, exc))
85 if throw:
86 raise
87 ui.traceback()
88 return True
88 finally: 89 finally:
89 sys.stdout, sys.stderr, sys.stdin = old 90 sys.stdout, sys.stderr, sys.stdin = old
90 if r: 91 if r:
91 if throw: 92 if throw:
92 raise util.Abort(_('%s hook failed') % hname) 93 raise util.Abort(_('%s hook failed') % hname)