Patchwork [stable] hook: disable demandimport before importing hooks

login
register
mail settings
Submitter Dirkjan Ochtman
Date Dec. 17, 2012, 11:45 a.m.
Message ID <50352cc4c0560f1e3e49.1355744707@hertz>
Download mbox | patch
Permalink /patch/150/
State Superseded
Commit d7c28954d9010d639de9ea856c29ff3889440c3f
Headers show

Comments

Dirkjan Ochtman - Dec. 17, 2012, 11:45 a.m.
# HG changeset patch
# User Dirkjan Ochtman <dirkjan at ochtman.nl>
# Date 1355744565 -3600
# Node ID 50352cc4c0560f1e3e49c78c8070a5dadac950c8
# Parent  e853d27956fb0a25dcaac29b18bb0d5719297830
hook: disable demandimport before importing hooks
Kevin Bullock - Dec. 17, 2012, 4:25 p.m.
On Dec 17, 2012, at 5:45 AM, Dirkjan Ochtman wrote:

> # HG changeset patch
> # User Dirkjan Ochtman <dirkjan at ochtman.nl>
> # Date 1355744565 -3600
> # Node ID 50352cc4c0560f1e3e49c78c8070a5dadac950c8
> # Parent  e853d27956fb0a25dcaac29b18bb0d5719297830
> hook: disable demandimport before importing hooks

Why is it needed? What problem does it fix?

pacem in terris / ??? / ?????? / ????????? / ??
Kevin R. Bullock
Kevin Bullock - Dec. 17, 2012, 4:25 p.m.
On Dec 17, 2012, at 10:25 AM, Kevin Bullock wrote:

> On Dec 17, 2012, at 5:45 AM, Dirkjan Ochtman wrote:
> 
>> # HG changeset patch
>> # User Dirkjan Ochtman <dirkjan at ochtman.nl>
>> # Date 1355744565 -3600
>> # Node ID 50352cc4c0560f1e3e49c78c8070a5dadac950c8
>> # Parent  e853d27956fb0a25dcaac29b18bb0d5719297830
>> hook: disable demandimport before importing hooks
> 
> Why is it needed? What problem does it fix?

Nevermind, just saw your other message.

pacem in terris / ??? / ?????? / ????????? / ??
Kevin R. Bullock

Patch

diff --git a/mercurial/hook.py b/mercurial/hook.py
--- a/mercurial/hook.py
+++ b/mercurial/hook.py
@@ -7,7 +7,7 @@ 
 
 from i18n import _
 import os, sys
-import extensions, util
+import extensions, util, demandimport
 
 def _pythonhook(ui, repo, name, hname, funcname, args, throw):
     '''call python hook. hook is callable object, looked up as
@@ -35,13 +35,17 @@ 
                 sys.path = sys.path[:] + [modpath]
                 modname = modfile
         try:
+            demandimport.disable()
             obj = __import__(modname)
+            demandimport.enable()
         except ImportError:
             e1 = sys.exc_type, sys.exc_value, sys.exc_traceback
             try:
                 # extensions are loaded with hgext_ prefix
                 obj = __import__("hgext_%s" % modname)
+                demandimport.enable()
             except ImportError:
+                demandimport.enable()
                 e2 = sys.exc_type, sys.exc_value, sys.exc_traceback
                 if ui.tracebackflag:
                     ui.warn(_('exception from first failed import attempt:\n'))