Merge lp:~jelmer/bzr/hpss-get-branches into lp:bzr

Proposed by Jelmer Vernooij
Status: Superseded
Proposed branch: lp:~jelmer/bzr/hpss-get-branches
Merge into: lp:bzr
Diff against target: 262 lines (+131/-15)
6 files modified
bzrlib/remote.py (+37/-13)
bzrlib/smart/bzrdir.py (+25/-1)
bzrlib/smart/request.py (+3/-0)
bzrlib/tests/test_remote.py (+35/-1)
bzrlib/tests/test_smart.py (+29/-0)
doc/en/release-notes/bzr-2.5.txt (+2/-0)
To merge this branch: bzr merge lp:~jelmer/bzr/hpss-get-branches
Reviewer Review Type Date Requested Status
Vincent Ladeuil Approve
Review via email: mp+87824@code.launchpad.net

This proposal has been superseded by a proposal from 2012-01-19.

Description of the change

Add HPSS call for BzrDir.get_branches.

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

Sounds fine.

Do we still support receiving None for a branch name there ? (If a newer client talks to an older server ?).

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/remote.py'
2--- bzrlib/remote.py 2012-01-04 16:02:14 +0000
3+++ bzrlib/remote.py 2012-01-06 22:19:24 +0000
4@@ -677,6 +677,24 @@
5 b = self.open_branch(name=name)
6 return b._format
7
8+ def get_branches(self, possible_transports=None, ignore_fallbacks=False):
9+ path = self._path_for_remote_call(self._client)
10+ try:
11+ response, handler = self._call_expecting_body(
12+ 'BzrDir.get_branches', path)
13+ except errors.UnknownSmartMethod:
14+ self._ensure_real()
15+ return self._real_bzrdir.get_branches()
16+ if response[0] != "success":
17+ raise errors.UnexpectedSmartServerResponse(response)
18+ body = bencode.bdecode(handler.read_body_bytes())
19+ ret = {}
20+ for (name, value) in body.iteritems():
21+ ret[name] = self._open_branch(name, value[0], value[1],
22+ possible_transports=possible_transports,
23+ ignore_fallbacks=ignore_fallbacks)
24+ return ret
25+
26 def get_branch_reference(self, name=None):
27 """See BzrDir.get_branch_reference()."""
28 if name is not None:
29@@ -722,23 +740,15 @@
30 """See BzrDir._get_tree_branch()."""
31 return None, self.open_branch(name=name)
32
33- def open_branch(self, name=None, unsupported=False,
34- ignore_fallbacks=False, possible_transports=None):
35- if unsupported:
36- raise NotImplementedError('unsupported flag support not implemented yet.')
37- if self._next_open_branch_result is not None:
38- # See create_branch for details.
39- result = self._next_open_branch_result
40- self._next_open_branch_result = None
41- return result
42- response = self._get_branch_reference()
43- if response[0] == 'ref':
44+ def _open_branch(self, name, kind, location_or_format,
45+ ignore_fallbacks=False, possible_transports=None):
46+ if kind == 'ref':
47 # a branch reference, use the existing BranchReference logic.
48 format = BranchReferenceFormat()
49 return format.open(self, name=name, _found=True,
50- location=response[1], ignore_fallbacks=ignore_fallbacks,
51+ location=location_or_format, ignore_fallbacks=ignore_fallbacks,
52 possible_transports=possible_transports)
53- branch_format_name = response[1]
54+ branch_format_name = location_or_format
55 if not branch_format_name:
56 branch_format_name = None
57 format = RemoteBranchFormat(network_name=branch_format_name)
58@@ -746,6 +756,20 @@
59 setup_stacking=not ignore_fallbacks, name=name,
60 possible_transports=possible_transports)
61
62+ def open_branch(self, name=None, unsupported=False,
63+ ignore_fallbacks=False, possible_transports=None):
64+ if unsupported:
65+ raise NotImplementedError('unsupported flag support not implemented yet.')
66+ if self._next_open_branch_result is not None:
67+ # See create_branch for details.
68+ result = self._next_open_branch_result
69+ self._next_open_branch_result = None
70+ return result
71+ response = self._get_branch_reference()
72+ return self._open_branch(name, response[0], response[1],
73+ possible_transports=possible_transports,
74+ ignore_fallbacks=ignore_fallbacks)
75+
76 def _open_repo_v1(self, path):
77 verb = 'BzrDir.find_repository'
78 response = self._call(verb, path)
79
80=== modified file 'bzrlib/smart/bzrdir.py'
81--- bzrlib/smart/bzrdir.py 2011-12-19 13:23:58 +0000
82+++ bzrlib/smart/bzrdir.py 2012-01-06 22:19:24 +0000
83@@ -18,7 +18,13 @@
84
85 from __future__ import absolute_import
86
87-from bzrlib import branch, errors, repository, urlutils
88+from bzrlib import (
89+ bencode,
90+ branch,
91+ errors,
92+ repository,
93+ urlutils,
94+ )
95 from bzrlib.bzrdir import (
96 BzrDir,
97 BzrDirFormat,
98@@ -425,6 +431,24 @@
99 return SuccessfulSmartServerResponse((), content)
100
101
102+class SmartServerBzrDirRequestGetBranches(SmartServerRequestBzrDir):
103+
104+ def do_bzrdir_request(self):
105+ """Get the branches in a control directory.
106+
107+ The body is a bencoded dictionary, with values similar to the return
108+ value of the open branch request.
109+ """
110+ branches = self._bzrdir.get_branches()
111+ ret = {}
112+ for name, b in branches.iteritems():
113+ if name is None:
114+ name = ""
115+ ret[name] = ("branch", b._format.network_name())
116+ return SuccessfulSmartServerResponse(
117+ ("success", ), bencode.bencode(ret))
118+
119+
120 class SmartServerRequestInitializeBzrDir(SmartServerRequest):
121
122 def do(self, path):
123
124=== modified file 'bzrlib/smart/request.py'
125--- bzrlib/smart/request.py 2011-12-18 12:46:49 +0000
126+++ bzrlib/smart/request.py 2012-01-06 22:19:24 +0000
127@@ -606,6 +606,9 @@
128 'BzrDir.find_repositoryV3', 'bzrlib.smart.bzrdir',
129 'SmartServerRequestFindRepositoryV3', info='read')
130 request_handlers.register_lazy(
131+ 'BzrDir.get_branches', 'bzrlib.smart.bzrdir',
132+ 'SmartServerBzrDirRequestGetBranches', info='read')
133+request_handlers.register_lazy(
134 'BzrDir.get_config_file', 'bzrlib.smart.bzrdir',
135 'SmartServerBzrDirRequestConfigFile', info='read')
136 request_handlers.register_lazy(
137
138=== modified file 'bzrlib/tests/test_remote.py'
139--- bzrlib/tests/test_remote.py 2012-01-02 10:24:02 +0000
140+++ bzrlib/tests/test_remote.py 2012-01-06 22:19:24 +0000
141@@ -28,12 +28,12 @@
142 import zlib
143
144 from bzrlib import (
145+ bencode,
146 branch,
147 bzrdir,
148 config,
149 controldir,
150 errors,
151- graph as _mod_graph,
152 inventory,
153 inventory_delta,
154 remote,
155@@ -541,6 +541,40 @@
156 self.assertFinished(client)
157
158
159+class TestBzrDirGetBranches(TestRemote):
160+
161+ def test_get_branches(self):
162+ transport = MemoryTransport()
163+ client = FakeClient(transport.base)
164+ reference_bzrdir_format = bzrdir.format_registry.get('default')()
165+ branch_name = reference_bzrdir_format.get_branch_format().network_name()
166+ client.add_success_response_with_body(
167+ bencode.bencode({
168+ "foo": ("branch", branch_name),
169+ "": ("branch", branch_name)}), "success")
170+ client.add_success_response(
171+ 'ok', '', 'no', 'no', 'no',
172+ reference_bzrdir_format.repository_format.network_name())
173+ client.add_error_response('NotStacked')
174+ client.add_success_response(
175+ 'ok', '', 'no', 'no', 'no',
176+ reference_bzrdir_format.repository_format.network_name())
177+ client.add_error_response('NotStacked')
178+ transport.mkdir('quack')
179+ transport = transport.clone('quack')
180+ a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
181+ _client=client)
182+ result = a_bzrdir.get_branches()
183+ self.assertEquals(["", "foo"], result.keys())
184+ self.assertEqual(
185+ [('call_expecting_body', 'BzrDir.get_branches', ('quack/',)),
186+ ('call', 'BzrDir.find_repositoryV3', ('quack/', )),
187+ ('call', 'Branch.get_stacked_on_url', ('quack/', )),
188+ ('call', 'BzrDir.find_repositoryV3', ('quack/', )),
189+ ('call', 'Branch.get_stacked_on_url', ('quack/', ))],
190+ client._calls)
191+
192+
193 class TestBzrDirDestroyBranch(TestRemote):
194
195 def test_destroy_default(self):
196
197=== modified file 'bzrlib/tests/test_smart.py'
198--- bzrlib/tests/test_smart.py 2011-12-14 21:24:07 +0000
199+++ bzrlib/tests/test_smart.py 2012-01-06 22:19:24 +0000
200@@ -28,6 +28,7 @@
201 import zlib
202
203 from bzrlib import (
204+ bencode,
205 branch as _mod_branch,
206 bzrdir,
207 errors,
208@@ -458,6 +459,32 @@
209 self.assertEqual(expected, request.execute(''))
210
211
212+class TestSmartServerBzrDirRequestGetBranches(
213+ tests.TestCaseWithMemoryTransport):
214+ """Tests for BzrDir.get_branches."""
215+
216+ def test_simple(self):
217+ backing = self.get_transport()
218+ branch = self.make_branch('.')
219+ request_class = smart_dir.SmartServerBzrDirRequestGetBranches
220+ request = request_class(backing)
221+ local_result = bencode.bencode(
222+ {"": ("branch", branch._format.network_name())})
223+ expected = smart_req.SuccessfulSmartServerResponse(
224+ ("success", ), local_result)
225+ self.assertEqual(expected, request.execute(''))
226+
227+ def test_empty(self):
228+ backing = self.get_transport()
229+ dir = self.make_bzrdir('.')
230+ request_class = smart_dir.SmartServerBzrDirRequestGetBranches
231+ request = request_class(backing)
232+ local_result = bencode.bencode({})
233+ expected = smart_req.SuccessfulSmartServerResponse(
234+ ('success',), local_result)
235+ self.assertEqual(expected, request.execute(''))
236+
237+
238 class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithMemoryTransport):
239
240 def test_empty_dir(self):
241@@ -2500,6 +2527,8 @@
242 smart_dir.SmartServerBzrDirRequestCheckoutMetaDir)
243 self.assertHandlerEqual('BzrDir.cloning_metadir',
244 smart_dir.SmartServerBzrDirRequestCloningMetaDir)
245+ self.assertHandlerEqual('BzrDir.get_branches',
246+ smart_dir.SmartServerBzrDirRequestGetBranches)
247 self.assertHandlerEqual('BzrDir.get_config_file',
248 smart_dir.SmartServerBzrDirRequestConfigFile)
249 self.assertHandlerEqual('BzrDir.open_branch',
250
251=== modified file 'doc/en/release-notes/bzr-2.5.txt'
252--- doc/en/release-notes/bzr-2.5.txt 2012-01-06 14:09:04 +0000
253+++ doc/en/release-notes/bzr-2.5.txt 2012-01-06 22:19:24 +0000
254@@ -40,6 +40,8 @@
255
256 * New HPSS call for ``Repository.reconcile``. (Jelmer Vernooij, #894455)
257
258+* New HPSS call for ``BzrDir.get_branches``. (Jelmer Vernooij, #894460)
259+
260 * Merge now has two new hooks ``pre_merge`` and ``post_merge``
261 that are called before and after a merge and can make
262 additional modifications to the trees involved.