changeset 3014:01454af644b8

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.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Tue, 22 Aug 2006 22:49:30 -0300
parents 494521a3f142
children fa4229c60dd7
files mercurial/commands.py mercurial/ui.py tests/test-bad-extension tests/test-bad-extension.out
diffstat 4 files changed, 23 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Tue Aug 22 20:45:03 2006 -0300
+++ b/mercurial/commands.py	Tue Aug 22 22:49:30 2006 -0300
@@ -3305,12 +3305,14 @@
         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	Tue Aug 22 20:45:03 2006 -0300
+++ b/mercurial/ui.py	Tue Aug 22 22:49:30 2006 -0300
@@ -12,13 +12,12 @@
 
 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 @@
         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 @@
         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
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-bad-extension	Tue Aug 22 22:49:30 2006 -0300
@@ -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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-bad-extension.out	Tue Aug 22 22:49:30 2006 -0300
@@ -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