Rev 6371: (jelmer) Add HPSS call for ``BzrDir.checkout_metadir``. (Jelmer Vernooij) in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Wed Dec 14 20:39:59 UTC 2011


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6371 [merge]
revision-id: pqm at pqm.ubuntu.com-20111214203958-q3d07mehwgt2oeku
parent: pqm at pqm.ubuntu.com-20111214201446-qtonj9txr8bsj5vv
parent: jelmer at samba.org-20111214195716-if8ld0nzu2atxn06
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2011-12-14 20:39:58 +0000
message:
  (jelmer) Add HPSS call for ``BzrDir.checkout_metadir``. (Jelmer Vernooij)
modified:
  bzrlib/controldir.py           controldir.py-20100802102926-hvtvh0uae5epuibp-1
  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/blackbox/test_checkout.py test_checkout.py-20060211231752-a5cde67cf70af854
  bzrlib/tests/per_branch/test_create_checkout.py test_create_checkout-20070322193723-n2wkp1g03r0404di-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/controldir.py'
--- a/bzrlib/controldir.py	2011-12-12 12:09:50 +0000
+++ b/bzrlib/controldir.py	2011-12-14 12:25:34 +0000
@@ -328,7 +328,12 @@
         raise NotImplementedError(self.cloning_metadir)
 
     def checkout_metadir(self):
-        """Produce a metadir suitable for checkouts of this controldir."""
+        """Produce a metadir suitable for checkouts of this controldir.
+
+        :returns: A ControlDirFormat with all component formats
+            either set appropriately or set to None if that component
+            should not be created.
+        """
         return self.cloning_metadir()
 
     def sprout(self, url, revision_id=None, force_new_repo=False,

=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2011-12-11 13:30:10 +0000
+++ b/bzrlib/remote.py	2011-12-14 12:33:04 +0000
@@ -490,6 +490,48 @@
         self._next_open_branch_result = None
         return _mod_bzrdir.BzrDir.break_lock(self)
 
+    def _vfs_checkout_metadir(self):
+        self._ensure_real()
+        return self._real_bzrdir.checkout_metadir()
+
+    def checkout_metadir(self):
+        """Retrieve the controldir format to use for checkouts of this one.
+        """
+        medium = self._client._medium
+        if medium._is_remote_before((2, 5)):
+            return self._vfs_checkout_metadir()
+        path = self._path_for_remote_call(self._client)
+        try:
+            response = self._client.call('BzrDir.checkout_metadir',
+                path)
+        except errors.UnknownSmartMethod:
+            medium._remember_remote_is_before((2, 5))
+            return self._vfs_checkout_metadir()
+        if len(response) != 3:
+            raise errors.UnexpectedSmartServerResponse(response)
+        control_name, repo_name, branch_name = response
+        try:
+            format = controldir.network_format_registry.get(control_name)
+        except KeyError:
+            raise errors.UnknownFormatError(kind='control',
+                format=control_name)
+        if repo_name:
+            try:
+                repo_format = _mod_repository.network_format_registry.get(
+                    repo_name)
+            except KeyError:
+                raise errors.UnknownFormatError(kind='repository',
+                    format=repo_name)
+            format.repository_format = repo_format
+        if branch_name:
+            try:
+                format.set_branch_format(
+                    branch.network_format_registry.get(branch_name))
+            except KeyError:
+                raise errors.UnknownFormatError(kind='branch',
+                    format=branch_name)
+        return format
+
     def _vfs_cloning_metadir(self, require_stacking=False):
         self._ensure_real()
         return self._real_bzrdir.cloning_metadir(
@@ -3179,17 +3221,6 @@
                 self.bzrdir, self._client)
         return self._control_files
 
-    def _get_checkout_format(self, lightweight=False):
-        self._ensure_real()
-        if lightweight:
-            format = RemoteBzrDirFormat()
-            self.bzrdir._format._supply_sub_formats_to(format)
-            format.workingtree_format = self._real_branch._get_checkout_format(
-                lightweight=lightweight).workingtree_format
-            return format
-        else:
-            return self._real_branch._get_checkout_format(lightweight=False)
-
     def get_physical_lock_status(self):
         """See Branch.get_physical_lock_status()."""
         try:

=== modified file 'bzrlib/smart/bzrdir.py'
--- a/bzrlib/smart/bzrdir.py	2011-11-21 14:44:03 +0000
+++ b/bzrlib/smart/bzrdir.py	2011-12-14 19:57:16 +0000
@@ -208,6 +208,41 @@
             branch_name))
 
 
+class SmartServerBzrDirRequestCheckoutMetaDir(SmartServerRequestBzrDir):
+    """Get the format to use for checkouts.
+
+    New in 2.5.
+
+    :return: on success, a 3-tuple of network names for (control,
+        repository, branch) directories, where '' signifies "not present".
+        If this BzrDir contains a branch reference then this will fail with
+        BranchReference; clients should resolve branch references before
+        calling this RPC (they should not try to create a checkout of a
+        checkout).
+    """
+
+    def do_bzrdir_request(self):
+        try:
+            branch_ref = self._bzrdir.get_branch_reference()
+        except errors.NotBranchError:
+            branch_ref = None
+        if branch_ref is not None:
+            # The server shouldn't try to resolve references, and it quite
+            # possibly can't reach them anyway.  The client needs to resolve
+            # the branch reference to determine the cloning_metadir.
+            return FailedSmartServerResponse(('BranchReference',))
+        control_format = self._bzrdir.checkout_metadir()
+        control_name = control_format.network_name()
+        if not control_format.fixed_components:
+            branch_name = control_format.get_branch_format().network_name()
+            repo_name = control_format.repository_format.network_name()
+        else:
+            branch_name = ''
+            repo_name = ''
+        return SuccessfulSmartServerResponse(
+            (control_name, repo_name, branch_name))
+
+
 class SmartServerRequestCreateBranch(SmartServerRequestBzrDir):
 
     def do(self, path, network_name):

=== modified file 'bzrlib/smart/request.py'
--- a/bzrlib/smart/request.py	2011-12-09 21:41:38 +0000
+++ b/bzrlib/smart/request.py	2011-12-14 12:20:36 +0000
@@ -583,6 +583,9 @@
     'Branch.revision_id_to_revno', 'bzrlib.smart.branch',
     'SmartServerBranchRequestRevisionIdToRevno', info='read')
 request_handlers.register_lazy(
+    'BzrDir.checkout_metadir', 'bzrlib.smart.bzrdir',
+    'SmartServerBzrDirRequestCheckoutMetaDir', info='read')
+request_handlers.register_lazy(
     'BzrDir.cloning_metadir', 'bzrlib.smart.bzrdir',
     'SmartServerBzrDirRequestCloningMetaDir', info='read')
 request_handlers.register_lazy(

=== modified file 'bzrlib/tests/blackbox/test_checkout.py'
--- a/bzrlib/tests/blackbox/test_checkout.py	2011-12-14 12:15:44 +0000
+++ b/bzrlib/tests/blackbox/test_checkout.py	2011-12-14 18:17:43 +0000
@@ -186,9 +186,8 @@
         # being too low. If rpc_count increases, more network roundtrips have
         # become necessary for this use case. Please do not adjust this number
         # upwards without agreement from bzr's network support maintainers.
-        self.assertLength(17, self.hpss_calls)
-        self.expectFailure("checkouts require VFS access",
-            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
+        self.assertLength(10, self.hpss_calls)
+        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
     def test_lightweight_checkout(self):
         self.setup_smart_server_with_call_log()
@@ -203,9 +202,9 @@
         # being too low. If rpc_count increases, more network roundtrips have
         # become necessary for this use case. Please do not adjust this number
         # upwards without agreement from bzr's network support maintainers.
-        if len(self.hpss_calls) < 34 or len(self.hpss_calls) > 48:
+        if len(self.hpss_calls) < 28 or len(self.hpss_calls) > 40:
             self.fail(
-                "Incorrect length: wanted between 34 and 48, got %d for %r" % (
+                "Incorrect length: wanted between 28 and 40, got %d for %r" % (
                     len(self.hpss_calls), self.hpss_calls))
         self.expectFailure("lightweight checkouts require VFS calls",
             self.assertThat, self.hpss_calls, ContainsNoVfsCalls)

=== modified file 'bzrlib/tests/per_branch/test_create_checkout.py'
--- a/bzrlib/tests/per_branch/test_create_checkout.py	2011-09-09 12:20:33 +0000
+++ b/bzrlib/tests/per_branch/test_create_checkout.py	2011-12-14 19:57:16 +0000
@@ -28,8 +28,8 @@
         # All branches can define the format they want checkouts made in.
         # This checks it is honoured.
         expected_format = a_branch._get_checkout_format(lightweight=True)
-        self.assertEqual(expected_format.get_branch_format().__class__,
-                         tree.branch._format.__class__)
+        self.assertEqual(expected_format.get_branch_format().network_name(),
+                         tree.branch._format.network_name())
 
     def test_checkout_format_heavyweight(self):
         """Make sure the new heavy checkout uses the desired branch format."""
@@ -38,8 +38,8 @@
         # All branches can define the format they want checkouts made in.
         # This checks it is honoured.
         expected_format = a_branch._get_checkout_format(lightweight=False)
-        self.assertEqual(expected_format.get_branch_format().__class__,
-                         tree.branch._format.__class__)
+        self.assertEqual(expected_format.get_branch_format().network_name(),
+                         tree.branch._format.network_name())
 
     def test_create_revision_checkout(self):
         """Test that we can create a checkout from an earlier revision."""

=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py	2011-12-11 13:30:10 +0000
+++ b/bzrlib/tests/test_remote.py	2011-12-14 12:20:36 +0000
@@ -503,6 +503,43 @@
         self.assertRaises(errors.UnknownFormatError, a_bzrdir.cloning_metadir)
 
 
+class TestBzrDirCheckoutMetaDir(TestRemote):
+
+    def test__get_checkout_format(self):
+        transport = MemoryTransport()
+        client = FakeClient(transport.base)
+        reference_bzrdir_format = bzrdir.format_registry.get('default')()
+        control_name = reference_bzrdir_format.network_name()
+        client.add_expected_call(
+            'BzrDir.checkout_metadir', ('quack/', ),
+            'success', (control_name, '', ''))
+        transport.mkdir('quack')
+        transport = transport.clone('quack')
+        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
+            _client=client)
+        result = a_bzrdir.checkout_metadir()
+        # We should have got a reference control dir with default branch and
+        # repository formats.
+        self.assertEqual(bzrdir.BzrDirMetaFormat1, type(result))
+        self.assertEqual(None, result._repository_format)
+        self.assertEqual(None, result._branch_format)
+        self.assertFinished(client)
+
+    def test_unknown_format(self):
+        transport = MemoryTransport()
+        client = FakeClient(transport.base)
+        client.add_expected_call(
+            'BzrDir.checkout_metadir', ('quack/',),
+            'success', ('dontknow', '', ''))
+        transport.mkdir('quack')
+        transport = transport.clone('quack')
+        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
+            _client=client)
+        self.assertRaises(errors.UnknownFormatError,
+            a_bzrdir.checkout_metadir)
+        self.assertFinished(client)
+
+
 class TestBzrDirDestroyBranch(TestRemote):
 
     def test_destroy_default(self):

=== modified file 'bzrlib/tests/test_smart.py'
--- a/bzrlib/tests/test_smart.py	2011-12-11 13:30:10 +0000
+++ b/bzrlib/tests/test_smart.py	2011-12-14 12:20:36 +0000
@@ -224,6 +224,24 @@
         self.assertEqual(expected, request.execute('', 'False'))
 
 
+class TestSmartServerBzrDirRequestCloningMetaDir(
+    tests.TestCaseWithMemoryTransport):
+    """Tests for BzrDir.checkout_metadir."""
+
+    def test_checkout_metadir(self):
+        backing = self.get_transport()
+        request = smart_dir.SmartServerBzrDirRequestCheckoutMetaDir(
+            backing)
+        branch = self.make_branch('.', format='2a')
+        response = request.execute('')
+        self.assertEqual(
+            smart_req.SmartServerResponse(
+                ('Bazaar-NG meta directory, format 1\n',
+                 'Bazaar repository format 2a (needs bzr 1.16 or later)\n',
+                 'Bazaar Branch Format 7 (needs bzr 1.6)\n')),
+            response)
+
+
 class TestSmartServerBzrDirRequestDestroyBranch(
     tests.TestCaseWithMemoryTransport):
     """Tests for BzrDir.destroy_branch."""
@@ -2477,6 +2495,8 @@
             smart_dir.SmartServerRequestInitializeBzrDir)
         self.assertHandlerEqual('BzrDirFormat.initialize_ex_1.16',
             smart_dir.SmartServerRequestBzrDirInitializeEx)
+        self.assertHandlerEqual('BzrDir.checkout_metadir',
+            smart_dir.SmartServerBzrDirRequestCheckoutMetaDir)
         self.assertHandlerEqual('BzrDir.cloning_metadir',
             smart_dir.SmartServerBzrDirRequestCloningMetaDir)
         self.assertHandlerEqual('BzrDir.get_config_file',

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2011-12-14 19:49:36 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2011-12-14 20:39:58 +0000
@@ -93,6 +93,8 @@
   branches themselves. The active branch uses the key None.
   (Neil Martinsen-Burrell)
 
+* New HPSS call ``BzrDir.checkout_metadir``. (Jelmer Vernooij, #894459)
+
 Testing
 *******
 
@@ -279,6 +281,12 @@
   ``Repository.get_revision_signature_text``.
   (Jelmer Vernooij)
 
+* Add HPSS call for ``Repository.pack``. (Jelmer Vernooij, #894461)
+
+* Custom HPSS error handlers can now be installed in the smart server client
+  using the ``error_translators`` and ``no_context_error_translators``
+  registries. (Jelmer Vernooij)
+
 * ``RemoteBranch.get_config_stack`` and ``RemoteBzrDir.get_config_stack``
   will now use HPSS calls where possible. (Jelmer Vernooij)
 




More information about the bazaar-commits mailing list