mercurial/localrepo.py
changeset 4070 961ccb615cf7
parent 4060 82eb0fafb56d
child 4118 35b39097c3e6
--- a/mercurial/localrepo.py	Fri Feb 09 03:48:26 2007 -0200
+++ b/mercurial/localrepo.py	Fri Feb 09 03:48:28 2007 -0200
@@ -142,32 +142,34 @@
             be run as hooks without wrappers to convert return values.'''
 
             self.ui.note(_("calling hook %s: %s\n") % (hname, funcname))
-            d = funcname.rfind('.')
-            if d == -1:
-                raise util.Abort(_('%s hook is invalid ("%s" not in a module)')
-                                 % (hname, funcname))
-            modname = funcname[:d]
-            try:
-                obj = __import__(modname)
-            except ImportError:
+            obj = funcname
+            if not callable(obj):
+                d = funcname.rfind('.')
+                if d == -1:
+                    raise util.Abort(_('%s hook is invalid ("%s" not in '
+                                       'a module)') % (hname, funcname))
+                modname = funcname[:d]
                 try:
-                    # extensions are loaded with hgext_ prefix
-                    obj = __import__("hgext_%s" % modname)
+                    obj = __import__(modname)
                 except ImportError:
+                    try:
+                        # extensions are loaded with hgext_ prefix
+                        obj = __import__("hgext_%s" % modname)
+                    except ImportError:
+                        raise util.Abort(_('%s hook is invalid '
+                                           '(import of "%s" failed)') %
+                                         (hname, modname))
+                try:
+                    for p in funcname.split('.')[1:]:
+                        obj = getattr(obj, p)
+                except AttributeError, err:
                     raise util.Abort(_('%s hook is invalid '
-                                       '(import of "%s" failed)') %
-                                     (hname, modname))
-            try:
-                for p in funcname.split('.')[1:]:
-                    obj = getattr(obj, p)
-            except AttributeError, err:
-                raise util.Abort(_('%s hook is invalid '
-                                   '("%s" is not defined)') %
-                                 (hname, funcname))
-            if not callable(obj):
-                raise util.Abort(_('%s hook is invalid '
-                                   '("%s" is not callable)') %
-                                 (hname, funcname))
+                                       '("%s" is not defined)') %
+                                     (hname, funcname))
+                if not callable(obj):
+                    raise util.Abort(_('%s hook is invalid '
+                                       '("%s" is not callable)') %
+                                     (hname, funcname))
             try:
                 r = obj(ui=self.ui, repo=self, hooktype=name, **args)
             except (KeyboardInterrupt, util.SignalInterrupt):
@@ -205,7 +207,9 @@
                  if hname.split(".", 1)[0] == name and cmd]
         hooks.sort()
         for hname, cmd in hooks:
-            if cmd.startswith('python:'):
+            if callable(cmd):
+                r = callhook(hname, cmd) or r
+            elif cmd.startswith('python:'):
                 r = callhook(hname, cmd[7:].strip()) or r
             else:
                 r = runhook(hname, cmd) or r