Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hook.py @ 8366:0bf0045000b5
some modernization cleanups, forward compatibility
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Wed, 13 May 2009 14:08:39 +0200 |
parents | b87a50b7125c |
children | 872d49dd577a |
comparison
equal
deleted
inserted
replaced
8365:94e91205d9b6 | 8366:0bf0045000b5 |
---|---|
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 callable(obj): | 24 if not hasattr(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] |
42 obj = getattr(obj, p) | 42 obj = getattr(obj, p) |
43 except AttributeError: | 43 except AttributeError: |
44 raise util.Abort(_('%s hook is invalid ' | 44 raise util.Abort(_('%s hook is invalid ' |
45 '("%s" is not defined)') % | 45 '("%s" is not defined)') % |
46 (hname, funcname)) | 46 (hname, funcname)) |
47 if not callable(obj): | 47 if not hasattr(obj, '__call__'): |
48 raise util.Abort(_('%s hook is invalid ' | 48 raise util.Abort(_('%s hook is invalid ' |
49 '("%s" is not callable)') % | 49 '("%s" is not callable)') % |
50 (hname, funcname)) | 50 (hname, funcname)) |
51 try: | 51 try: |
52 r = obj(ui=ui, repo=repo, hooktype=name, **args) | 52 r = obj(ui=ui, repo=repo, hooktype=name, **args) |
72 def _exthook(ui, repo, name, cmd, args, throw): | 72 def _exthook(ui, repo, name, cmd, args, throw): |
73 ui.note(_("running hook %s: %s\n") % (name, cmd)) | 73 ui.note(_("running hook %s: %s\n") % (name, cmd)) |
74 | 74 |
75 env = {} | 75 env = {} |
76 for k, v in args.iteritems(): | 76 for k, v in args.iteritems(): |
77 if callable(v): | 77 if hasattr(v, '__call__'): |
78 v = v() | 78 v = v() |
79 env['HG_' + k.upper()] = v | 79 env['HG_' + k.upper()] = v |
80 | 80 |
81 if repo: | 81 if repo: |
82 cwd = repo.root | 82 cwd = repo.root |
105 | 105 |
106 try: | 106 try: |
107 for hname, cmd in ui.configitems('hooks'): | 107 for hname, cmd in ui.configitems('hooks'): |
108 if hname.split('.')[0] != name or not cmd: | 108 if hname.split('.')[0] != name or not cmd: |
109 continue | 109 continue |
110 if callable(cmd): | 110 if hasattr(cmd, '__call__'): |
111 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r | 111 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r |
112 elif cmd.startswith('python:'): | 112 elif cmd.startswith('python:'): |
113 if cmd.count(':') == 2: | 113 if cmd.count(':') == 2: |
114 path, cmd = cmd[7:].split(':') | 114 path, cmd = cmd[7:].split(':') |
115 mod = extensions.loadpath(path, 'hgkook.%s' % hname) | 115 mod = extensions.loadpath(path, 'hgkook.%s' % hname) |