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
1=== modified file 'NEWS'
2--- NEWS 2010-07-26 17:19:33 +0000
3+++ NEWS 2010-08-01 07:14:39 +0000
4@@ -25,6 +25,8 @@
5 New Features
6 ************
7
8+* ``status`` now lists shelved changes if any. (Parth Malwankar, #403687)
9+
10 * The ``lp:`` prefix will now use your known username (from
11 ``bzr launchpad-login``) to expand ``~`` to your username. For example:
12 ``bzr launchpad-login user && bzr push lp:~/project/branch`` will now
13
14=== modified file 'bzrlib/builtins.py'
15--- bzrlib/builtins.py 2010-07-20 10:18:05 +0000
16+++ bzrlib/builtins.py 2010-08-01 07:14:39 +0000
17@@ -206,8 +206,8 @@
18 class cmd_status(Command):
19 __doc__ = """Display status summary.
20
21- This reports on versioned and unknown files, reporting them
22- grouped by state. Possible states are:
23+ This reports on files and changes, reporting them grouped by state.
24+ Possible states are:
25
26 added
27 Versioned in the working copy but not in the previous revision.
28@@ -230,6 +230,9 @@
29 unknown
30 Not versioned and not matching an ignore pattern.
31
32+ shelved
33+ Shelved changes.
34+
35 Additionally for directories, symlinks and files with an executable
36 bit, Bazaar indicates their type using a trailing character: '/', '@'
37 or '*' respectively.
38@@ -5844,7 +5847,17 @@
39 def run(self, revision=None, all=False, file_list=None, message=None,
40 writer=None, list=False, destroy=False, directory=u'.'):
41 if list:
42- return self.run_for_list()
43+ from bzrlib.shelf import list_shelves
44+ tree = WorkingTree.open_containing('.')[0]
45+ self.add_cleanup(tree.lock_read().unlock)
46+ shelves = list_shelves(tree.get_shelf_manager())
47+ for s in shelves:
48+ self.outf.write(s)
49+ if shelves:
50+ return 1
51+ else:
52+ note('No shelved changes.')
53+ return 0
54 from bzrlib.shelf_ui import Shelver
55 if writer is None:
56 writer = bzrlib.option.diff_writer_registry.get()
57@@ -5858,21 +5871,6 @@
58 except errors.UserAbort:
59 return 0
60
61- def run_for_list(self):
62- tree = WorkingTree.open_containing('.')[0]
63- self.add_cleanup(tree.lock_read().unlock)
64- manager = tree.get_shelf_manager()
65- shelves = manager.active_shelves()
66- if len(shelves) == 0:
67- note('No shelved changes.')
68- return 0
69- for shelf_id in reversed(shelves):
70- message = manager.get_metadata(shelf_id).get('message')
71- if message is None:
72- message = '<no message>'
73- self.outf.write('%3d: %s\n' % (shelf_id, message))
74- return 1
75-
76
77 class cmd_unshelve(Command):
78 __doc__ = """Restore shelved changes.
79
80=== modified file 'bzrlib/help_topics/__init__.py'
81--- bzrlib/help_topics/__init__.py 2010-06-02 04:50:35 +0000
82+++ bzrlib/help_topics/__init__.py 2010-08-01 07:14:39 +0000
83@@ -581,6 +581,7 @@
84 D File deleted
85 K File kind changed
86 M File modified
87+ S Shelf
88
89 Column 3 - execute::
90
91
92=== modified file 'bzrlib/shelf.py'
93--- bzrlib/shelf.py 2010-04-30 11:03:59 +0000
94+++ bzrlib/shelf.py 2010-08-01 07:14:39 +0000
95@@ -15,6 +15,8 @@
96 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
97
98
99+from bzrlib.lazy_import import lazy_import
100+lazy_import(globals(), """
101 import errno
102 import re
103
104@@ -26,6 +28,7 @@
105 pack,
106 transform,
107 )
108+""")
109
110
111 class ShelfCreator(object):
112@@ -429,3 +432,21 @@
113 return active[-1]
114 else:
115 return None
116+
117+
118+def list_shelves(manager):
119+ """Return the current list of shelves as strings.
120+
121+ :param manager: Shelf manager for the tree.
122+ """
123+ shelves = manager.active_shelves()
124+ output = []
125+ if len(shelves) == 0:
126+ return output
127+ for shelf_id in reversed(shelves):
128+ message = manager.get_metadata(shelf_id).get('message')
129+ if message is None:
130+ message = '<no message>'
131+ output.append('%3d: %s\n' % (shelf_id, message))
132+ return output
133+
134
135=== modified file 'bzrlib/status.py'
136--- bzrlib/status.py 2010-04-30 11:35:43 +0000
137+++ bzrlib/status.py 2010-08-01 07:14:39 +0000
138@@ -24,6 +24,7 @@
139 revision as _mod_revision,
140 )
141 import bzrlib.errors as errors
142+from bzrlib.shelf import list_shelves
143 from bzrlib.trace import mutter, warning
144
145 # TODO: when showing single-line logs, truncate to the width of the terminal
146@@ -210,6 +211,15 @@
147 show_pending_merges(new, to_file, short, verbose=verbose)
148 if nonexistents:
149 raise errors.PathsDoNotExist(nonexistents)
150+ shelves = list_shelves(wt.get_shelf_manager())
151+ if shelves:
152+ prefix = ''
153+ if not short:
154+ to_file.write("shelves:\n")
155+ else:
156+ prefix = ' S'
157+ for s in shelves:
158+ to_file.write(prefix + s)
159 finally:
160 old.unlock()
161 new.unlock()
162
163=== modified file 'bzrlib/tests/blackbox/test_status.py'
164--- bzrlib/tests/blackbox/test_status.py 2010-06-24 06:57:31 +0000
165+++ bzrlib/tests/blackbox/test_status.py 2010-08-01 07:14:39 +0000
166@@ -33,6 +33,7 @@
167 conflicts,
168 errors,
169 osutils,
170+ shelf,
171 )
172 import bzrlib.branch
173 from bzrlib.osutils import pathjoin
174@@ -520,6 +521,30 @@
175 out, err = self.run_bzr('status branch1 -rbranch:branch2')
176 self.assertEqual('', out)
177
178+ def test_shelve_status(self):
179+ """Ensure that shelves are lists.
180+ """
181+ tree = self.make_branch_and_tree('.')
182+ self.build_tree(['hello.c', 'bye.c'])
183+ creator = shelf.ShelfCreator(tree, tree.basis_tree())
184+ self.addCleanup(creator.finalize)
185+ shelf_manager = tree.get_shelf_manager()
186+ shelf_id = shelf_manager.shelve_changes(creator)
187+ self.assertStatus([
188+ 'unknown:\n',
189+ ' bye.c\n',
190+ ' hello.c\n',
191+ 'shelves:\n',
192+ ' 1: <no message>\n',
193+ ],
194+ tree)
195+ self.assertStatus([
196+ '? bye.c\n',
197+ '? hello.c\n',
198+ ' S 1: <no message>\n',
199+ ],
200+ tree, short=True)
201+
202
203 class CheckoutStatus(BranchStatus):
204
205
206=== modified file 'bzrlib/tests/test_shelf.py'
207--- bzrlib/tests/test_shelf.py 2010-01-13 23:06:42 +0000
208+++ bzrlib/tests/test_shelf.py 2010-08-01 07:14:39 +0000
209@@ -729,6 +729,23 @@
210 unshelver.make_merger().do_merge()
211 self.assertFileEqual('bar', 'tree/foo')
212
213+ def test_list_shelves(self):
214+ """Ensure shelf.list_shelves() works correctly.
215+ """
216+ tree = self.make_branch_and_tree('tree')
217+ tree.commit('no-change commit')
218+ tree.lock_write()
219+ self.addCleanup(tree.unlock)
220+ self.build_tree_contents([('tree/foo', 'bar')])
221+ tree.add('foo', 'foo-id')
222+ creator = shelf.ShelfCreator(tree, tree.basis_tree())
223+ self.addCleanup(creator.finalize)
224+ shelf_manager = tree.get_shelf_manager()
225+ self.assertEqual([], shelf.list_shelves(shelf_manager))
226+ shelf_id = shelf_manager.shelve_changes(creator)
227+ self.assertEqual([' 1: <no message>\n'],
228+ shelf.list_shelves(shelf_manager))
229+
230 def test_get_metadata(self):
231 tree = self.make_branch_and_tree('.')
232 tree.lock_tree_write()