Mercurial > hg
diff 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 |
line wrap: on
line diff
--- a/mercurial/hook.py Mon Feb 10 00:43:54 2014 +0100 +++ b/mercurial/hook.py Mon Feb 10 14:51:06 2014 -0800 @@ -36,28 +36,33 @@ if modpath and modfile: sys.path = sys.path[:] + [modpath] modname = modfile - try: + demandimportenabled = demandimport.isenabled() + if demandimportenabled: demandimport.disable() - obj = __import__(modname) - demandimport.enable() - except ImportError: - e1 = sys.exc_type, sys.exc_value, sys.exc_traceback + try: try: - # extensions are loaded with hgext_ prefix - obj = __import__("hgext_%s" % modname) - demandimport.enable() + obj = __import__(modname) except ImportError: + e1 = sys.exc_type, sys.exc_value, sys.exc_traceback + try: + # extensions are loaded with hgext_ prefix + obj = __import__("hgext_%s" % modname) + except ImportError: + e2 = sys.exc_type, sys.exc_value, sys.exc_traceback + if ui.tracebackflag: + ui.warn(_('exception from first failed import ' + 'attempt:\n')) + ui.traceback(e1) + if ui.tracebackflag: + ui.warn(_('exception from second failed import ' + 'attempt:\n')) + ui.traceback(e2) + raise util.Abort(_('%s hook is invalid ' + '(import of "%s" failed)') % + (hname, modname)) + finally: + if demandimportenabled: demandimport.enable() - e2 = sys.exc_type, sys.exc_value, sys.exc_traceback - if ui.tracebackflag: - ui.warn(_('exception from first failed import attempt:\n')) - ui.traceback(e1) - if ui.tracebackflag: - ui.warn(_('exception from second failed import attempt:\n')) - ui.traceback(e2) - raise util.Abort(_('%s hook is invalid ' - '(import of "%s" failed)') % - (hname, modname)) sys.path = oldpaths try: for p in funcname.split('.')[1:]: