Rev 3224: * Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so in http://people.ubuntu.com/~robertc/baz2.0/shallow-branch

Robert Collins robertc at robertcollins.net
Tue Feb 12 05:18:15 GMT 2008


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

------------------------------------------------------------
revno: 3224
revision-id:robertc at robertcollins.net-20080212051725-m8fjb5ouzl1pkso0
parent: robertc at robertcollins.net-20080212045218-2yo8xf84u7458320
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository-stackable-flag
timestamp: Tue 2008-02-12 16:17:25 +1100
message:
   * Hook up the new remote method ``RemoteBzrDir.find_repositoryV2`` so
     that it is now attempted first when lookup up repositories, leading to
     an extra round trip on older bzr smart servers but supporting the
     feature on newer servers. (Robert Collins)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/smart/bzrdir.py         bzrdir.py-20061122024551-ol0l0o0oofsu9b3t-1
  bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
=== modified file 'NEWS'
--- a/NEWS	2008-02-12 04:52:18 +0000
+++ b/NEWS	2008-02-12 05:17:25 +0000
@@ -172,8 +172,9 @@
       cares about ghosts during revision selection). (Robert Collins)
 
     * New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
-      detecting external lookup support on remote repositories.
-      (Robert Collins)
+      detecting external lookup support on remote repositories. This method is
+      now attempted first when lookup up repositories, leading to an extra 
+      round trip on older bzr smart servers. (Robert Collins)
  
     * Record a timestamp against each mutter to the trace file, relative to the
       first import of bzrlib.  (Andrew Bennetts)

=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2008-02-12 02:38:27 +0000
+++ b/bzrlib/remote.py	2008-02-12 05:17:25 +0000
@@ -148,18 +148,29 @@
                 
     def open_repository(self):
         path = self._path_for_remote_call(self._client)
-        response = self._client.call('BzrDir.find_repository', path)
+        verb = 'BzrDir.find_repositoryV2'
+        response = self._client.call(verb, path)
+        if (response == ('error', "Generic bzr smart protocol error: "
+                "bad request '%s'" % verb) or
+              response == ('error', "Generic bzr smart protocol error: "
+                "bad request u'%s'" % verb)):
+            verb = 'BzrDir.find_repository'
+            response = self._client.call(verb, path)
         assert response[0] in ('ok', 'norepository'), \
             'unexpected response code %s' % (response,)
         if response[0] == 'norepository':
             raise errors.NoRepositoryPresent(self)
-        assert len(response) == 4, 'incorrect response length %s' % (response,)
+        if verb == 'BzrDir.find_repository':
+            # servers that don't support the V2 method don't support external
+            # references either.
+            response = response + ('no', )
+        assert len(response) == 5, 'incorrect response length %s' % (response,)
         if response[1] == '':
             format = RemoteRepositoryFormat()
             format.rich_root_data = (response[2] == 'yes')
             format.supports_tree_reference = (response[3] == 'yes')
             # No wire format to check this yet.
-            format.supports_external_lookups = False
+            format.supports_external_lookups = (response[4] == 'yes')
             return RemoteRepository(self, format)
         else:
             raise errors.NoRepositoryPresent(self)

=== modified file 'bzrlib/smart/bzrdir.py'
--- a/bzrlib/smart/bzrdir.py	2008-02-12 04:52:18 +0000
+++ b/bzrlib/smart/bzrdir.py	2008-02-12 05:17:25 +0000
@@ -111,7 +111,7 @@
         If a bzrdir is not present, an exception is propogated
         rather than 'no branch' because these are different conditions.
 
-        This is the second edition of this method introduced in bzr 1.2, which
+        This is the second edition of this method introduced in bzr 1.3, which
         returns information about the supports_external_lookups format
         attribute too.
 

=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py	2008-02-07 03:47:24 +0000
+++ b/bzrlib/tests/test_remote.py	2008-02-12 05:17:25 +0000
@@ -197,13 +197,13 @@
         transport = MemoryTransport()
         transport.mkdir('quack')
         transport = transport.clone('quack')
-        client = FakeClient([(('ok', ''), ), (('ok', '', 'no', 'no'), )],
+        client = FakeClient([(('ok', ''), ), (('ok', '', 'no', 'no', 'no'), )],
                             transport.base)
         bzrdir = RemoteBzrDir(transport, _client=client)
         result = bzrdir.open_branch()
         self.assertEqual(
             [('call', 'BzrDir.open_branch', ('quack/',)),
-             ('call', 'BzrDir.find_repository', ('quack/',))],
+             ('call', 'BzrDir.find_repositoryV2', ('quack/',))],
             client._calls)
         self.assertIsInstance(result, RemoteBranch)
         self.assertEqual(bzrdir, result.bzrdir)
@@ -240,16 +240,16 @@
         # Relpaths on the wire should not be URL-escaped.  So "~" should be
         # transmitted as "~", not "%7E".
         transport = RemoteTransport('bzr://localhost/~hello/')
-        client = FakeClient([(('ok', ''), ), (('ok', '', 'no', 'no'), )],
+        client = FakeClient([(('ok', ''), ), (('ok', '', 'no', 'no', 'no'), )],
                             transport.base)
         bzrdir = RemoteBzrDir(transport, _client=client)
         result = bzrdir.open_branch()
         self.assertEqual(
             [('call', 'BzrDir.open_branch', ('~hello/',)),
-             ('call', 'BzrDir.find_repository', ('~hello/',))],
+             ('call', 'BzrDir.find_repositoryV2', ('~hello/',))],
             client._calls)
 
-    def check_open_repository(self, rich_root, subtrees):
+    def check_open_repository(self, rich_root, subtrees, external_lookup='no'):
         transport = MemoryTransport()
         transport.mkdir('quack')
         transport = transport.clone('quack')
@@ -261,12 +261,13 @@
             subtree_response = 'yes'
         else:
             subtree_response = 'no'
-        client = FakeClient([(('ok', '', rich_response, subtree_response), ),],
-                            transport.base)
+        client = FakeClient(
+            [(('ok', '', rich_response, subtree_response, external_lookup), ),],
+            transport.base)
         bzrdir = RemoteBzrDir(transport, _client=client)
         result = bzrdir.open_repository()
         self.assertEqual(
-            [('call', 'BzrDir.find_repository', ('quack/',))],
+            [('call', 'BzrDir.find_repositoryV2', ('quack/',))],
             client._calls)
         self.assertIsInstance(result, RemoteRepository)
         self.assertEqual(bzrdir, result.bzrdir)
@@ -278,6 +279,7 @@
         self.check_open_repository(False, True)
         self.check_open_repository(True, False)
         self.check_open_repository(False, False)
+        self.check_open_repository(False, False, 'yes')
 
     def test_old_server(self):
         """RemoteBzrDirFormat should fail to probe if the server version is too



More information about the bazaar-commits mailing list