Rev 4079: Add a Branch.get_parent remote call for RemoteBranch. in http://people.ubuntu.com/~robertc/baz2.0/branch.roundtrips

Robert Collins robertc at robertcollins.net
Thu Mar 5 05:26:35 GMT 2009


At http://people.ubuntu.com/~robertc/baz2.0/branch.roundtrips

------------------------------------------------------------
revno: 4079
revision-id: robertc at robertcollins.net-20090305052624-ejso9br8bxv68twx
parent: pqm at pqm.ubuntu.com-20090304163710-r7hhqdi9f3jsbe5g
committer: Robert Collins <robertc at robertcollins.net>
branch nick: branch.roundtrips
timestamp: Thu 2009-03-05 16:26:24 +1100
message:
  Add a Branch.get_parent remote call for RemoteBranch.
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2009-03-04 14:01:30 +0000
+++ b/bzrlib/branch.py	2009-03-05 05:26:24 +0000
@@ -768,7 +768,20 @@
         pattern is that the user can override it by specifying a
         location.
         """
-        raise NotImplementedError(self.get_parent)
+        parent = self._get_parent_location()
+        if parent is None:
+            return parent
+        # This is an old-format absolute path to a local branch
+        # turn it into a url
+        if parent.startswith('/'):
+            parent = urlutils.local_path_to_url(parent.decode('utf8'))
+        try:
+            return urlutils.join(self.base[:-1], parent)
+        except errors.InvalidURLJoin, e:
+            raise errors.InaccessibleParent(parent, self.base)
+
+    def _get_parent_location(self):
+        raise NotImplementedError(self._get_parent_location)
 
     def _set_config_location(self, name, url, config=None,
                              make_relative=False):
@@ -2081,20 +2094,6 @@
         result.new_revno, result.new_revid = target.last_revision_info()
         return result
 
-    def get_parent(self):
-        """See Branch.get_parent."""
-        parent = self._get_parent_location()
-        if parent is None:
-            return parent
-        # This is an old-format absolute path to a local branch
-        # turn it into a url
-        if parent.startswith('/'):
-            parent = urlutils.local_path_to_url(parent.decode('utf8'))
-        try:
-            return urlutils.join(self.base[:-1], parent)
-        except errors.InvalidURLJoin, e:
-            raise errors.InaccessibleParent(parent, self.base)
-
     def get_stacked_on_url(self):
         raise errors.UnstackableBranchFormat(self._format, self.base)
 

=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2009-03-03 07:22:25 +0000
+++ b/bzrlib/remote.py	2009-03-05 05:26:24 +0000
@@ -2030,15 +2030,23 @@
             hook(self, rev_history)
         self._cache_revision_history(rev_history)
 
-    def get_parent(self):
+    def _get_parent_location(self):
+        medium = self._client._medium
+        if medium._is_remote_before((1, 13)):
+            return self._vfs_get_parent_location()
+        try:
+            response = self._call('Branch.get_parent',
+                self._remote_path())
+        except errors.UnknownSmartMethod:
+            return self._vfs_get_parent_location()
+        if not response:
+            return None
+        return response
+
+    def _vfs_get_parent_location(self):
         self._ensure_real()
         return self._real_branch.get_parent()
 
-    def _get_parent_location(self):
-        # Used by tests, when checking normalisation of given vs stored paths.
-        self._ensure_real()
-        return self._real_branch._get_parent_location()
-
     def set_parent(self, url):
         self._ensure_real()
         return self._real_branch.set_parent(url)

=== modified file 'bzrlib/smart/branch.py'
--- a/bzrlib/smart/branch.py	2009-02-23 15:29:35 +0000
+++ b/bzrlib/smart/branch.py	2009-03-05 05:26:24 +0000
@@ -92,6 +92,14 @@
         return SuccessfulSmartServerResponse( ('ok', ), content)
 
 
+class SmartServerBranchGetParent(SmartServerBranchRequest):
+
+    def do_with_branch(self, branch):
+        """Return the parent of branch."""
+        parent = branch._get_parent_location() or ''
+        return SuccessfulSmartServerResponse((parent))
+
+
 class SmartServerBranchRequestGetStackedOnURL(SmartServerBranchRequest):
 
     def do_with_branch(self, branch):

=== modified file 'bzrlib/smart/request.py'
--- a/bzrlib/smart/request.py	2009-03-03 03:27:51 +0000
+++ b/bzrlib/smart/request.py	2009-03-05 05:26:24 +0000
@@ -390,6 +390,8 @@
 request_handlers.register_lazy(
     'Branch.get_config_file', 'bzrlib.smart.branch', 'SmartServerBranchGetConfigFile')
 request_handlers.register_lazy(
+    'Branch.get_parent', 'bzrlib.smart.branch', 'SmartServerBranchGetParent')
+request_handlers.register_lazy(
     'Branch.get_stacked_on_url', 'bzrlib.smart.branch', 'SmartServerBranchRequestGetStackedOnURL')
 request_handlers.register_lazy(
     'Branch.last_revision_info', 'bzrlib.smart.branch', 'SmartServerBranchRequestLastRevisionInfo')

=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py	2009-03-03 08:12:05 +0000
+++ b/bzrlib/tests/test_remote.py	2009-03-05 05:26:24 +0000
@@ -704,6 +704,56 @@
         return RemoteBranch(bzrdir, repo, _client=client)
 
 
+class TestBranchGetParent(RemoteBranchTestCase):
+
+    def test_no_parent(self):
+        # in an empty branch we decode the response properly
+        transport = MemoryTransport()
+        client = FakeClient(transport.base)
+        client.add_expected_call(
+            'Branch.get_stacked_on_url', ('quack/',),
+            'error', ('NotStacked',))
+        client.add_expected_call(
+            'Branch.get_parent', ('quack/',),
+            'success', (''))
+        transport.mkdir('quack')
+        transport = transport.clone('quack')
+        branch = self.make_remote_branch(transport, client)
+        result = branch.get_parent()
+        client.finished_test()
+        self.assertEqual(None, result)
+
+    def test_parent_relative(self):
+        transport = MemoryTransport()
+        client = FakeClient(transport.base)
+        client.add_expected_call(
+            'Branch.get_stacked_on_url', ('kwaak/',),
+            'error', ('NotStacked',))
+        client.add_expected_call(
+            'Branch.get_parent', ('kwaak/',),
+            'success', ('../foo/'))
+        transport.mkdir('kwaak')
+        transport = transport.clone('kwaak')
+        branch = self.make_remote_branch(transport, client)
+        result = branch.get_parent()
+        self.assertEqual(transport.clone('../foo').base, result)
+
+    def test_parent_absolute(self):
+        transport = MemoryTransport()
+        client = FakeClient(transport.base)
+        client.add_expected_call(
+            'Branch.get_stacked_on_url', ('kwaak/',),
+            'error', ('NotStacked',))
+        client.add_expected_call(
+            'Branch.get_parent', ('kwaak/',),
+            'success', ('http://foo/'))
+        transport.mkdir('kwaak')
+        transport = transport.clone('kwaak')
+        branch = self.make_remote_branch(transport, client)
+        result = branch.get_parent()
+        self.assertEqual('http://foo/', result)
+
+
 class TestBranchLastRevisionInfo(RemoteBranchTestCase):
 
     def test_empty_branch(self):

=== modified file 'bzrlib/tests/test_smart.py'
--- a/bzrlib/tests/test_smart.py	2009-03-03 03:27:51 +0000
+++ b/bzrlib/tests/test_smart.py	2009-03-05 05:26:24 +0000
@@ -658,6 +658,25 @@
         self.assertEqual('child-1', self.tree.branch.last_revision())
 
 
+class TestSmartServerBranchRequestGetParent(tests.TestCaseWithMemoryTransport):
+
+    def test_get_parent_none(self):
+        base_branch = self.make_branch('base')
+        request = smart.branch.SmartServerBranchGetParent(self.get_transport())
+        response = request.execute('base')
+        self.assertEquals(
+            SuccessfulSmartServerResponse(('')), response)
+
+    def test_get_parent_something(self):
+        base_branch = self.make_branch('base')
+        base_branch.set_parent(self.get_url('foo'))
+        request = smart.branch.SmartServerBranchGetParent(self.get_transport())
+        response = request.execute('base')
+        self.assertEquals(
+            SuccessfulSmartServerResponse(("../foo")),
+            response)
+
+
 class TestSmartServerBranchRequestGetStackedOnURL(tests.TestCaseWithMemoryTransport):
 
     def test_get_stacked_on_url(self):
@@ -1168,6 +1187,9 @@
             smart.request.request_handlers.get('Branch.get_config_file'),
             smart.branch.SmartServerBranchGetConfigFile)
         self.assertEqual(
+            smart.request.request_handlers.get('Branch.get_parent'),
+            smart.branch.SmartServerBranchGetParent)
+        self.assertEqual(
             smart.request.request_handlers.get('Branch.lock_write'),
             smart.branch.SmartServerBranchRequestLockWrite)
         self.assertEqual(




More information about the bazaar-commits mailing list