mercurial/hook.py
changeset 38041 242eb5132203
parent 37942 32bc3815efae
child 38484 e9e61fbac787
equal deleted inserted replaced
38031:37ef6ee87488 38041:242eb5132203
    22 from .utils import (
    22 from .utils import (
    23     procutil,
    23     procutil,
    24     stringutil,
    24     stringutil,
    25 )
    25 )
    26 
    26 
    27 def _pythonhook(ui, repo, htype, hname, funcname, args, throw):
    27 def pythonhook(ui, repo, htype, hname, funcname, args, throw):
    28     '''call python hook. hook is callable object, looked up as
    28     '''call python hook. hook is callable object, looked up as
    29     name in python module. if callable returns "true", hook
    29     name in python module. if callable returns "true", hook
    30     fails, else passes. if hook raises exception, treated as
    30     fails, else passes. if hook raises exception, treated as
    31     hook failure. exception propagates if throw is "true".
    31     hook failure. exception propagates if throw is "true".
    32 
    32 
   240                         hint = _("see 'hg help config.trusted'"))
   240                         hint = _("see 'hg help config.trusted'"))
   241                 ui.warn(_('warning: untrusted hook %s not executed\n') % hname)
   241                 ui.warn(_('warning: untrusted hook %s not executed\n') % hname)
   242                 r = 1
   242                 r = 1
   243                 raised = False
   243                 raised = False
   244             elif callable(cmd):
   244             elif callable(cmd):
   245                 r, raised = _pythonhook(ui, repo, htype, hname, cmd, args,
   245                 r, raised = pythonhook(ui, repo, htype, hname, cmd, args,
   246                                         throw)
   246                                         throw)
   247             elif cmd.startswith('python:'):
   247             elif cmd.startswith('python:'):
   248                 if cmd.count(':') >= 2:
   248                 if cmd.count(':') >= 2:
   249                     path, cmd = cmd[7:].rsplit(':', 1)
   249                     path, cmd = cmd[7:].rsplit(':', 1)
   250                     path = util.expandpath(path)
   250                     path = util.expandpath(path)
   256                         ui.write(_("loading %s hook failed:\n") % hname)
   256                         ui.write(_("loading %s hook failed:\n") % hname)
   257                         raise
   257                         raise
   258                     hookfn = getattr(mod, cmd)
   258                     hookfn = getattr(mod, cmd)
   259                 else:
   259                 else:
   260                     hookfn = cmd[7:].strip()
   260                     hookfn = cmd[7:].strip()
   261                 r, raised = _pythonhook(ui, repo, htype, hname, hookfn, args,
   261                 r, raised = pythonhook(ui, repo, htype, hname, hookfn, args,
   262                                         throw)
   262                                         throw)
   263             else:
   263             else:
   264                 r = _exthook(ui, repo, htype, hname, cmd, args, throw)
   264                 r = _exthook(ui, repo, htype, hname, cmd, args, throw)
   265                 raised = False
   265                 raised = False
   266 
   266