comparison mercurial/hook.py @ 31746:0fa30fbccc34

hook: provide hook type information to external hook The python hooks have access to the hook type information. There is not reason for external hook to not be aware of it too. For the record my use case is to make sure a hook script is configured for the right type.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Fri, 31 Mar 2017 11:08:11 +0200
parents 33504b54863e
children aff7b32b3c05
comparison
equal deleted inserted replaced
31745:33504b54863e 31746:0fa30fbccc34
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
116 116
117 def _exthook(ui, repo, name, cmd, args, throw): 117 def _exthook(ui, repo, htype, name, cmd, args, throw):
118 ui.note(_("running hook %s: %s\n") % (name, cmd)) 118 ui.note(_("running hook %s: %s\n") % (name, cmd))
119 119
120 starttime = util.timer() 120 starttime = util.timer()
121 env = {} 121 env = {}
122 122
124 if repo is not None: 124 if repo is not None:
125 tr = repo.currenttransaction() 125 tr = repo.currenttransaction()
126 repo.dirstate.write(tr) 126 repo.dirstate.write(tr)
127 if tr and tr.writepending(): 127 if tr and tr.writepending():
128 env['HG_PENDING'] = repo.root 128 env['HG_PENDING'] = repo.root
129 env['HG_HOOKTYPE'] = htype
129 130
130 for k, v in args.iteritems(): 131 for k, v in args.iteritems():
131 if callable(v): 132 if callable(v):
132 v = v() 133 v = v()
133 if isinstance(v, dict): 134 if isinstance(v, dict):
246 else: 247 else:
247 hookfn = cmd[7:].strip() 248 hookfn = cmd[7:].strip()
248 r, raised = _pythonhook(ui, repo, htype, hname, hookfn, args, 249 r, raised = _pythonhook(ui, repo, htype, hname, hookfn, args,
249 throw) 250 throw)
250 else: 251 else:
251 r = _exthook(ui, repo, hname, cmd, args, throw) 252 r = _exthook(ui, repo, htype, hname, cmd, args, throw)
252 raised = False 253 raised = False
253 254
254 res[hname] = r, raised 255 res[hname] = r, raised
255 256
256 # The stderr is fully buffered on Windows when connected to a pipe. 257 # The stderr is fully buffered on Windows when connected to a pipe.