mercurial/hook.py
changeset 14943 d3bb825ddae3
parent 14941 4a28cb4df1f8
child 14999 f6a737357195
equal deleted inserted replaced
14942:5b072d4b62f2 14943:d3bb825ddae3
    19     unmodified commands (e.g. mercurial.commands.update) can
    19     unmodified commands (e.g. mercurial.commands.update) can
    20     be run as hooks without wrappers to convert return values.'''
    20     be run as hooks without wrappers to convert return values.'''
    21 
    21 
    22     ui.note(_("calling hook %s: %s\n") % (hname, funcname))
    22     ui.note(_("calling hook %s: %s\n") % (hname, funcname))
    23     obj = funcname
    23     obj = funcname
    24     if not hasattr(obj, '__call__'):
    24     if not util.safehasattr(obj, '__call__'):
    25         d = funcname.rfind('.')
    25         d = funcname.rfind('.')
    26         if d == -1:
    26         if d == -1:
    27             raise util.Abort(_('%s hook is invalid ("%s" not in '
    27             raise util.Abort(_('%s hook is invalid ("%s" not in '
    28                                'a module)') % (hname, funcname))
    28                                'a module)') % (hname, funcname))
    29         modname = funcname[:d]
    29         modname = funcname[:d]
    58                 obj = getattr(obj, p)
    58                 obj = getattr(obj, p)
    59         except AttributeError:
    59         except AttributeError:
    60             raise util.Abort(_('%s hook is invalid '
    60             raise util.Abort(_('%s hook is invalid '
    61                                '("%s" is not defined)') %
    61                                '("%s" is not defined)') %
    62                              (hname, funcname))
    62                              (hname, funcname))
    63         if not hasattr(obj, '__call__'):
    63         if not util.safehasattr(obj, '__call__'):
    64             raise util.Abort(_('%s hook is invalid '
    64             raise util.Abort(_('%s hook is invalid '
    65                                '("%s" is not callable)') %
    65                                '("%s" is not callable)') %
    66                              (hname, funcname))
    66                              (hname, funcname))
    67     try:
    67     try:
    68         try:
    68         try:
    97 def _exthook(ui, repo, name, cmd, args, throw):
    97 def _exthook(ui, repo, name, cmd, args, throw):
    98     ui.note(_("running hook %s: %s\n") % (name, cmd))
    98     ui.note(_("running hook %s: %s\n") % (name, cmd))
    99 
    99 
   100     env = {}
   100     env = {}
   101     for k, v in args.iteritems():
   101     for k, v in args.iteritems():
   102         if hasattr(v, '__call__'):
   102         if util.safehasattr(v, '__call__'):
   103             v = v()
   103             v = v()
   104         if isinstance(v, dict):
   104         if isinstance(v, dict):
   105             # make the dictionary element order stable across Python
   105             # make the dictionary element order stable across Python
   106             # implementations
   106             # implementations
   107             v = ('{' +
   107             v = ('{' +
   143 
   143 
   144     try:
   144     try:
   145         for hname, cmd in ui.configitems('hooks'):
   145         for hname, cmd in ui.configitems('hooks'):
   146             if hname.split('.')[0] != name or not cmd:
   146             if hname.split('.')[0] != name or not cmd:
   147                 continue
   147                 continue
   148             if hasattr(cmd, '__call__'):
   148             if util.safehasattr(cmd, '__call__'):
   149                 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r
   149                 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r
   150             elif cmd.startswith('python:'):
   150             elif cmd.startswith('python:'):
   151                 if cmd.count(':') >= 2:
   151                 if cmd.count(':') >= 2:
   152                     path, cmd = cmd[7:].rsplit(':', 1)
   152                     path, cmd = cmd[7:].rsplit(':', 1)
   153                     path = util.expandpath(path)
   153                     path = util.expandpath(path)