load extensions only after the ui object has been completely initialized
This fixes a traceback printed when hg tries to print another traceback
after an extension fails to be loaded. Add a test for that.
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3305,12 +3305,14 @@ def dispatch(args):
if num: signal.signal(num, catchterm)
try:
- u = ui.ui(traceback='--traceback' in sys.argv[1:],
- readhooks=[load_extensions])
+ u = ui.ui(traceback='--traceback' in sys.argv[1:])
except util.Abort, inst:
sys.stderr.write(_("abort: %s\n") % inst)
return -1
+ load_extensions(u)
+ u.addreadhook(load_extensions)
+
try:
cmd, func, args, options, cmdoptions = parse(u, args)
if options["time"]:
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -12,13 +12,12 @@ demandload(globals(), "ConfigParser mdif
class ui(object):
def __init__(self, verbose=False, debug=False, quiet=False,
- interactive=True, traceback=False, parentui=None,
- readhooks=[]):
+ interactive=True, traceback=False, parentui=None):
self.overlay = {}
if parentui is None:
# this is the parent of all ui children
self.parentui = None
- self.readhooks = list(readhooks)
+ self.readhooks = []
self.trusted_users = {}
self.trusted_groups = {}
self.cdata = ConfigParser.SafeConfigParser()
@@ -38,7 +37,7 @@ class ui(object):
else:
# parentui may point to an ui object which is already a child
self.parentui = parentui.parentui or parentui
- self.readhooks = list(parentui.readhooks or readhooks)
+ self.readhooks = parentui.readhooks[:]
self.trusted_users = parentui.trusted_users.copy()
self.trusted_groups = parentui.trusted_groups.copy()
parent_cdata = self.parentui.cdata
@@ -110,6 +109,9 @@ class ui(object):
for hook in self.readhooks:
hook(self)
+ def addreadhook(self, hook):
+ self.readhooks.append(hook)
+
def setconfig(self, section, name, val):
self.overlay[(section, name)] = val
new file mode 100755
--- /dev/null
+++ b/tests/test-bad-extension
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+echo 'syntax error' > badext.py
+abspath=`pwd`/badext.py
+
+echo '[extensions]' >> $HGRCPATH
+echo "badext = $abspath" >> $HGRCPATH
+
+hg -q help help
new file mode 100644
--- /dev/null
+++ b/tests/test-bad-extension.out
@@ -0,0 +1,4 @@
+*** failed to import extension badext: invalid syntax (badext.py, line 1)
+hg help [COMMAND]
+
+show help for a command, extension, or list of commands