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
=== modified file 'bzrlib/builtins.py'
--- bzrlib/builtins.py 2011-04-11 00:18:12 +0000
+++ bzrlib/builtins.py 2011-04-19 03:25:50 +0000
@@ -1205,6 +1205,8 @@
12051205
1206 To retrieve the branch as of a particular revision, supply the --revision1206 To retrieve the branch as of a particular revision, supply the --revision
1207 parameter, as in "branch foo/bar -r 5".1207 parameter, as in "branch foo/bar -r 5".
1208
1209 The synonyms 'clone' and 'get' for this command are deprecated.
1208 """1210 """
12091211
1210 _see_also = ['checkout']1212 _see_also = ['checkout']
@@ -1240,6 +1242,12 @@
1240 files_from=None):1242 files_from=None):
1241 from bzrlib import switch as _mod_switch1243 from bzrlib import switch as _mod_switch
1242 from bzrlib.tag import _merge_tags_if_possible1244 from bzrlib.tag import _merge_tags_if_possible
1245 if self.invoked_as in ['get', 'clone']:
1246 ui.ui_factory.show_user_warning(
1247 'deprecated_command',
1248 deprecated_name=self.invoked_as,
1249 recommended_name='branch',
1250 deprecated_in_version='2.4')
1243 accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(1251 accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1244 from_location)1252 from_location)
1245 if not (hardlink or files_from):1253 if not (hardlink or files_from):
12461254
=== modified file 'bzrlib/commands.py'
--- bzrlib/commands.py 2011-04-15 18:11:31 +0000
+++ bzrlib/commands.py 2011-04-19 03:25:50 +0000
@@ -273,6 +273,8 @@
273 # Allow plugins to extend commands273 # Allow plugins to extend commands
274 for hook in Command.hooks['extend_command']:274 for hook in Command.hooks['extend_command']:
275 hook(cmd)275 hook(cmd)
276 if getattr(cmd, 'invoked_as', None) is None:
277 cmd.invoked_as = cmd_name
276 return cmd278 return cmd
277279
278280
@@ -394,7 +396,13 @@
394 sys.stdout is forced to be a binary stream, and line-endings396 sys.stdout is forced to be a binary stream, and line-endings
395 will not mangled.397 will not mangled.
396398
399 :ivar invoked_as:
400 A string indicating the real name under which this command was
401 invoked, before expansion of aliases.
402 (This may be None if the command was constructed and run in-process.)
403
397 :cvar hooks: An instance of CommandHooks.404 :cvar hooks: An instance of CommandHooks.
405
398 :ivar __doc__: The help shown by 'bzr help command' for this command.406 :ivar __doc__: The help shown by 'bzr help command' for this command.
399 This is set by assigning explicitly to __doc__ so that -OO can407 This is set by assigning explicitly to __doc__ so that -OO can
400 be used::408 be used::
@@ -406,6 +414,7 @@
406 takes_args = []414 takes_args = []
407 takes_options = []415 takes_options = []
408 encoding_type = 'strict'416 encoding_type = 'strict'
417 invoked_as = None
409418
410 hidden = False419 hidden = False
411420
@@ -749,6 +758,10 @@
749 return getdoc(self)758 return getdoc(self)
750759
751 def name(self):760 def name(self):
761 """Return the canonical name for this command.
762
763 The name under which it was actually invoked is available in invoked_as.
764 """
752 return _unsquish_command_name(self.__class__.__name__)765 return _unsquish_command_name(self.__class__.__name__)
753766
754 def plugin_name(self):767 def plugin_name(self):
755768
=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- bzrlib/tests/blackbox/test_branch.py 2011-04-15 07:01:22 +0000
+++ bzrlib/tests/blackbox/test_branch.py 2011-04-19 03:25:50 +0000
@@ -33,6 +33,7 @@
33 test_server,33 test_server,
34 )34 )
35from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer35from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
36from bzrlib.tests.script import run_script
36from bzrlib.urlutils import local_path_to_url, strip_trailing_slash37from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
37from bzrlib.workingtree import WorkingTree38from bzrlib.workingtree import WorkingTree
3839
@@ -501,3 +502,17 @@
501 # Ensure that no working tree what created remotely502 # Ensure that no working tree what created remotely
502 self.assertFalse(t.has('remote/file'))503 self.assertFalse(t.has('remote/file'))
503504
505
506class TestDeprecatedAliases(TestCaseWithTransport):
507
508 def test_deprecated_aliases(self):
509 """bzr branch can be called clone or get, but those names are deprecated.
510
511 See bug 506265.
512 """
513 for command in ['clone', 'get']:
514 run_script(self, """
515 $ bzr %(command)s A B
516 2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
517 2>bzr: ERROR: Not a branch...
518 """ % locals())
504519
=== modified file 'bzrlib/tests/test_commands.py'
--- bzrlib/tests/test_commands.py 2011-01-12 01:01:53 +0000
+++ bzrlib/tests/test_commands.py 2011-04-19 03:25:50 +0000
@@ -91,6 +91,18 @@
91 self.assertContainsRe(c.get_help_text(), '--foo')91 self.assertContainsRe(c.get_help_text(), '--foo')
9292
9393
94class TestInvokedAs(tests.TestCase):
95
96 def test_invoked_as(self):
97 """The command object knows the actual name used to invoke it."""
98 commands.install_bzr_command_hooks()
99 commands._register_builtin_commands()
100 # get one from the real get_cmd_object.
101 c = commands.get_cmd_object('ci')
102 self.assertIsInstance(c, builtins.cmd_commit)
103 self.assertEquals(c.invoked_as, 'ci')
104
105
94class TestGetAlias(tests.TestCase):106class TestGetAlias(tests.TestCase):
95107
96 def _get_config(self, config_text):108 def _get_config(self, config_text):
97109
=== modified file 'bzrlib/ui/__init__.py'
--- bzrlib/ui/__init__.py 2011-04-07 10:36:24 +0000
+++ bzrlib/ui/__init__.py 2011-04-19 03:25:50 +0000
@@ -145,6 +145,10 @@
145 "This may take some time. Upgrade the repositories to the "145 "This may take some time. Upgrade the repositories to the "
146 "same format for better performance."146 "same format for better performance."
147 ),147 ),
148 deprecated_command=(
149 "The command 'bzr %(deprecated_name)s' "
150 "has been deprecated in bzr %(deprecated_in_version)s. "
151 "Please use 'bzr %(recommended_name)s' instead."),
148 recommend_upgrade=("%(current_format_name)s is deprecated "152 recommend_upgrade=("%(current_format_name)s is deprecated "
149 "and a better format is available.\n"153 "and a better format is available.\n"
150 "It is recommended that you upgrade by "154 "It is recommended that you upgrade by "
151155
=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- doc/en/release-notes/bzr-2.4.txt 2011-04-18 03:15:03 +0000
+++ doc/en/release-notes/bzr-2.4.txt 2011-04-19 03:25:50 +0000
@@ -15,6 +15,10 @@
1515
16.. These may require users to change the way they use Bazaar.16.. These may require users to change the way they use Bazaar.
1717
18* Two command synonyms for ``bzr branch`` have been deprecated, to avoid
19 confusion and to allow the names to later be reused. The removed names
20 are: ``get`` and ``clone``. (Martin Pool, #506265)
21
18New Features22New Features
19************23************
2024
@@ -107,6 +111,10 @@
107.. Changes that may require updates in plugins or other code that uses111.. Changes that may require updates in plugins or other code that uses
108 bzrlib.112 bzrlib.
109113
114* Commands now have an `invoked_as` attribute, showing the name under
115 which they were called before alias expansion.
116 (Martin Pool)
117
110* ``Hooks.create_hook`` is now deprecated in favour of ``Hooks.add_hook``.118* ``Hooks.create_hook`` is now deprecated in favour of ``Hooks.add_hook``.
111 (Jelmer Vernooij)119 (Jelmer Vernooij)
112120
113121
=== modified file 'doc/en/whats-new/whats-new-in-2.4.txt'
--- doc/en/whats-new/whats-new-in-2.4.txt 2011-03-15 08:07:04 +0000
+++ doc/en/whats-new/whats-new-in-2.4.txt 2011-04-19 03:25:50 +0000
@@ -16,14 +16,14 @@
162.1, 2.2 and 2.3, and can read and write repositories generated by all162.1, 2.2 and 2.3, and can read and write repositories generated by all
17previous versions.17previous versions.
1818
19External Merge Tools19External merge tools
20********************20********************
2121
22External merge tool configuration has been added to ``bzr`` core. The name22External merge tool configuration has been added to ``bzr`` core. The name
23and commandline of one or more external merge tools can be defined in23and commandline of one or more external merge tools can be defined in
24bazaar.conf. See the help topic ``configuration`` for more details.24bazaar.conf. See the help topic ``configuration`` for more details.
2525
26Tagged Revisions are Copied26Tagged revisions are copied
27***************************27***************************
2828
29When tags are copied from a branch, the associated revisions are now copied29When tags are copied from a branch, the associated revisions are now copied
@@ -32,6 +32,12 @@
32revisions from tags will always be present, so that operations like ``bzr32revisions from tags will always be present, so that operations like ``bzr
33log -r tag:foo`` will always work.33log -r tag:foo`` will always work.
3434
35Deprecated command synonyms
36***************************
37
38Two built-in synonyms for ``bzr branch`` have been deprecated: ``clone`` and
39``get``.
40
35Configuration files41Configuration files
36*******************42*******************
3743