[PATCH 1 of 2] hooks: print out more information when loading a python hook fails

Simon Heimberg simohe at besonet.ch
Wed Jul 4 01:49:41 CDT 2012


# HG changeset patch
# User Simon Heimberg <simohe at besonet.ch>
# Date 1341381671 -7200
# Node ID 50fd5d8ba5552dc75585c576d4d3b82987b21f99
# Parent  fba17a64fa4978bfea19222da5e64a18cfddeecd
hooks: print out more information when loading a python hook fails

diff -r fba17a64fa49 -r 50fd5d8ba555 mercurial/extensions.py
--- a/mercurial/extensions.py	Fre Jun 29 00:40:52 2012 -0500
+++ b/mercurial/extensions.py	Mit Jul 04 08:01:11 2012 +0200
@@ -42,7 +42,12 @@
         fd, fpath, desc = imp.find_module(f, [d])
         return imp.load_module(module_name, fd, fpath, desc)
     else:
-        return imp.load_source(module_name, path)
+        try:
+            return imp.load_source(module_name, path)
+        except IOError, exc:
+            if not exc.filename:
+                exc.filename = path # python does not fill this
+            raise
 
 def load(ui, name, path):
     # unused ui argument kept for backwards compatibility
diff -r fba17a64fa49 -r 50fd5d8ba555 mercurial/hook.py
--- a/mercurial/hook.py	Fre Jun 29 00:40:52 2012 -0500
+++ b/mercurial/hook.py	Mit Jul 04 08:01:11 2012 +0200
@@ -169,7 +169,11 @@
                     path = util.expandpath(path)
                     if repo:
                         path = os.path.join(repo.root, path)
-                    mod = extensions.loadpath(path, 'hghook.%s' % hname)
+                    try:
+                        mod = extensions.loadpath(path, 'hghook.%s' % hname)
+                    except Exception, exc:
+                        ui.write(_("loading %s hook failed:\n") % hname)
+                        raise
                     hookfn = getattr(mod, cmd)
                 else:
                     hookfn = cmd[7:].strip()


More information about the Mercurial-devel mailing list