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

Proposed by Martin Pool
Status: Merged
Approved by: Andrew Bennetts
Approved revision: no longer in the source branch.
Merged at revision: 5802
Proposed branch: lp:~mbp/bzr/506265-command-deprecation
Merge into: lp:bzr
Diff against target: 198 lines (+68/-2)
7 files modified
bzrlib/builtins.py (+8/-0)
bzrlib/commands.py (+13/-0)
bzrlib/tests/blackbox/test_branch.py (+15/-0)
bzrlib/tests/test_commands.py (+12/-0)
bzrlib/ui/__init__.py (+4/-0)
doc/en/release-notes/bzr-2.4.txt (+8/-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
Andrew Bennetts Approve
John A Meinel Needs Fixing
Review via email: mp+55030@code.launchpad.net

This proposal supersedes a proposal from 2011-03-25.

Commit message

Deprecate 'bzr clone' and 'bzr get' (bug 506265)

Description of the change

This makes cmd_branch give a warning if it's invoked as 'bzr get' or 'bzr clone'. See bug 506265.

This can't be suppressed by defining a user alias, but it also is not fatal.

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

-----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 : Posted in a previous version of this proposal

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

Revision history for this message
John A Meinel (jameinel) wrote :

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

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

I'm a little concerned about the "unable to be suppressed by user alias"
aspect.

I think I really prefer an implementation like:

class cmd_deprecated(Command):

 aliases = ['get', 'clone']

 def run(self, *args, **kwargs):
   if self.invoked_as in ('get', 'clone'):
     official_name = 'branch'
   trace.warning('Command %s deprecated in favor of its official name'
    ' %s' % (self.invoked_as, official_name))
   trace.warning('Please retry with that name')

We might also want to do a trick with self.run_argv_aliases, since we
won't be providing all the flags for every command we are deprecating on
this single command. I don't think it would be very hard to do.

Thoughts?

 review: needsfixing

John
=:->

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

iEYEARECAAYFAk2QckEACgkQJdeBCYSNAANa+QCgqG2DGer6DxXVxkU99icEgiuO
5aEAoIoqRLyOlEs2z95NAG206DOL7Z5s
=T4mo
-----END PGP SIGNATURE-----

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

Being able to easily turn it off would be good.

I wonder if the exact command you sketch would fail before it runs
because of option or alias mismatches. I can try it.

Alternatively we can add a user option to turn off particular
warnings; I intended to add one already.
Martin

Revision history for this message
Andrew Bennetts (spiv) wrote :

Chatting with poolie on IRC I think the inability to suppress the warnings is probably not enough of a problem to let this patch go stale. It'd be great to add the option, and I hope poolie does that soon, but for now I think we land this.

review: Approve
Revision history for this message
Andrew Bennetts (spiv) wrote :

sent to pqm by email

Revision history for this message
Andrew Bennetts (spiv) wrote :

PQM replied to me: Conflicts during merge: Text conflict in doc/en/release-notes/bzr-2.4.txt

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

sent to pqm by email

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

this apparently has some test failures in pqm

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

sent to pqm by email

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

sent to pqm by email

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-04-11 00:18:12 +0000
3+++ bzrlib/builtins.py 2011-04-19 03:25:50 +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
27=== modified file 'bzrlib/commands.py'
28--- bzrlib/commands.py 2011-04-15 18:11:31 +0000
29+++ bzrlib/commands.py 2011-04-19 03:25:50 +0000
30@@ -273,6 +273,8 @@
31 # Allow plugins to extend commands
32 for hook in Command.hooks['extend_command']:
33 hook(cmd)
34+ if getattr(cmd, 'invoked_as', None) is None:
35+ cmd.invoked_as = cmd_name
36 return cmd
37
38
39@@ -394,7 +396,13 @@
40 sys.stdout is forced to be a binary stream, and line-endings
41 will not mangled.
42
43+ :ivar invoked_as:
44+ A string indicating the real name under which this command was
45+ invoked, before expansion of aliases.
46+ (This may be None if the command was constructed and run in-process.)
47+
48 :cvar hooks: An instance of CommandHooks.
49+
50 :ivar __doc__: The help shown by 'bzr help command' for this command.
51 This is set by assigning explicitly to __doc__ so that -OO can
52 be used::
53@@ -406,6 +414,7 @@
54 takes_args = []
55 takes_options = []
56 encoding_type = 'strict'
57+ invoked_as = None
58
59 hidden = False
60
61@@ -749,6 +758,10 @@
62 return getdoc(self)
63
64 def name(self):
65+ """Return the canonical name for this command.
66+
67+ The name under which it was actually invoked is available in invoked_as.
68+ """
69 return _unsquish_command_name(self.__class__.__name__)
70
71 def plugin_name(self):
72
73=== modified file 'bzrlib/tests/blackbox/test_branch.py'
74--- bzrlib/tests/blackbox/test_branch.py 2011-04-15 07:01:22 +0000
75+++ bzrlib/tests/blackbox/test_branch.py 2011-04-19 03:25:50 +0000
76@@ -33,6 +33,7 @@
77 test_server,
78 )
79 from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
80+from bzrlib.tests.script import run_script
81 from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
82 from bzrlib.workingtree import WorkingTree
83
84@@ -501,3 +502,17 @@
85 # Ensure that no working tree what created remotely
86 self.assertFalse(t.has('remote/file'))
87
88+
89+class TestDeprecatedAliases(TestCaseWithTransport):
90+
91+ def test_deprecated_aliases(self):
92+ """bzr branch can be called clone or get, but those names are deprecated.
93+
94+ See bug 506265.
95+ """
96+ for command in ['clone', 'get']:
97+ run_script(self, """
98+ $ bzr %(command)s A B
99+ 2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
100+ 2>bzr: ERROR: Not a branch...
101+ """ % locals())
102
103=== modified file 'bzrlib/tests/test_commands.py'
104--- bzrlib/tests/test_commands.py 2011-01-12 01:01:53 +0000
105+++ bzrlib/tests/test_commands.py 2011-04-19 03:25:50 +0000
106@@ -91,6 +91,18 @@
107 self.assertContainsRe(c.get_help_text(), '--foo')
108
109
110+class TestInvokedAs(tests.TestCase):
111+
112+ def test_invoked_as(self):
113+ """The command object knows the actual name used to invoke it."""
114+ commands.install_bzr_command_hooks()
115+ commands._register_builtin_commands()
116+ # get one from the real get_cmd_object.
117+ c = commands.get_cmd_object('ci')
118+ self.assertIsInstance(c, builtins.cmd_commit)
119+ self.assertEquals(c.invoked_as, 'ci')
120+
121+
122 class TestGetAlias(tests.TestCase):
123
124 def _get_config(self, config_text):
125
126=== modified file 'bzrlib/ui/__init__.py'
127--- bzrlib/ui/__init__.py 2011-04-07 10:36:24 +0000
128+++ bzrlib/ui/__init__.py 2011-04-19 03:25:50 +0000
129@@ -145,6 +145,10 @@
130 "This may take some time. Upgrade the repositories to the "
131 "same format for better performance."
132 ),
133+ deprecated_command=(
134+ "The command 'bzr %(deprecated_name)s' "
135+ "has been deprecated in bzr %(deprecated_in_version)s. "
136+ "Please use 'bzr %(recommended_name)s' instead."),
137 recommend_upgrade=("%(current_format_name)s is deprecated "
138 "and a better format is available.\n"
139 "It is recommended that you upgrade by "
140
141=== modified file 'doc/en/release-notes/bzr-2.4.txt'
142--- doc/en/release-notes/bzr-2.4.txt 2011-04-18 03:15:03 +0000
143+++ doc/en/release-notes/bzr-2.4.txt 2011-04-19 03:25:50 +0000
144@@ -15,6 +15,10 @@
145
146 .. These may require users to change the way they use Bazaar.
147
148+* Two command synonyms for ``bzr branch`` have been deprecated, to avoid
149+ confusion and to allow the names to later be reused. The removed names
150+ are: ``get`` and ``clone``. (Martin Pool, #506265)
151+
152 New Features
153 ************
154
155@@ -107,6 +111,10 @@
156 .. Changes that may require updates in plugins or other code that uses
157 bzrlib.
158
159+* Commands now have an `invoked_as` attribute, showing the name under
160+ which they were called before alias expansion.
161+ (Martin Pool)
162+
163 * ``Hooks.create_hook`` is now deprecated in favour of ``Hooks.add_hook``.
164 (Jelmer Vernooij)
165
166
167=== modified file 'doc/en/whats-new/whats-new-in-2.4.txt'
168--- doc/en/whats-new/whats-new-in-2.4.txt 2011-03-15 08:07:04 +0000
169+++ doc/en/whats-new/whats-new-in-2.4.txt 2011-04-19 03:25:50 +0000
170@@ -16,14 +16,14 @@
171 2.1, 2.2 and 2.3, and can read and write repositories generated by all
172 previous versions.
173
174-External Merge Tools
175+External merge tools
176 ********************
177
178 External merge tool configuration has been added to ``bzr`` core. The name
179 and commandline of one or more external merge tools can be defined in
180 bazaar.conf. See the help topic ``configuration`` for more details.
181
182-Tagged Revisions are Copied
183+Tagged revisions are copied
184 ***************************
185
186 When tags are copied from a branch, the associated revisions are now copied
187@@ -32,6 +32,12 @@
188 revisions from tags will always be present, so that operations like ``bzr
189 log -r tag:foo`` will always work.
190
191+Deprecated command synonyms
192+***************************
193+
194+Two built-in synonyms for ``bzr branch`` have been deprecated: ``clone`` and
195+``get``.
196+
197 Configuration files
198 *******************
199