comparison mercurial/hook.py @ 26587:56b2bcea2529

error: get Abort from 'error' instead of 'util' The home of 'Abort' is 'error' not 'util' however, a lot of code seems to be confused about that and gives all the credit to 'util' instead of the hardworking 'error'. In a spirit of equity, we break the cycle of injustice and give back to 'error' the respect it deserves. And screw that 'util' poser. For great justice.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Thu, 08 Oct 2015 12:55:45 -0700
parents d15b279ddade
children 8d1cfd77b64f
comparison
equal deleted inserted replaced
26586:d51c658d3f04 26587:56b2bcea2529
33 obj = funcname 33 obj = funcname
34 funcname = obj.__module__ + "." + obj.__name__ 34 funcname = obj.__module__ + "." + obj.__name__
35 else: 35 else:
36 d = funcname.rfind('.') 36 d = funcname.rfind('.')
37 if d == -1: 37 if d == -1:
38 raise util.Abort(_('%s hook is invalid ("%s" not in ' 38 raise error.Abort(_('%s hook is invalid ("%s" not in '
39 'a module)') % (hname, funcname)) 39 'a module)') % (hname, funcname))
40 modname = funcname[:d] 40 modname = funcname[:d]
41 oldpaths = sys.path 41 oldpaths = sys.path
42 if util.mainfrozen(): 42 if util.mainfrozen():
43 # binary installs require sys.path manipulation 43 # binary installs require sys.path manipulation
61 ui.traceback(e1) 61 ui.traceback(e1)
62 if ui.tracebackflag: 62 if ui.tracebackflag:
63 ui.warn(_('exception from second failed import ' 63 ui.warn(_('exception from second failed import '
64 'attempt:\n')) 64 'attempt:\n'))
65 ui.traceback(e2) 65 ui.traceback(e2)
66 raise util.Abort(_('%s hook is invalid ' 66 raise error.Abort(_('%s hook is invalid '
67 '(import of "%s" failed)') % 67 '(import of "%s" failed)') %
68 (hname, modname)) 68 (hname, modname))
69 sys.path = oldpaths 69 sys.path = oldpaths
70 try: 70 try:
71 for p in funcname.split('.')[1:]: 71 for p in funcname.split('.')[1:]:
72 obj = getattr(obj, p) 72 obj = getattr(obj, p)
73 except AttributeError: 73 except AttributeError:
74 raise util.Abort(_('%s hook is invalid ' 74 raise error.Abort(_('%s hook is invalid '
75 '("%s" is not defined)') % 75 '("%s" is not defined)') %
76 (hname, funcname)) 76 (hname, funcname))
77 if not callable(obj): 77 if not callable(obj):
78 raise util.Abort(_('%s hook is invalid ' 78 raise error.Abort(_('%s hook is invalid '
79 '("%s" is not callable)') % 79 '("%s" is not callable)') %
80 (hname, funcname)) 80 (hname, funcname))
81 81
82 ui.note(_("calling hook %s: %s\n") % (hname, funcname)) 82 ui.note(_("calling hook %s: %s\n") % (hname, funcname))
83 starttime = time.time() 83 starttime = time.time()
89 old = sys.stdout, sys.stderr, sys.stdin 89 old = sys.stdout, sys.stderr, sys.stdin
90 sys.stdout, sys.stderr, sys.stdin = ui.fout, ui.ferr, ui.fin 90 sys.stdout, sys.stderr, sys.stdin = ui.fout, ui.ferr, ui.fin
91 91
92 r = obj(ui=ui, repo=repo, hooktype=name, **args) 92 r = obj(ui=ui, repo=repo, hooktype=name, **args)
93 except Exception as exc: 93 except Exception as exc:
94 if isinstance(exc, util.Abort): 94 if isinstance(exc, error.Abort):
95 ui.warn(_('error: %s hook failed: %s\n') % 95 ui.warn(_('error: %s hook failed: %s\n') %
96 (hname, exc.args[0])) 96 (hname, exc.args[0]))
97 else: 97 else:
98 ui.warn(_('error: %s hook raised an exception: ' 98 ui.warn(_('error: %s hook raised an exception: '
99 '%s\n') % (hname, exc)) 99 '%s\n') % (hname, exc))