Merge lp:~parthm/bzr/403687-status-shows-shelves into lp:bzr

Proposed by Parth Malwankar
Status: Rejected
Rejected by: Parth Malwankar
Proposed branch: lp:~parthm/bzr/403687-status-shows-shelves
Merge into: lp:bzr
Diff against target: 232 lines (+92/-18)
7 files modified
NEWS (+2/-0)
bzrlib/builtins.py (+16/-18)
bzrlib/help_topics/__init__.py (+1/-0)
bzrlib/shelf.py (+21/-0)
bzrlib/status.py (+10/-0)
bzrlib/tests/blackbox/test_status.py (+25/-0)
bzrlib/tests/test_shelf.py (+17/-0)
To merge this branch: bzr merge lp:~parthm/bzr/403687-status-shows-shelves
Reviewer Review Type Date Requested Status
Vincent Ladeuil Needs Fixing
Review via email: mp+31182@code.launchpad.net

Description of the change

=== Fixes bug #403687 ===
This patch updates the status command to list shelves if any. --short option shows shelves with 'S' in the second column. This patch doesn't do exactly what the bug describes i.e. display files with shelves. Instead it lists shelves with their ids. List of files can probably be looked at in the context of bug #330311.

Shelf listing function cmd_shelf.run_for_list is pulled out into the common location shelf.list_shelves which is used by cmd_shelf and status. list_shelves returns the shelves as a list of strings rather than directly displaying them.

Sample output:

[bzr-grep]% ~/src/bzr.dev/403687-st-shows-shelve/bzr st -S
 M INSTALL
? x
 S 1: <no message>

[bzr-grep]% ~/src/bzr.dev/403687-st-shows-shelve/bzr st
modified:
  INSTALL
unknown:
  x
shelves:
  1: <no message>

To post a comment you must log in.
5370. By Parth Malwankar

make imports in bzrlib.shelf lazy to pass test_import_tariff

5371. By Parth Malwankar

update status doc to mentioned 'shelved' as a state

5372. By Parth Malwankar

merged in trunk and resolved NEWS conflict.

Revision history for this message
Vincent Ladeuil (vila) wrote :

I agree with the comments on bug #403687, a single line in the output to mention the number
of shelves would better suit 'bzr status'.

A dedicated command 'bzr shelf-status' or 'bzr shelf --status' or something else
sounds more appropriate for a detailed output.

There are some compatibility issues to consider too here, some programs already parse the output
of status and adding new indicators can't be done lightly.

May be you should bring the subject to the mailing list so it can be discussed more broadly.

review: Needs Fixing
Revision history for this message
Parth Malwankar (parthm) wrote :

> I agree with the comments on bug #403687, a single line in the output to
> mention the number
> of shelves would better suit 'bzr status'.
>
> A dedicated command 'bzr shelf-status' or 'bzr shelf --status' or something
> else
> sounds more appropriate for a detailed output.
>
> There are some compatibility issues to consider too here, some programs
> already parse the output
> of status and adding new indicators can't be done lightly.
>
> May be you should bring the subject to the mailing list so it can be discussed
> more broadly.

Yes. This is quite a bit of a change in UI. I will start a discussion in the mailing list.

Revision history for this message
Parth Malwankar (parthm) wrote :

I am rejecting this in favor of the hook based and single line suggestion that came up on the mailing list. The proposed post_status hook can be found here https://code.launchpad.net/~parthm/bzr/601749-status-options-show/+merge/33985

Unmerged revisions

5372. By Parth Malwankar

merged in trunk and resolved NEWS conflict.

5371. By Parth Malwankar

update status doc to mentioned 'shelved' as a state

5370. By Parth Malwankar

make imports in bzrlib.shelf lazy to pass test_import_tariff

5369. By Parth Malwankar

test case for short status

5368. By Parth Malwankar

support for 'st -S' with shelf listing

5367. By Parth Malwankar

added blackbox test case

5366. By Parth Malwankar

test case cleanup

5365. By Parth Malwankar

test case for shelf.list_shelves()

5364. By Parth Malwankar

updated NEWS

5363. By Parth Malwankar

show 'no changes' message only for shelve command

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2010-07-26 17:19:33 +0000
+++ NEWS 2010-08-01 07:14:39 +0000
@@ -25,6 +25,8 @@
25New Features25New Features
26************26************
2727
28* ``status`` now lists shelved changes if any. (Parth Malwankar, #403687)
29
28* The ``lp:`` prefix will now use your known username (from30* The ``lp:`` prefix will now use your known username (from
29 ``bzr launchpad-login``) to expand ``~`` to your username. For example:31 ``bzr launchpad-login``) to expand ``~`` to your username. For example:
30 ``bzr launchpad-login user && bzr push lp:~/project/branch`` will now32 ``bzr launchpad-login user && bzr push lp:~/project/branch`` will now
3133
=== modified file 'bzrlib/builtins.py'
--- bzrlib/builtins.py 2010-07-20 10:18:05 +0000
+++ bzrlib/builtins.py 2010-08-01 07:14:39 +0000
@@ -206,8 +206,8 @@
206class cmd_status(Command):206class cmd_status(Command):
207 __doc__ = """Display status summary.207 __doc__ = """Display status summary.
208208
209 This reports on versioned and unknown files, reporting them209 This reports on files and changes, reporting them grouped by state.
210 grouped by state. Possible states are:210 Possible states are:
211211
212 added212 added
213 Versioned in the working copy but not in the previous revision.213 Versioned in the working copy but not in the previous revision.
@@ -230,6 +230,9 @@
230 unknown230 unknown
231 Not versioned and not matching an ignore pattern.231 Not versioned and not matching an ignore pattern.
232232
233 shelved
234 Shelved changes.
235
233 Additionally for directories, symlinks and files with an executable236 Additionally for directories, symlinks and files with an executable
234 bit, Bazaar indicates their type using a trailing character: '/', '@'237 bit, Bazaar indicates their type using a trailing character: '/', '@'
235 or '*' respectively.238 or '*' respectively.
@@ -5844,7 +5847,17 @@
5844 def run(self, revision=None, all=False, file_list=None, message=None,5847 def run(self, revision=None, all=False, file_list=None, message=None,
5845 writer=None, list=False, destroy=False, directory=u'.'):5848 writer=None, list=False, destroy=False, directory=u'.'):
5846 if list:5849 if list:
5847 return self.run_for_list()5850 from bzrlib.shelf import list_shelves
5851 tree = WorkingTree.open_containing('.')[0]
5852 self.add_cleanup(tree.lock_read().unlock)
5853 shelves = list_shelves(tree.get_shelf_manager())
5854 for s in shelves:
5855 self.outf.write(s)
5856 if shelves:
5857 return 1
5858 else:
5859 note('No shelved changes.')
5860 return 0
5848 from bzrlib.shelf_ui import Shelver5861 from bzrlib.shelf_ui import Shelver
5849 if writer is None:5862 if writer is None:
5850 writer = bzrlib.option.diff_writer_registry.get()5863 writer = bzrlib.option.diff_writer_registry.get()
@@ -5858,21 +5871,6 @@
5858 except errors.UserAbort:5871 except errors.UserAbort:
5859 return 05872 return 0
58605873
5861 def run_for_list(self):
5862 tree = WorkingTree.open_containing('.')[0]
5863 self.add_cleanup(tree.lock_read().unlock)
5864 manager = tree.get_shelf_manager()
5865 shelves = manager.active_shelves()
5866 if len(shelves) == 0:
5867 note('No shelved changes.')
5868 return 0
5869 for shelf_id in reversed(shelves):
5870 message = manager.get_metadata(shelf_id).get('message')
5871 if message is None:
5872 message = '<no message>'
5873 self.outf.write('%3d: %s\n' % (shelf_id, message))
5874 return 1
5875
58765874
5877class cmd_unshelve(Command):5875class cmd_unshelve(Command):
5878 __doc__ = """Restore shelved changes.5876 __doc__ = """Restore shelved changes.
58795877
=== modified file 'bzrlib/help_topics/__init__.py'
--- bzrlib/help_topics/__init__.py 2010-06-02 04:50:35 +0000
+++ bzrlib/help_topics/__init__.py 2010-08-01 07:14:39 +0000
@@ -581,6 +581,7 @@
581 D File deleted581 D File deleted
582 K File kind changed582 K File kind changed
583 M File modified583 M File modified
584 S Shelf
584585
585Column 3 - execute::586Column 3 - execute::
586587
587588
=== modified file 'bzrlib/shelf.py'
--- bzrlib/shelf.py 2010-04-30 11:03:59 +0000
+++ bzrlib/shelf.py 2010-08-01 07:14:39 +0000
@@ -15,6 +15,8 @@
15# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA15# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1616
1717
18from bzrlib.lazy_import import lazy_import
19lazy_import(globals(), """
18import errno20import errno
19import re21import re
2022
@@ -26,6 +28,7 @@
26 pack,28 pack,
27 transform,29 transform,
28)30)
31""")
2932
3033
31class ShelfCreator(object):34class ShelfCreator(object):
@@ -429,3 +432,21 @@
429 return active[-1]432 return active[-1]
430 else:433 else:
431 return None434 return None
435
436
437def list_shelves(manager):
438 """Return the current list of shelves as strings.
439
440 :param manager: Shelf manager for the tree.
441 """
442 shelves = manager.active_shelves()
443 output = []
444 if len(shelves) == 0:
445 return output
446 for shelf_id in reversed(shelves):
447 message = manager.get_metadata(shelf_id).get('message')
448 if message is None:
449 message = '<no message>'
450 output.append('%3d: %s\n' % (shelf_id, message))
451 return output
452
432453
=== modified file 'bzrlib/status.py'
--- bzrlib/status.py 2010-04-30 11:35:43 +0000
+++ bzrlib/status.py 2010-08-01 07:14:39 +0000
@@ -24,6 +24,7 @@
24 revision as _mod_revision,24 revision as _mod_revision,
25 )25 )
26import bzrlib.errors as errors26import bzrlib.errors as errors
27from bzrlib.shelf import list_shelves
27from bzrlib.trace import mutter, warning28from bzrlib.trace import mutter, warning
2829
29# TODO: when showing single-line logs, truncate to the width of the terminal30# TODO: when showing single-line logs, truncate to the width of the terminal
@@ -210,6 +211,15 @@
210 show_pending_merges(new, to_file, short, verbose=verbose)211 show_pending_merges(new, to_file, short, verbose=verbose)
211 if nonexistents:212 if nonexistents:
212 raise errors.PathsDoNotExist(nonexistents)213 raise errors.PathsDoNotExist(nonexistents)
214 shelves = list_shelves(wt.get_shelf_manager())
215 if shelves:
216 prefix = ''
217 if not short:
218 to_file.write("shelves:\n")
219 else:
220 prefix = ' S'
221 for s in shelves:
222 to_file.write(prefix + s)
213 finally:223 finally:
214 old.unlock()224 old.unlock()
215 new.unlock()225 new.unlock()
216226
=== modified file 'bzrlib/tests/blackbox/test_status.py'
--- bzrlib/tests/blackbox/test_status.py 2010-06-24 06:57:31 +0000
+++ bzrlib/tests/blackbox/test_status.py 2010-08-01 07:14:39 +0000
@@ -33,6 +33,7 @@
33 conflicts,33 conflicts,
34 errors,34 errors,
35 osutils,35 osutils,
36 shelf,
36 )37 )
37import bzrlib.branch38import bzrlib.branch
38from bzrlib.osutils import pathjoin39from bzrlib.osutils import pathjoin
@@ -520,6 +521,30 @@
520 out, err = self.run_bzr('status branch1 -rbranch:branch2')521 out, err = self.run_bzr('status branch1 -rbranch:branch2')
521 self.assertEqual('', out)522 self.assertEqual('', out)
522523
524 def test_shelve_status(self):
525 """Ensure that shelves are lists.
526 """
527 tree = self.make_branch_and_tree('.')
528 self.build_tree(['hello.c', 'bye.c'])
529 creator = shelf.ShelfCreator(tree, tree.basis_tree())
530 self.addCleanup(creator.finalize)
531 shelf_manager = tree.get_shelf_manager()
532 shelf_id = shelf_manager.shelve_changes(creator)
533 self.assertStatus([
534 'unknown:\n',
535 ' bye.c\n',
536 ' hello.c\n',
537 'shelves:\n',
538 ' 1: <no message>\n',
539 ],
540 tree)
541 self.assertStatus([
542 '? bye.c\n',
543 '? hello.c\n',
544 ' S 1: <no message>\n',
545 ],
546 tree, short=True)
547
523548
524class CheckoutStatus(BranchStatus):549class CheckoutStatus(BranchStatus):
525550
526551
=== modified file 'bzrlib/tests/test_shelf.py'
--- bzrlib/tests/test_shelf.py 2010-01-13 23:06:42 +0000
+++ bzrlib/tests/test_shelf.py 2010-08-01 07:14:39 +0000
@@ -729,6 +729,23 @@
729 unshelver.make_merger().do_merge()729 unshelver.make_merger().do_merge()
730 self.assertFileEqual('bar', 'tree/foo')730 self.assertFileEqual('bar', 'tree/foo')
731731
732 def test_list_shelves(self):
733 """Ensure shelf.list_shelves() works correctly.
734 """
735 tree = self.make_branch_and_tree('tree')
736 tree.commit('no-change commit')
737 tree.lock_write()
738 self.addCleanup(tree.unlock)
739 self.build_tree_contents([('tree/foo', 'bar')])
740 tree.add('foo', 'foo-id')
741 creator = shelf.ShelfCreator(tree, tree.basis_tree())
742 self.addCleanup(creator.finalize)
743 shelf_manager = tree.get_shelf_manager()
744 self.assertEqual([], shelf.list_shelves(shelf_manager))
745 shelf_id = shelf_manager.shelve_changes(creator)
746 self.assertEqual([' 1: <no message>\n'],
747 shelf.list_shelves(shelf_manager))
748
732 def test_get_metadata(self):749 def test_get_metadata(self):
733 tree = self.make_branch_and_tree('.')750 tree = self.make_branch_and_tree('.')
734 tree.lock_tree_write()751 tree.lock_tree_write()