diff mercurial/hook.py @ 31751: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
line wrap: on
line diff
--- a/mercurial/hook.py	Fri Mar 31 11:06:42 2017 +0200
+++ b/mercurial/hook.py	Fri Mar 31 11:08:11 2017 +0200
@@ -114,7 +114,7 @@
         ui.warn(_('warning: %s hook failed\n') % hname)
     return r, False
 
-def _exthook(ui, repo, name, cmd, args, throw):
+def _exthook(ui, repo, htype, name, cmd, args, throw):
     ui.note(_("running hook %s: %s\n") % (name, cmd))
 
     starttime = util.timer()
@@ -126,6 +126,7 @@
         repo.dirstate.write(tr)
         if tr and tr.writepending():
             env['HG_PENDING'] = repo.root
+    env['HG_HOOKTYPE'] = htype
 
     for k, v in args.iteritems():
         if callable(v):
@@ -248,7 +249,7 @@
                 r, raised = _pythonhook(ui, repo, htype, hname, hookfn, args,
                                         throw)
             else:
-                r = _exthook(ui, repo, hname, cmd, args, throw)
+                r = _exthook(ui, repo, htype, hname, cmd, args, throw)
                 raised = False
 
             res[hname] = r, raised