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

Patch Queue Manager pqm at pqm.ubuntu.com
Mon Nov 28 05:07:41 UTC 2011


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

------------------------------------------------------------
revno: 6310 [merge]
revision-id: pqm at pqm.ubuntu.com-20111128050740-md31i70uhigil8mq
parent: pqm at pqm.ubuntu.com-20111128035243-w2jbl870d8lq94v1
parent: jelmer at samba.org-20111128033843-e2zulktxzh76t6wa
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2011-11-28 05:07:40 +0000
message:
  (jelmer) Add HPSS call for ``Repository.pack``. (Jelmer Vernooij)
modified:
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/smart/repository.py     repository.py-20061128022038-vr5wy5bubyb8xttk-1
  bzrlib/smart/request.py        request.py-20061108095550-gunadhxmzkdjfeek-1
  bzrlib/tests/blackbox/test_pack.py test_pack.py-20070712120702-0c7585lh56p894mo-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	2011-11-28 03:52:43 +0000
+++ b/bzrlib/remote.py	2011-11-28 05:07:40 +0000
@@ -2133,11 +2133,23 @@
     @needs_write_lock
     def pack(self, hint=None, clean_obsolete_packs=False):
         """Compress the data within the repository.
-
-        This is not currently implemented within the smart server.
         """
-        self._ensure_real()
-        return self._real_repository.pack(hint=hint, clean_obsolete_packs=clean_obsolete_packs)
+        if hint is None:
+            body = ""
+        else:
+            body = "".join([l+"\n" for l in hint])
+        path = self.bzrdir._path_for_remote_call(self._client)
+        try:
+            response, handler = self._call_with_body_bytes_expecting_body(
+                'Repository.pack', (path, self._lock_token,
+                    str(clean_obsolete_packs)), body)
+        except errors.UnknownSmartMethod:
+            self._ensure_real()
+            return self._real_repository.pack(hint=hint,
+                clean_obsolete_packs=clean_obsolete_packs)
+        handler.cancel_read_body()
+        if response != ('ok', ):
+            raise errors.UnexpectedSmartServerResponse(response)
 
     @property
     def revisions(self):

=== modified file 'bzrlib/smart/repository.py'
--- a/bzrlib/smart/repository.py	2011-11-25 18:45:53 +0000
+++ b/bzrlib/smart/repository.py	2011-11-28 03:38:43 +0000
@@ -1073,3 +1073,31 @@
     def do_repository_request(self, repository):
         revids = repository.all_revision_ids()
         return SuccessfulSmartServerResponse(("ok", ), "\n".join(revids))
+
+
+class SmartServerRepositoryPack(SmartServerRepositoryRequest):
+    """Pack a repository.
+
+    New in 2.5.
+    """
+
+    def do_repository_request(self, repository, lock_token, clean_obsolete_packs):
+        self._repository = repository
+        self._lock_token = lock_token
+        if clean_obsolete_packs == 'True':
+            self._clean_obsolete_packs = True
+        else:
+            self._clean_obsolete_packs = False
+        return None
+
+    def do_body(self, body_bytes):
+        if body_bytes == "":
+            hint = None
+        else:
+            hint = body_bytes.splitlines()
+        self._repository.lock_write(token=self._lock_token)
+        try:
+            self._repository.pack(hint, self._clean_obsolete_packs)
+        finally:
+            self._repository.unlock()
+        return SuccessfulSmartServerResponse(("ok", ), )

=== modified file 'bzrlib/smart/request.py'
--- a/bzrlib/smart/request.py	2011-11-25 18:45:53 +0000
+++ b/bzrlib/smart/request.py	2011-11-28 03:38:43 +0000
@@ -676,6 +676,9 @@
     'Repository.get_stream_1.19', 'bzrlib.smart.repository',
     'SmartServerRepositoryGetStream_1_19')
 request_handlers.register_lazy(
+    'Repository.pack', 'bzrlib.smart.repository',
+    'SmartServerRepositoryPack')
+request_handlers.register_lazy(
     'Repository.tarball', 'bzrlib.smart.repository',
     'SmartServerRepositoryTarball')
 request_handlers.register_lazy(

=== modified file 'bzrlib/tests/blackbox/test_pack.py'
--- a/bzrlib/tests/blackbox/test_pack.py	2011-05-13 20:44:45 +0000
+++ b/bzrlib/tests/blackbox/test_pack.py	2011-11-27 23:55:33 +0000
@@ -83,3 +83,22 @@
 
         pack_names = transport.list_dir('repository/obsolete_packs')
         self.assertTrue(len(pack_names) == 0)
+
+
+class TestSmartServerPack(tests.TestCaseWithTransport):
+
+    def test_simple_pack(self):
+        self.setup_smart_server_with_call_log()
+        t = self.make_branch_and_tree('branch')
+        self.build_tree_contents([('branch/foo', 'thecontents')])
+        t.add("foo")
+        t.commit("message")
+        self.reset_smart_call_log()
+        out, err = self.run_bzr(['pack', self.get_url('branch')])
+        # This figure represent the amount of HPSS calls to perform this use
+        # case. It is entirely ok to reduce this number if a test fails due to
+        # rpc_count # 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(6, self.hpss_calls)

=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py	2011-11-28 03:52:43 +0000
+++ b/bzrlib/tests/test_remote.py	2011-11-28 05:07:40 +0000
@@ -4023,3 +4023,34 @@
         branch = self.make_remote_branch(transport, client)
         self.assertRaises(OutOfTea, branch.last_revision_info)
         self.assertFinished(client)
+
+
+class TestRepositoryPack(TestRemoteRepository):
+
+    def test_pack(self):
+        transport_path = 'quack'
+        repo, client = self.setup_fake_client_and_repository(transport_path)
+        client.add_expected_call(
+            'Repository.lock_write', ('quack/', ''),
+            'success', ('ok', 'token'))
+        client.add_expected_call(
+            'Repository.pack', ('quack/', 'token', 'False'),
+            'success', ('ok',), )
+        client.add_expected_call(
+            'Repository.unlock', ('quack/', 'token'),
+            'success', ('ok', ))
+        repo.pack()
+
+    def test_pack_with_hint(self):
+        transport_path = 'quack'
+        repo, client = self.setup_fake_client_and_repository(transport_path)
+        client.add_expected_call(
+            'Repository.lock_write', ('quack/', ''),
+            'success', ('ok', 'token'))
+        client.add_expected_call(
+            'Repository.pack', ('quack/', 'token', 'False'),
+            'success', ('ok',), )
+        client.add_expected_call(
+            'Repository.unlock', ('quack/', 'token', 'False'),
+            'success', ('ok', ))
+        repo.pack(['hinta', 'hintb'])

=== modified file 'bzrlib/tests/test_smart.py'
--- a/bzrlib/tests/test_smart.py	2011-11-25 18:45:53 +0000
+++ b/bzrlib/tests/test_smart.py	2011-11-28 03:38:43 +0000
@@ -2402,6 +2402,8 @@
             smart_repo.SmartServerRepositoryLockWrite)
         self.assertHandlerEqual('Repository.make_working_trees',
             smart_repo.SmartServerRepositoryMakeWorkingTrees)
+        self.assertHandlerEqual('Repository.pack',
+            smart_repo.SmartServerRepositoryPack)
         self.assertHandlerEqual('Repository.tarball',
             smart_repo.SmartServerRepositoryTarball)
         self.assertHandlerEqual('Repository.unlock',
@@ -2465,3 +2467,19 @@
         self.server.run_server_stopped_hooks()
         self.assertEquals(stopped_calls,
             [([self.get_transport().base], 'bzr://example.com:42/')])
+
+
+class TestSmartServerRepositoryPack(tests.TestCaseWithMemoryTransport):
+
+    def test_pack(self):
+        backing = self.get_transport()
+        request = smart_repo.SmartServerRepositoryPack(backing)
+        tree = self.make_branch_and_memory_tree('.')
+        repo_token = tree.branch.repository.lock_write().repository_token
+
+        self.assertIs(None, request.execute('', repo_token, False))
+
+        self.assertEqual(
+            smart_req.SuccessfulSmartServerResponse(('ok', ), ),
+            request.do_body(''))
+

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2011-11-25 18:45:53 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2011-11-28 03:38:43 +0000
@@ -123,6 +123,8 @@
   ``Repository.add_signature_revision_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)




More information about the bazaar-commits mailing list