Rev 6451: (jelmer) Add HPSS call for ``BzrDir.get_branches`` (Jelmer Vernooij) in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.5/

Patch Queue Manager pqm at pqm.ubuntu.com
Thu Jan 19 15:57:11 UTC 2012


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.5/

------------------------------------------------------------
revno: 6451 [merge]
revision-id: pqm at pqm.ubuntu.com-20120119155710-h465ytc8xq03ccn9
parent: pqm at pqm.ubuntu.com-20120119153024-nmdwegbgkjh5a7up
parent: jelmer at samba.org-20120119141755-g0kmmvr2dcbb5r0v
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.5
timestamp: Thu 2012-01-19 15:57:10 +0000
message:
  (jelmer) Add HPSS call for ``BzrDir.get_branches`` (Jelmer Vernooij)
modified:
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/smart/bzrdir.py         bzrdir.py-20061122024551-ol0l0o0oofsu9b3t-1
  bzrlib/smart/request.py        request.py-20061108095550-gunadhxmzkdjfeek-1
  bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
  bzrlib/tests/test_smart.py     test_smart.py-20061122024551-ol0l0o0oofsu9b3t-2
  doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2012-01-18 17:37:38 +0000
+++ b/bzrlib/remote.py	2012-01-19 14:17:55 +0000
@@ -679,6 +679,24 @@
         b = self.open_branch(name=name)
         return b._format
 
+    def get_branches(self, possible_transports=None, ignore_fallbacks=False):
+        path = self._path_for_remote_call(self._client)
+        try:
+            response, handler = self._call_expecting_body(
+                'BzrDir.get_branches', path)
+        except errors.UnknownSmartMethod:
+            self._ensure_real()
+            return self._real_bzrdir.get_branches()
+        if response[0] != "success":
+            raise errors.UnexpectedSmartServerResponse(response)
+        body = bencode.bdecode(handler.read_body_bytes())
+        ret = {}
+        for (name, value) in body.iteritems():
+            ret[name] = self._open_branch(name, value[0], value[1],
+                possible_transports=possible_transports,
+                ignore_fallbacks=ignore_fallbacks)
+        return ret
+
     def set_branch_reference(self, target_branch, name=None):
         """See BzrDir.set_branch_reference()."""
         self._ensure_real()
@@ -729,25 +747,15 @@
         """See BzrDir._get_tree_branch()."""
         return None, self.open_branch(name=name)
 
-    def open_branch(self, name=None, unsupported=False,
-                    ignore_fallbacks=False, possible_transports=None):
-        if name is None:
-            name = self._get_selected_branch()
-        if unsupported:
-            raise NotImplementedError('unsupported flag support not implemented yet.')
-        if self._next_open_branch_result is not None:
-            # See create_branch for details.
-            result = self._next_open_branch_result
-            self._next_open_branch_result = None
-            return result
-        response = self._get_branch_reference()
-        if response[0] == 'ref':
+    def _open_branch(self, name, kind, location_or_format,
+                     ignore_fallbacks=False, possible_transports=None):
+        if kind == 'ref':
             # a branch reference, use the existing BranchReference logic.
             format = BranchReferenceFormat()
             return format.open(self, name=name, _found=True,
-                location=response[1], ignore_fallbacks=ignore_fallbacks,
+                location=location_or_format, ignore_fallbacks=ignore_fallbacks,
                 possible_transports=possible_transports)
-        branch_format_name = response[1]
+        branch_format_name = location_or_format
         if not branch_format_name:
             branch_format_name = None
         format = RemoteBranchFormat(network_name=branch_format_name)
@@ -755,6 +763,22 @@
             setup_stacking=not ignore_fallbacks, name=name,
             possible_transports=possible_transports)
 
+    def open_branch(self, name=None, unsupported=False,
+                    ignore_fallbacks=False, possible_transports=None):
+        if unsupported:
+            raise NotImplementedError('unsupported flag support not implemented yet.')
+        if self._next_open_branch_result is not None:
+            # See create_branch for details.
+            result = self._next_open_branch_result
+            self._next_open_branch_result = None
+            return result
+        response = self._get_branch_reference()
+        if name is None:
+            name = self._get_selected_branch()
+        return self._open_branch(name, response[0], response[1],
+            possible_transports=possible_transports,
+            ignore_fallbacks=ignore_fallbacks)
+
     def _open_repo_v1(self, path):
         verb = 'BzrDir.find_repository'
         response = self._call(verb, path)

=== modified file 'bzrlib/smart/bzrdir.py'
--- a/bzrlib/smart/bzrdir.py	2012-01-07 01:06:26 +0000
+++ b/bzrlib/smart/bzrdir.py	2012-01-19 12:08:42 +0000
@@ -18,7 +18,13 @@
 
 from __future__ import absolute_import
 
-from bzrlib import branch, errors, repository, urlutils
+from bzrlib import (
+    bencode,
+    branch,
+    errors,
+    repository,
+    urlutils,
+    )
 from bzrlib.bzrdir import (
     BzrDir,
     BzrDirFormat,
@@ -425,6 +431,24 @@
         return SuccessfulSmartServerResponse((), content)
 
 
+class SmartServerBzrDirRequestGetBranches(SmartServerRequestBzrDir):
+
+    def do_bzrdir_request(self):
+        """Get the branches in a control directory.
+        
+        The body is a bencoded dictionary, with values similar to the return
+        value of the open branch request.
+        """
+        branches = self._bzrdir.get_branches()
+        ret = {}
+        for name, b in branches.iteritems():
+            if name is None:
+                name = ""
+            ret[name] = ("branch", b._format.network_name())
+        return SuccessfulSmartServerResponse(
+            ("success", ), bencode.bencode(ret))
+
+
 class SmartServerRequestInitializeBzrDir(SmartServerRequest):
 
     def do(self, path):

=== modified file 'bzrlib/smart/request.py'
--- a/bzrlib/smart/request.py	2011-12-18 12:46:49 +0000
+++ b/bzrlib/smart/request.py	2012-01-06 22:06:36 +0000
@@ -606,6 +606,9 @@
     'BzrDir.find_repositoryV3', 'bzrlib.smart.bzrdir',
     'SmartServerRequestFindRepositoryV3', info='read')
 request_handlers.register_lazy(
+    'BzrDir.get_branches', 'bzrlib.smart.bzrdir',
+    'SmartServerBzrDirRequestGetBranches', info='read')
+request_handlers.register_lazy(
     'BzrDir.get_config_file', 'bzrlib.smart.bzrdir',
     'SmartServerBzrDirRequestConfigFile', info='read')
 request_handlers.register_lazy(

=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py	2012-01-02 10:24:02 +0000
+++ b/bzrlib/tests/test_remote.py	2012-01-06 22:06:36 +0000
@@ -28,12 +28,12 @@
 import zlib
 
 from bzrlib import (
+    bencode,
     branch,
     bzrdir,
     config,
     controldir,
     errors,
-    graph as _mod_graph,
     inventory,
     inventory_delta,
     remote,
@@ -541,6 +541,40 @@
         self.assertFinished(client)
 
 
+class TestBzrDirGetBranches(TestRemote):
+
+    def test_get_branches(self):
+        transport = MemoryTransport()
+        client = FakeClient(transport.base)
+        reference_bzrdir_format = bzrdir.format_registry.get('default')()
+        branch_name = reference_bzrdir_format.get_branch_format().network_name()
+        client.add_success_response_with_body(
+            bencode.bencode({
+                "foo": ("branch", branch_name),
+                "": ("branch", branch_name)}), "success")
+        client.add_success_response(
+            'ok', '', 'no', 'no', 'no',
+                reference_bzrdir_format.repository_format.network_name())
+        client.add_error_response('NotStacked')
+        client.add_success_response(
+            'ok', '', 'no', 'no', 'no',
+                reference_bzrdir_format.repository_format.network_name())
+        client.add_error_response('NotStacked')
+        transport.mkdir('quack')
+        transport = transport.clone('quack')
+        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
+            _client=client)
+        result = a_bzrdir.get_branches()
+        self.assertEquals(["", "foo"], result.keys())
+        self.assertEqual(
+            [('call_expecting_body', 'BzrDir.get_branches', ('quack/',)),
+             ('call', 'BzrDir.find_repositoryV3', ('quack/', )),
+             ('call', 'Branch.get_stacked_on_url', ('quack/', )),
+             ('call', 'BzrDir.find_repositoryV3', ('quack/', )),
+             ('call', 'Branch.get_stacked_on_url', ('quack/', ))],
+            client._calls)
+
+
 class TestBzrDirDestroyBranch(TestRemote):
 
     def test_destroy_default(self):

=== modified file 'bzrlib/tests/test_smart.py'
--- a/bzrlib/tests/test_smart.py	2011-12-14 21:24:07 +0000
+++ b/bzrlib/tests/test_smart.py	2012-01-06 22:06:36 +0000
@@ -28,6 +28,7 @@
 import zlib
 
 from bzrlib import (
+    bencode,
     branch as _mod_branch,
     bzrdir,
     errors,
@@ -458,6 +459,32 @@
         self.assertEqual(expected, request.execute(''))
 
 
+class TestSmartServerBzrDirRequestGetBranches(
+    tests.TestCaseWithMemoryTransport):
+    """Tests for BzrDir.get_branches."""
+
+    def test_simple(self):
+        backing = self.get_transport()
+        branch = self.make_branch('.')
+        request_class = smart_dir.SmartServerBzrDirRequestGetBranches
+        request = request_class(backing)
+        local_result = bencode.bencode(
+            {"": ("branch", branch._format.network_name())})
+        expected = smart_req.SuccessfulSmartServerResponse(
+            ("success", ), local_result)
+        self.assertEqual(expected, request.execute(''))
+
+    def test_empty(self):
+        backing = self.get_transport()
+        dir = self.make_bzrdir('.')
+        request_class = smart_dir.SmartServerBzrDirRequestGetBranches
+        request = request_class(backing)
+        local_result = bencode.bencode({})
+        expected = smart_req.SuccessfulSmartServerResponse(
+            ('success',), local_result)
+        self.assertEqual(expected, request.execute(''))
+
+
 class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithMemoryTransport):
 
     def test_empty_dir(self):
@@ -2500,6 +2527,8 @@
             smart_dir.SmartServerBzrDirRequestCheckoutMetaDir)
         self.assertHandlerEqual('BzrDir.cloning_metadir',
             smart_dir.SmartServerBzrDirRequestCloningMetaDir)
+        self.assertHandlerEqual('BzrDir.get_branches',
+            smart_dir.SmartServerBzrDirRequestGetBranches)
         self.assertHandlerEqual('BzrDir.get_config_file',
             smart_dir.SmartServerBzrDirRequestConfigFile)
         self.assertHandlerEqual('BzrDir.open_branch',

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2012-01-19 15:03:38 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2012-01-19 15:57:10 +0000
@@ -29,6 +29,8 @@
 * "bzr switch -b" in a standalone tree will now create a colocated branch.
   (Jelmer Vernooij, #918197)
 
+* New HPSS call for ``BzrDir.get_branches``. (Jelmer Vernooij, #894460)
+
 Bug Fixes
 *********
 




More information about the bazaar-commits mailing list