Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hook.py @ 20422:aac87f70f38e stable
hooks: only disable/re-enable demandimport when it's already enabled
This fixes an issue introduced in d7c28954d901 where, when disabling
demandimport while running hooks, it's inadvertently re-enabled even when
it was never enabled in the first place.
This doesn't affect normal command line usage of Mercurial; it only matters
when Mercurial is run with demandimport intentionally disabled.
author | Brodie Rao <brodie@sf.io> |
---|---|
date | Mon, 10 Feb 2014 14:51:06 -0800 |
parents | 4f485bd68f1d |
children | 9d9f8ccffead |
comparison
equal
deleted
inserted
replaced
20415:e4d7cbc94219 | 20422:aac87f70f38e |
---|---|
34 # binary installs require sys.path manipulation | 34 # binary installs require sys.path manipulation |
35 modpath, modfile = os.path.split(modname) | 35 modpath, modfile = os.path.split(modname) |
36 if modpath and modfile: | 36 if modpath and modfile: |
37 sys.path = sys.path[:] + [modpath] | 37 sys.path = sys.path[:] + [modpath] |
38 modname = modfile | 38 modname = modfile |
39 demandimportenabled = demandimport.isenabled() | |
40 if demandimportenabled: | |
41 demandimport.disable() | |
39 try: | 42 try: |
40 demandimport.disable() | |
41 obj = __import__(modname) | |
42 demandimport.enable() | |
43 except ImportError: | |
44 e1 = sys.exc_type, sys.exc_value, sys.exc_traceback | |
45 try: | 43 try: |
46 # extensions are loaded with hgext_ prefix | 44 obj = __import__(modname) |
47 obj = __import__("hgext_%s" % modname) | 45 except ImportError: |
46 e1 = sys.exc_type, sys.exc_value, sys.exc_traceback | |
47 try: | |
48 # extensions are loaded with hgext_ prefix | |
49 obj = __import__("hgext_%s" % modname) | |
50 except ImportError: | |
51 e2 = sys.exc_type, sys.exc_value, sys.exc_traceback | |
52 if ui.tracebackflag: | |
53 ui.warn(_('exception from first failed import ' | |
54 'attempt:\n')) | |
55 ui.traceback(e1) | |
56 if ui.tracebackflag: | |
57 ui.warn(_('exception from second failed import ' | |
58 'attempt:\n')) | |
59 ui.traceback(e2) | |
60 raise util.Abort(_('%s hook is invalid ' | |
61 '(import of "%s" failed)') % | |
62 (hname, modname)) | |
63 finally: | |
64 if demandimportenabled: | |
48 demandimport.enable() | 65 demandimport.enable() |
49 except ImportError: | |
50 demandimport.enable() | |
51 e2 = sys.exc_type, sys.exc_value, sys.exc_traceback | |
52 if ui.tracebackflag: | |
53 ui.warn(_('exception from first failed import attempt:\n')) | |
54 ui.traceback(e1) | |
55 if ui.tracebackflag: | |
56 ui.warn(_('exception from second failed import attempt:\n')) | |
57 ui.traceback(e2) | |
58 raise util.Abort(_('%s hook is invalid ' | |
59 '(import of "%s" failed)') % | |
60 (hname, modname)) | |
61 sys.path = oldpaths | 66 sys.path = oldpaths |
62 try: | 67 try: |
63 for p in funcname.split('.')[1:]: | 68 for p in funcname.split('.')[1:]: |
64 obj = getattr(obj, p) | 69 obj = getattr(obj, p) |
65 except AttributeError: | 70 except AttributeError: |