Merge lp:~parthm/bzr/403687-shelve-summary-in-status into lp:bzr

Proposed by Parth Malwankar
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: no longer in the source branch.
Merged at revision: 5444
Proposed branch: lp:~parthm/bzr/403687-shelve-summary-in-status
Merge into: lp:bzr
Diff against target: 117 lines (+50/-4)
4 files modified
NEWS (+6/-1)
bzrlib/shelf.py (+3/-0)
bzrlib/status.py (+19/-3)
bzrlib/tests/blackbox/test_status.py (+22/-0)
To merge this branch: bzr merge lp:~parthm/bzr/403687-shelve-summary-in-status
Reviewer Review Type Date Requested Status
Vincent Ladeuil Approve
Alexander Belchenko Approve
Review via email: mp+35218@code.launchpad.net

Commit message

'bzr status' now displays shelve summary (#403687).

Description of the change

=== Fixes bug #403687 ===
This patch adds a post_status hook to display a one line summary of shelves. If there are no shelves then nothing is displayed.

E.g.
[bzr-grep]% bzr st
modified:
  features.py
3 shelves exist. See "bzr shelve --list" for details.
[bzr-grep]%

To post a comment you must log in.
Revision history for this message
Alexander Belchenko (bialix) wrote :

+* ``bzr status`` now displays a summary of existing shelves after
+ the other status information. This us done using a ``post_status``

This *is* done, I guess.

I think you need to add direct test for list_shelves because it's a new public API.

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

Does this cope with tree types that don't support shelves, or is that
done automatically for all classes?

--
Martin

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

> +* ``bzr status`` now displays a summary of existing shelves after
> + the other status information. This us done using a ``post_status``
>
> This *is* done, I guess.
>
> I think you need to add direct test for list_shelves because it's a new public
> API.

Thanks for the review Alexander. I have made the above fixes.

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

> Does this cope with tree types that don't support shelves, or is that
> done automatically for all classes?
>

Good point. I am not too sure. What would be a good way to test this?

Revision history for this message
Alexander Belchenko (bialix) wrote :

Good for me.

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

Sorry to come late in the game, but I don't understand why list_shelves is needed at all.
Is this because you used it previously for 'bzr status' ?

status needs only a number of shelves so active_shelves() is enough (no need to build more
data just to throw it away).

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

> Sorry to come late in the game, but I don't understand why list_shelves is
> needed at all.
> Is this because you used it previously for 'bzr status' ?
>
> status needs only a number of shelves so active_shelves() is enough (no need
> to build more
> data just to throw it away).

I was not aware of active_shelves. This is definitely shorter and cleaner. Thanks. Fixed.

Revision history for this message
Alexander Belchenko (bialix) wrote :

I think Vincent or somebody else should look the last time on the patch and just approve this. I believe Parth has fixed all issues now.

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

Doh !
This looks straight forward now ! Well done.

Check that the NEWS entry is for the right release and land !

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

sent to pqm by email

Revision history for this message
Parth Malwankar (parthm) 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 'NEWS'
2--- NEWS 2010-09-24 02:19:28 +0000
3+++ NEWS 2010-09-24 15:15:56 +0000
4@@ -18,10 +18,15 @@
5
6 * Add ``mainline`` revision specifier, which selects the revision that
7 merged a specified revision into the mainline. (Aaron Bentley)
8-
9+
10 * Add ``annotate`` revision specifier, which selects the revision that
11 introduced a specified line of a file. (Aaron Bentley)
12
13+* ``bzr status`` now displays a summary of existing shelves after
14+ the other status information. This is done using a ``post_status``
15+ hook.
16+ (Parth Malwankar, #403687)
17+
18 Bug Fixes
19 *********
20
21
22=== modified file 'bzrlib/shelf.py'
23--- bzrlib/shelf.py 2010-04-30 11:03:59 +0000
24+++ bzrlib/shelf.py 2010-09-24 15:15:56 +0000
25@@ -18,6 +18,8 @@
26 import errno
27 import re
28
29+from bzrlib.lazy_import import lazy_import
30+lazy_import(globals(), """
31 from bzrlib import (
32 bencode,
33 errors,
34@@ -26,6 +28,7 @@
35 pack,
36 transform,
37 )
38+""")
39
40
41 class ShelfCreator(object):
42
43=== modified file 'bzrlib/status.py'
44--- bzrlib/status.py 2010-08-31 13:49:48 +0000
45+++ bzrlib/status.py 2010-09-24 15:15:56 +0000
46@@ -398,9 +398,6 @@
47 (2, 3), None))
48
49
50-hooks = StatusHooks()
51-
52-
53 class StatusHookParams(object):
54 """Object holding parameters passed to post_status hooks.
55
56@@ -441,3 +438,22 @@
57 self.old_tree, self.new_tree, self.to_file, self.versioned,
58 self.show_ids, self.short, self.verbose)
59
60+
61+def _show_shelve_summary(params):
62+ """post_status hook to display a summary of shelves.
63+
64+ :param params: StatusHookParams.
65+ """
66+ manager = params.new_tree.get_shelf_manager()
67+ shelves = manager.active_shelves()
68+ if shelves:
69+ params.to_file.write('%d shelves exist. '
70+ 'See "bzr shelve --list" for details.\n' % len(shelves))
71+
72+
73+hooks = StatusHooks()
74+
75+
76+hooks.install_named_hook('post_status', _show_shelve_summary,
77+ 'bzr status')
78+
79
80=== modified file 'bzrlib/tests/blackbox/test_status.py'
81--- bzrlib/tests/blackbox/test_status.py 2010-06-24 06:57:31 +0000
82+++ bzrlib/tests/blackbox/test_status.py 2010-09-24 15:15:56 +0000
83@@ -33,6 +33,7 @@
84 conflicts,
85 errors,
86 osutils,
87+ status,
88 )
89 import bzrlib.branch
90 from bzrlib.osutils import pathjoin
91@@ -520,6 +521,27 @@
92 out, err = self.run_bzr('status branch1 -rbranch:branch2')
93 self.assertEqual('', out)
94
95+ def test_status_with_shelves(self):
96+ """Ensure that _show_shelve_summary handler works.
97+ """
98+ wt = self.make_branch_and_tree('.')
99+ self.build_tree(['hello.c'])
100+ wt.add('hello.c')
101+ self.run_bzr(['shelve', '--all', '-m', 'foo'])
102+ self.build_tree(['bye.c'])
103+ wt.add('bye.c')
104+ # As TestCase.setUp clears all hooks, we install this default
105+ # post_status hook handler for the test.
106+ status.hooks.install_named_hook('post_status',
107+ status._show_shelve_summary,
108+ 'bzr status')
109+ self.assertStatus([
110+ 'added:\n',
111+ ' bye.c\n',
112+ '1 shelves exist. See "bzr shelve --list" for details.\n',
113+ ],
114+ wt)
115+
116
117 class CheckoutStatus(BranchStatus):
118