Merge lp:~mbp/bzr/506265-command-deprecation into lp:bzr

Proposed by Martin Pool
Status: Superseded
Proposed branch: lp:~mbp/bzr/506265-command-deprecation
Merge into: lp:bzr
Diff against target: 215 lines (+72/-4)
7 files modified
bzrlib/builtins.py (+9/-1)
bzrlib/commands.py (+13/-0)
bzrlib/tests/blackbox/test_branch.py (+15/-0)
bzrlib/tests/test_commands.py (+15/-0)
bzrlib/ui/__init__.py (+5/-1)
doc/en/release-notes/bzr-2.4.txt (+7/-0)
doc/en/whats-new/whats-new-in-2.4.txt (+8/-2)
To merge this branch: bzr merge lp:~mbp/bzr/506265-command-deprecation
Reviewer Review Type Date Requested Status
John A Meinel Approve
Review via email: mp+54828@code.launchpad.net

This proposal has been superseded by a proposal from 2011-03-28.

Description of the change

This doesn't fix bug 506265, but it adds a new Command.invoked_as member, which gets the original name before alias expansion.

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 03/25/2011 10:45 AM, Martin Pool wrote:
> Martin Pool has proposed merging lp:~mbp/bzr/506265-command-deprecation into lp:bzr.
>
> Requested reviews:
> bzr-core (bzr-core)
>
> For more details, see:
> https://code.launchpad.net/~mbp/bzr/506265-command-deprecation/+merge/54828
>
> This doesn't fix bug 506265, but it adds a new Command.invoked_as member, which gets the original name before alias expansion.

Does this distinguish between user aliases and built-in aliases?

I'm certainly fine with the addition. I think I see how you want to use
this, so I'm happy to bring it in, even though it isn't directly used now.

John
=:->
 merge: approve
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk2MZZ8ACgkQJdeBCYSNAANKEACfdTxJA44Pwnmn+mT8XFO0s8mt
xOUAoMlIE+GVuakK2qPUvht/ROUllozW
=wEc1
-----END PGP SIGNATURE-----

review: Approve
Revision history for this message
Martin Pool (mbp) wrote :

It doesn't distinguish between user and builtin aliases: it will give the actual name on the command line in either case.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/builtins.py'
2--- bzrlib/builtins.py 2011-03-15 10:28:20 +0000
3+++ bzrlib/builtins.py 2011-03-28 00:24:46 +0000
4@@ -1205,6 +1205,8 @@
5
6 To retrieve the branch as of a particular revision, supply the --revision
7 parameter, as in "branch foo/bar -r 5".
8+
9+ The synonyms 'clone' and 'get' for this command are deprecated.
10 """
11
12 _see_also = ['checkout']
13@@ -1240,6 +1242,12 @@
14 files_from=None):
15 from bzrlib import switch as _mod_switch
16 from bzrlib.tag import _merge_tags_if_possible
17+ if self.invoked_as in ['get', 'clone']:
18+ ui.ui_factory.show_user_warning(
19+ 'deprecated_command',
20+ deprecated_name=self.invoked_as,
21+ recommended_name='branch',
22+ deprecated_in_version='2.4')
23 accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
24 from_location)
25 if not (hardlink or files_from):
26@@ -3170,7 +3178,7 @@
27 help='When no message is supplied, show the diff along'
28 ' with the status summary in the message editor.'),
29 ]
30- aliases = ['ci', 'checkin']
31+ aliases = ['ci']
32
33 def _iter_bug_fix_urls(self, fixes, branch):
34 # Configure the properties for bug fixing attributes.
35
36=== modified file 'bzrlib/commands.py'
37--- bzrlib/commands.py 2011-02-04 22:25:59 +0000
38+++ bzrlib/commands.py 2011-03-28 00:24:46 +0000
39@@ -276,6 +276,8 @@
40 # Allow plugins to extend commands
41 for hook in Command.hooks['extend_command']:
42 hook(cmd)
43+ if getattr(cmd, 'invoked_as', None) is None:
44+ cmd.invoked_as = cmd_name
45 return cmd
46
47
48@@ -397,7 +399,13 @@
49 sys.stdout is forced to be a binary stream, and line-endings
50 will not mangled.
51
52+ :ivar invoked_as:
53+ A string indicating the real name under which this command was
54+ invoked, before expansion of aliases.
55+ (This may be None if the command was constructed and run in-process.)
56+
57 :cvar hooks: An instance of CommandHooks.
58+
59 :ivar __doc__: The help shown by 'bzr help command' for this command.
60 This is set by assigning explicitly to __doc__ so that -OO can
61 be used::
62@@ -409,6 +417,7 @@
63 takes_args = []
64 takes_options = []
65 encoding_type = 'strict'
66+ invoked_as = None
67
68 hidden = False
69
70@@ -752,6 +761,10 @@
71 return getdoc(self)
72
73 def name(self):
74+ """Return the canonical name for this command.
75+
76+ The name under which it was actually invoked is available in invoked_as.
77+ """
78 return _unsquish_command_name(self.__class__.__name__)
79
80 def plugin_name(self):
81
82=== modified file 'bzrlib/tests/blackbox/test_branch.py'
83--- bzrlib/tests/blackbox/test_branch.py 2011-02-11 05:57:31 +0000
84+++ bzrlib/tests/blackbox/test_branch.py 2011-03-28 00:24:46 +0000
85@@ -33,6 +33,7 @@
86 test_server,
87 )
88 from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
89+from bzrlib.tests.script import run_script
90 from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
91 from bzrlib.workingtree import WorkingTree
92
93@@ -501,3 +502,17 @@
94 # Ensure that no working tree what created remotely
95 self.assertFalse(t.has('remote/file'))
96
97+
98+class TestDeprecatedAliases(TestCaseWithTransport):
99+
100+ def test_deprecated_aliases(self):
101+ """bzr branch can be called clone or get, but those names are deprecated.
102+
103+ See bug 506265.
104+ """
105+ for command in ['clone', 'get']:
106+ run_script(self, """
107+ $ bzr %(command)s A B
108+ 2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
109+ 2>bzr: ERROR: Not a branch...
110+ """ % locals())
111
112=== modified file 'bzrlib/tests/test_commands.py'
113--- bzrlib/tests/test_commands.py 2011-01-12 01:01:53 +0000
114+++ bzrlib/tests/test_commands.py 2011-03-28 00:24:46 +0000
115@@ -91,6 +91,21 @@
116 self.assertContainsRe(c.get_help_text(), '--foo')
117
118
119+class TestInvokedAs(tests.TestCase):
120+
121+ def setUp(self):
122+ super(TestCommandDeprecation, self).setUp()
123+ commands.install_bzr_command_hooks()
124+ commands._register_builtin_commands()
125+
126+ def test_invoked_as(self):
127+ """The command object knows the actual name used to invoke it."""
128+ # get one from the real get_cmd_object.
129+ c = commands.get_cmd_object('ci')
130+ self.assertIsInstance(c, builtins.cmd_commit)
131+ self.assertEquals(c.invoked_as, 'ci')
132+
133+
134 class TestGetAlias(tests.TestCase):
135
136 def _get_config(self, config_text):
137
138=== modified file 'bzrlib/ui/__init__.py'
139--- bzrlib/ui/__init__.py 2011-03-12 17:06:27 +0000
140+++ bzrlib/ui/__init__.py 2011-03-28 00:24:46 +0000
141@@ -1,4 +1,4 @@
142-# Copyright (C) 2005-2010 Canonical Ltd
143+# Copyright (C) 2005-2011 Canonical Ltd
144 #
145 # This program is free software; you can redistribute it and/or modify
146 # it under the terms of the GNU General Public License as published by
147@@ -155,6 +155,10 @@
148 "This may take some time. Upgrade the repositories to the "
149 "same format for better performance."
150 ),
151+ deprecated_command=(
152+ "The command 'bzr %(deprecated_name)s' "
153+ "has been deprecated in bzr %(deprecated_in_version)s. "
154+ "Please use 'bzr %(recommended_name)s' instead."),
155 recommend_upgrade=("%(current_format_name)s is deprecated "
156 "and a better format is available.\n"
157 "It is recommended that you upgrade by "
158
159=== modified file 'doc/en/release-notes/bzr-2.4.txt'
160--- doc/en/release-notes/bzr-2.4.txt 2011-03-24 11:41:42 +0000
161+++ doc/en/release-notes/bzr-2.4.txt 2011-03-28 00:24:46 +0000
162@@ -15,6 +15,10 @@
163
164 .. These may require users to change the way they use Bazaar.
165
166+* Two command synonyms for ``bzr branch`` have been deprecated, to avoid
167+ confusion and to allow the names to later be reused. The removed names
168+ are: ``get`` and ``clone``. (Martin Pool, #506265)
169+
170 New Features
171 ************
172
173@@ -54,6 +58,9 @@
174 .. Changes that may require updates in plugins or other code that uses
175 bzrlib.
176
177+* Commands now have an `invoked_as` attribute, showing the name under
178+ which they were called before alias expansion.
179+
180 Internals
181 *********
182
183
184=== modified file 'doc/en/whats-new/whats-new-in-2.4.txt'
185--- doc/en/whats-new/whats-new-in-2.4.txt 2011-03-15 08:07:04 +0000
186+++ doc/en/whats-new/whats-new-in-2.4.txt 2011-03-28 00:24:46 +0000
187@@ -16,14 +16,14 @@
188 2.1, 2.2 and 2.3, and can read and write repositories generated by all
189 previous versions.
190
191-External Merge Tools
192+External merge tools
193 ********************
194
195 External merge tool configuration has been added to ``bzr`` core. The name
196 and commandline of one or more external merge tools can be defined in
197 bazaar.conf. See the help topic ``configuration`` for more details.
198
199-Tagged Revisions are Copied
200+Tagged revisions are copied
201 ***************************
202
203 When tags are copied from a branch, the associated revisions are now copied
204@@ -32,6 +32,12 @@
205 revisions from tags will always be present, so that operations like ``bzr
206 log -r tag:foo`` will always work.
207
208+Deprecated command synonyms
209+***************************
210+
211+Two built-in synonyms for ``bzr branch`` have been deprecated: ``clone`` and
212+``get``.
213+
214 Configuration files
215 *******************
216