Rev 5059: * ``bzr help`` will no longer trigger the get_missing_command hook when in http://bazaar.launchpad.net/~lifeless/bzr/commandlookup
Robert Collins
robertc at robertcollins.net
Fri Feb 26 04:43:49 GMT 2010
At http://bazaar.launchpad.net/~lifeless/bzr/commandlookup
------------------------------------------------------------
revno: 5059
revision-id: robertc at robertcollins.net-20100226044331-es52r2tz8hy8j4xz
parent: pqm at pqm.ubuntu.com-20100226043331-dia5wyri05hdke48
fixes bug(s): https://launchpad.net/bugs/396261
committer: Robert Collins <robertc at robertcollins.net>
branch nick: commandlookup
timestamp: Fri 2010-02-26 15:43:31 +1100
message:
* ``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)
=== 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-23 07:43:11 +0000
+++ b/bzrlib/commands.py 2010-02-26 04:43:31 +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:
@@ -1162,7 +1164,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