Rev 5060: (robertc) Do not call Commands.hooks[get_missing_command] when in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Feb 26 14:14:39 GMT 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5060 [merge]
revision-id: pqm at pqm.ubuntu.com-20100226141436-t8s3uqt5w9ktt04g
parent: pqm at pqm.ubuntu.com-20100226133925-1qsa3webm753b6hx
parent: robertc at robertcollins.net-20100226044331-es52r2tz8hy8j4xz
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2010-02-26 14:14:36 +0000
message:
  (robertc) Do not call Commands.hooks[get_missing_command] when
  	looking up help topics. (Robert Collins, bug 396261)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/commands.py             bzr.py-20050309040720-d10f4714595cf8c3
  bzrlib/tests/test_commands.py  test_command.py-20051019190109-3b17be0f52eaa7a8
=== modified file 'NEWS'
--- a/NEWS	2010-02-25 06:17:27 +0000
+++ b/NEWS	2010-02-26 04:43:31 +0000
@@ -70,6 +70,12 @@
 * ``bzr add`` will not add conflict related files unless explicitly required.
   (Vincent Ladeuil, #322767, #414589)
 
+* ``bzr help`` will no longer trigger the get_missing_command hook when
+  doing a topic lookup. This avoids prompting (like 'no command plugins/loom,
+  did you mean log?') when getting help. In future we may trigger the hook 
+  deliberately when no help topics match from any help index.
+  (Robert Collins, #396261)
+
 * ``bzr remove-tree`` can now remove multiple working trees.
   (Jared Hance, Andrew Bennetts, #253137)
 

=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2010-02-26 12:56:09 +0000
+++ b/bzrlib/commands.py	2010-02-26 14:14:36 +0000
@@ -199,11 +199,13 @@
         raise errors.BzrCommandError('unknown command "%s"' % cmd_name)
 
 
-def _get_cmd_object(cmd_name, plugins_override=True):
+def _get_cmd_object(cmd_name, plugins_override=True, check_missing=True):
     """Get a command object.
 
     :param cmd_name: The name of the command.
     :param plugins_override: Allow plugins to override builtins.
+    :param check_missing: Look up commands not found in the regular index via
+        the get_missing_command hook.
     :return: A Command object instance
     :raises KeyError: If no command is found.
     """
@@ -219,7 +221,7 @@
             # We've found a non-plugin command, don't permit it to be
             # overridden.
             break
-    if cmd is None:
+    if cmd is None and check_missing:
         for hook in Command.hooks['get_missing_command']:
             cmd = hook(cmd_name)
             if cmd is not None:
@@ -1166,7 +1168,7 @@
         if topic and topic.startswith(self.prefix):
             topic = topic[len(self.prefix):]
         try:
-            cmd = _get_cmd_object(topic)
+            cmd = _get_cmd_object(topic, check_missing=False)
         except KeyError:
             return []
         else:

=== modified file 'bzrlib/tests/test_commands.py'
--- a/bzrlib/tests/test_commands.py	2010-01-14 13:17:33 +0000
+++ b/bzrlib/tests/test_commands.py	2010-02-26 04:43:31 +0000
@@ -276,32 +276,45 @@
 
 class TestGetMissingCommandHook(tests.TestCase):
 
-    def test_fires_on_get_cmd_object(self):
-        # The get_missing_command(cmd) hook fires when commands are delivered to the
-        # ui.
-        hook_calls = []
+    def hook_missing(self):
+        """Hook get_missing_command for testing."""
+        self.hook_calls = []
         class ACommand(commands.Command):
             """A sample command."""
         def get_missing_cmd(cmd_name):
-            hook_calls.append(('called', cmd_name))
+            self.hook_calls.append(('called', cmd_name))
             if cmd_name in ('foo', 'info'):
                 return ACommand()
         commands.Command.hooks.install_named_hook(
             "get_missing_command", get_missing_cmd, None)
+        self.ACommand = ACommand
+
+    def test_fires_on_get_cmd_object(self):
+        # The get_missing_command(cmd) hook fires when commands are delivered to the
+        # ui.
+        self.hook_missing()
         # create a command directly, should not fire
-        cmd = ACommand()
-        self.assertEqual([], hook_calls)
+        self.cmd = self.ACommand()
+        self.assertEqual([], self.hook_calls)
         # ask by name, should fire and give us our command
         cmd = commands.get_cmd_object('foo')
-        self.assertEqual([('called', 'foo')], hook_calls)
-        self.assertIsInstance(cmd, ACommand)
-        del hook_calls[:]
+        self.assertEqual([('called', 'foo')], self.hook_calls)
+        self.assertIsInstance(cmd, self.ACommand)
+        del self.hook_calls[:]
         # ask by a name that is supplied by a builtin - the hook should not
         # fire and we still get our object.
         commands.install_bzr_command_hooks()
         cmd = commands.get_cmd_object('info')
         self.assertNotEqual(None, cmd)
-        self.assertEqual(0, len(hook_calls))
+        self.assertEqual(0, len(self.hook_calls))
+
+    def test_skipped_on_HelpCommandIndex_get_topics(self):
+        # The get_missing_command(cmd_name) hook is not fired when
+        # looking up help topics.
+        self.hook_missing()
+        topic = commands.HelpCommandIndex()
+        topics = topic.get_topics('foo')
+        self.assertEqual([], self.hook_calls)
 
 
 class TestListCommandHook(tests.TestCase):




More information about the bazaar-commits mailing list