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

Patch Queue Manager pqm at pqm.ubuntu.com
Sun Dec 11 16:36:59 UTC 2011


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

------------------------------------------------------------
revno: 6354 [merge]
revision-id: pqm at pqm.ubuntu.com-20111211163659-9iey381vjoj039ia
parent: pqm at pqm.ubuntu.com-20111211041104-34xrpeot82gw17ut
parent: jelmer at samba.org-20111211160342-wjw9hsllut605sks
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sun 2011-12-11 16:36:59 +0000
message:
  (jelmer) Add HPSS call for ``Repository.reconcile``. (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_reconcile.py test_fix.py-20060223013051-9a188e15a5ee9451
  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-12-05 14:12:23 +0000
+++ b/bzrlib/remote.py	2011-12-11 13:30:10 +0000
@@ -2152,9 +2152,31 @@
         self._ensure_real()
         return self._real_repository._get_inventory_xml(revision_id)
 
+    @needs_write_lock
     def reconcile(self, other=None, thorough=False):
-        self._ensure_real()
-        return self._real_repository.reconcile(other=other, thorough=thorough)
+        from bzrlib.reconcile import RepoReconciler
+        path = self.bzrdir._path_for_remote_call(self._client)
+        try:
+            response, handler = self._call_expecting_body(
+                'Repository.reconcile', path, self._lock_token)
+        except (errors.UnknownSmartMethod, errors.TokenLockingNotSupported):
+            self._ensure_real()
+            return self._real_repository.reconcile(other=other, thorough=thorough)
+        if response != ('ok', ):
+            raise errors.UnexpectedSmartServerResponse(response)
+        body = handler.read_body_bytes()
+        result = RepoReconciler(self)
+        for line in body.split('\n'):
+            if not line:
+                continue
+            key, val_text = line.split(':')
+            if key == "garbage_inventories":
+                result.garbage_inventories = int(val_text)
+            elif key == "inconsistent_parents":
+                result.inconsistent_parents = int(val_text)
+            else:
+                mutter("unknown reconcile key %r" % key)
+        return result
 
     def all_revision_ids(self):
         path = self.bzrdir._path_for_remote_call(self._client)
@@ -3928,6 +3950,9 @@
     lambda err, find, get_path: errors.ReadError(get_path()))
 error_translators.register('NoSuchFile',
     lambda err, find, get_path: errors.NoSuchFile(get_path()))
+error_translators.register('TokenLockingNotSupported',
+    lambda err, find, get_path: errors.TokenLockingNotSupported(
+        find('repository')))
 error_translators.register('UnsuspendableWriteGroup',
     lambda err, find, get_path: errors.UnsuspendableWriteGroup(
         repository=find('repository')))

=== modified file 'bzrlib/smart/repository.py'
--- a/bzrlib/smart/repository.py	2011-12-05 15:16:52 +0000
+++ b/bzrlib/smart/repository.py	2011-12-11 13:30:10 +0000
@@ -1101,6 +1101,29 @@
         return SuccessfulSmartServerResponse(("ok", ), "\n".join(revids))
 
 
+class SmartServerRepositoryReconcile(SmartServerRepositoryRequest):
+    """Reconcile a repository.
+
+    New in 2.5.
+    """
+
+    def do_repository_request(self, repository, lock_token):
+        try:
+            repository.lock_write(token=lock_token)
+        except errors.TokenLockingNotSupported, e:
+            return FailedSmartServerResponse(
+                ('TokenLockingNotSupported', ))
+        try:
+            reconciler = repository.reconcile()
+        finally:
+            repository.unlock()
+        body = [
+            "garbage_inventories: %d\n" % reconciler.garbage_inventories,
+            "inconsistent_parents: %d\n" % reconciler.inconsistent_parents,
+            ]
+        return SuccessfulSmartServerResponse(('ok', ), "".join(body))
+
+
 class SmartServerRepositoryPack(SmartServerRepositoryRequest):
     """Pack a repository.
 

=== modified file 'bzrlib/smart/request.py'
--- a/bzrlib/smart/request.py	2011-11-29 06:22:10 +0000
+++ b/bzrlib/smart/request.py	2011-12-09 21:41:38 +0000
@@ -751,6 +751,9 @@
     'VersionedFileRepository.get_serializer_format', 'bzrlib.smart.repository',
     'SmartServerRepositoryGetSerializerFormat', info='read')
 request_handlers.register_lazy(
+    'Repository.reconcile', 'bzrlib.smart.repository',
+    'SmartServerRepositoryReconcile', info='idem')
+request_handlers.register_lazy(
     'Repository.tarball', 'bzrlib.smart.repository',
     'SmartServerRepositoryTarball', info='read')
 request_handlers.register_lazy(

=== modified file 'bzrlib/tests/blackbox/test_reconcile.py'
--- a/bzrlib/tests/blackbox/test_reconcile.py	2010-01-25 17:48:22 +0000
+++ b/bzrlib/tests/blackbox/test_reconcile.py	2011-12-11 16:03:42 +0000
@@ -20,7 +20,6 @@
 from bzrlib import (
     bzrdir,
     inventory,
-    repository,
     tests,
     )
 
@@ -72,3 +71,18 @@
                      does_backup_text))
         self.assertEqualDiff(expected, out)
         self.assertEqualDiff(err, "")
+
+
+class TestSmartServerReconcile(tests.TestCaseWithTransport):
+
+    def test_simple_reconcile(self):
+        self.setup_smart_server_with_call_log()
+        self.make_branch('branch')
+        self.reset_smart_call_log()
+        out, err = self.run_bzr(['reconcile', self.get_url('branch')])
+        # This figure represent the amount of work 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(10, self.hpss_calls)

=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py	2011-12-05 14:12:23 +0000
+++ b/bzrlib/tests/test_remote.py	2011-12-11 13:30:10 +0000
@@ -2373,6 +2373,27 @@
             client._calls)
 
 
+class TestRepositoryReconcile(TestRemoteRepository):
+
+    def test_reconcile(self):
+        transport_path = 'hill'
+        repo, client = self.setup_fake_client_and_repository(transport_path)
+        body = ("garbage_inventories: 2\n"
+                "inconsistent_parents: 3\n")
+        client.add_expected_call(
+            'Repository.lock_write', ('hill/', ''),
+            'success', ('ok', 'a token'))
+        client.add_success_response_with_body(body, 'ok')
+        reconciler = repo.reconcile()
+        self.assertEqual(
+            [('call', 'Repository.lock_write', ('hill/', '')),
+             ('call_expecting_body', 'Repository.reconcile',
+                ('hill/', 'a token'))],
+            client._calls)
+        self.assertEquals(2, reconciler.garbage_inventories)
+        self.assertEquals(3, reconciler.inconsistent_parents)
+
+
 class TestRepositoryGetRevisionSignatureText(TestRemoteRepository):
 
     def test_text(self):

=== modified file 'bzrlib/tests/test_smart.py'
--- a/bzrlib/tests/test_smart.py	2011-11-28 17:30:38 +0000
+++ b/bzrlib/tests/test_smart.py	2011-12-11 13:30:10 +0000
@@ -2208,6 +2208,22 @@
             request.execute('', ))
 
 
+class TestSmartServerRepositoryReconcile(tests.TestCaseWithTransport):
+
+    def test_reconcile(self):
+        backing = self.get_transport()
+        repo = self.make_repository('.')
+        token = repo.lock_write().repository_token
+        self.addCleanup(repo.unlock)
+        request_class = smart_repo.SmartServerRepositoryReconcile
+        request = request_class(backing)
+        self.assertEqual(smart_req.SuccessfulSmartServerResponse(
+            ('ok', ),
+             'garbage_inventories: 0\n'
+             'inconsistent_parents: 0\n'),
+            request.execute('', token))
+
+
 class TestSmartServerIsReadonly(tests.TestCaseWithMemoryTransport):
 
     def test_is_readonly_no(self):
@@ -2513,6 +2529,8 @@
             smart_repo.SmartServerRepositoryMakeWorkingTrees)
         self.assertHandlerEqual('Repository.pack',
             smart_repo.SmartServerRepositoryPack)
+        self.assertHandlerEqual('Repository.reconcile',
+            smart_repo.SmartServerRepositoryReconcile)
         self.assertHandlerEqual('Repository.tarball',
             smart_repo.SmartServerRepositoryTarball)
         self.assertHandlerEqual('Repository.unlock',

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2011-12-09 12:04:25 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2011-12-09 21:11:41 +0000
@@ -26,6 +26,8 @@
 .. Improvements to existing commands, especially improved performance 
    or memory usage, or better results.
 
+* New HPSS call for ``Repository.reconcile``. (Jelmer Vernooij, #894455)
+
 Bug Fixes
 *********
 
@@ -237,6 +239,10 @@
 * ``RemoteBranch.get_config_stack`` and ``RemoteBzrDir.get_config_stack``
   will now use HPSS calls where possible. (Jelmer Vernooij)
 
+* 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)
+
 * The registry of merge types has been moved to ``merge`` from ``option`` but
   ``merge.get_merge_type_registry`` remains as an accessor. (Martin Packman)
 




More information about the bazaar-commits mailing list