comparison mercurial/hook.py @ 31747:f243b7fbeba5

hook: use "htype" as variable name in _pythonhook We rename 'name' to 'htype' because it fits the variable content better. Multiple python hooks already use 'htype' as a name for the argument. This makes the difference with "hname" clearer and the code less error prone.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Fri, 31 Mar 2017 10:59:37 +0200
parents a48c6ac5c13a
children f610c3220eec
comparison
equal deleted inserted replaced
31746:728d37353e1e 31747:f243b7fbeba5
17 extensions, 17 extensions,
18 pycompat, 18 pycompat,
19 util, 19 util,
20 ) 20 )
21 21
22 def _pythonhook(ui, repo, name, hname, funcname, args, throw): 22 def _pythonhook(ui, repo, htype, hname, funcname, args, throw):
23 '''call python hook. hook is callable object, looked up as 23 '''call python hook. hook is callable object, looked up as
24 name in python module. if callable returns "true", hook 24 name in python module. if callable returns "true", hook
25 fails, else passes. if hook raises exception, treated as 25 fails, else passes. if hook raises exception, treated as
26 hook failure. exception propagates if throw is "true". 26 hook failure. exception propagates if throw is "true".
27 27
88 88
89 ui.note(_("calling hook %s: %s\n") % (hname, funcname)) 89 ui.note(_("calling hook %s: %s\n") % (hname, funcname))
90 starttime = util.timer() 90 starttime = util.timer()
91 91
92 try: 92 try:
93 r = obj(ui=ui, repo=repo, hooktype=name, **args) 93 r = obj(ui=ui, repo=repo, hooktype=htype, **args)
94 except Exception as exc: 94 except Exception as exc:
95 if isinstance(exc, error.Abort): 95 if isinstance(exc, error.Abort):
96 ui.warn(_('error: %s hook failed: %s\n') % 96 ui.warn(_('error: %s hook failed: %s\n') %
97 (hname, exc.args[0])) 97 (hname, exc.args[0]))
98 else: 98 else:
105 ui.traceback() 105 ui.traceback()
106 return True, True 106 return True, True
107 finally: 107 finally:
108 duration = util.timer() - starttime 108 duration = util.timer() - starttime
109 ui.log('pythonhook', 'pythonhook-%s: %s finished in %0.2f seconds\n', 109 ui.log('pythonhook', 'pythonhook-%s: %s finished in %0.2f seconds\n',
110 name, funcname, duration) 110 htype, funcname, duration)
111 if r: 111 if r:
112 if throw: 112 if throw:
113 raise error.HookAbort(_('%s hook failed') % hname) 113 raise error.HookAbort(_('%s hook failed') % hname)
114 ui.warn(_('warning: %s hook failed\n') % hname) 114 ui.warn(_('warning: %s hook failed\n') % hname)
115 return r, False 115 return r, False