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

Patch Queue Manager pqm at pqm.ubuntu.com
Thu Nov 17 13:32:39 UTC 2011


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

------------------------------------------------------------
revno: 6270 [merge]
revision-id: pqm at pqm.ubuntu.com-20111117133239-0yk0ttnj6jto3a04
parent: pqm at pqm.ubuntu.com-20111117125955-yjbz106l8gkzslos
parent: jelmer at samba.org-20111117130658-qinqsrf373zh5kkj
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2011-11-17 13:32:39 +0000
message:
  (jelmer) Add HPSS call ``Repository.has_signature_for_revision_id``. (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/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-16 13:33:11 +0000
+++ b/bzrlib/remote.py	2011-11-17 11:22:28 +0000
@@ -2011,8 +2011,17 @@
         return self._real_repository.add_signature_text(revision_id, signature)
 
     def has_signature_for_revision_id(self, revision_id):
-        self._ensure_real()
-        return self._real_repository.has_signature_for_revision_id(revision_id)
+        path = self.bzrdir._path_for_remote_call(self._client)
+        try:
+            response = self._call('Repository.has_signature_for_revision_id',
+                path, revision_id)
+        except errors.UnknownSmartMethod:
+            self._ensure_real()
+            return self._real_repository.has_signature_for_revision_id(
+                revision_id)
+        if response[0] not in ('yes', 'no'):
+            raise SmartProtocolError('unexpected response code %s' % (response,))
+        return (response[0] == 'yes')
 
     def verify_revision_signature(self, revision_id, gpg_strategy):
         self._ensure_real()

=== modified file 'bzrlib/smart/repository.py'
--- a/bzrlib/smart/repository.py	2011-11-17 09:51:07 +0000
+++ b/bzrlib/smart/repository.py	2011-11-17 12:49:07 +0000
@@ -25,7 +25,6 @@
 
 from bzrlib import (
     bencode,
-    commands,
     errors,
     estimate_compressed_size,
     graph,
@@ -334,8 +333,8 @@
 
         :param repository: The repository to query in.
         :param revision_id: The utf8 encoded revision_id to lookup.
-        :return: A smart server response of ('ok', ) if the revision is
-            present.
+        :return: A smart server response of ('yes', ) if the revision is
+            present. ('no', ) if it is missing.
         """
         if repository.has_revision(revision_id):
             return SuccessfulSmartServerResponse(('yes', ))
@@ -343,6 +342,30 @@
             return SuccessfulSmartServerResponse(('no', ))
 
 
+class SmartServerRequestHasSignatureForRevisionId(
+        SmartServerRepositoryRequest):
+
+    def do_repository_request(self, repository, revision_id):
+        """Return ok if a signature is present for a revision.
+
+        Introduced in bzr 2.5.0.
+
+        :param repository: The repository to query in.
+        :param revision_id: The utf8 encoded revision_id to lookup.
+        :return: A smart server response of ('yes', ) if a
+            signature for the revision is present,
+            ('no', ) if it is missing.
+        """
+        try:
+            if repository.has_signature_for_revision_id(revision_id):
+                return SuccessfulSmartServerResponse(('yes', ))
+            else:
+                return SuccessfulSmartServerResponse(('no', ))
+        except errors.NoSuchRevision:
+            return FailedSmartServerResponse(
+                ('nosuchrevision', revision_id))
+
+
 class SmartServerRepositoryGatherStats(SmartServerRepositoryRequest):
 
     def do_repository_request(self, repository, revid, committers):

=== modified file 'bzrlib/smart/request.py'
--- a/bzrlib/smart/request.py	2011-11-16 13:33:11 +0000
+++ b/bzrlib/smart/request.py	2011-11-17 11:22:28 +0000
@@ -613,6 +613,9 @@
 request_handlers.register_lazy(
     'Repository.has_revision', 'bzrlib.smart.repository', 'SmartServerRequestHasRevision')
 request_handlers.register_lazy(
+    'Repository.has_signature_for_revision_id', 'bzrlib.smart.repository',
+    'SmartServerRequestHasSignatureForRevisionId')
+request_handlers.register_lazy(
     'Repository.insert_stream', 'bzrlib.smart.repository', 'SmartServerRepositoryInsertStream')
 request_handlers.register_lazy(
     'Repository.insert_stream_1.19', 'bzrlib.smart.repository', 'SmartServerRepositoryInsertStream_1_19')

=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py	2011-11-16 13:33:11 +0000
+++ b/bzrlib/tests/test_remote.py	2011-11-17 11:22:28 +0000
@@ -2479,6 +2479,33 @@
                               call.call.method == verb])
 
 
+class TestRepositoryHasSignatureForRevisionId(TestRemoteRepository):
+
+    def test_has_signature_for_revision_id(self):
+        # ('yes', ) for Repository.has_signature_for_revision_id -> 'True'.
+        transport_path = 'quack'
+        repo, client = self.setup_fake_client_and_repository(transport_path)
+        client.add_success_response('yes')
+        result = repo.has_signature_for_revision_id('A')
+        self.assertEqual(
+            [('call', 'Repository.has_signature_for_revision_id',
+              ('quack/', 'A'))],
+            client._calls)
+        self.assertEqual(True, result)
+
+    def test_is_not_shared(self):
+        # ('no', ) for Repository.has_signature_for_revision_id -> 'False'.
+        transport_path = 'qwack'
+        repo, client = self.setup_fake_client_and_repository(transport_path)
+        client.add_success_response('no')
+        result = repo.has_signature_for_revision_id('A')
+        self.assertEqual(
+            [('call', 'Repository.has_signature_for_revision_id',
+              ('qwack/', 'A'))],
+            client._calls)
+        self.assertEqual(False, result)
+
+
 class TestRepositoryIsShared(TestRemoteRepository):
 
     def test_is_shared(self):

=== modified file 'bzrlib/tests/test_smart.py'
--- a/bzrlib/tests/test_smart.py	2011-11-16 13:33:11 +0000
+++ b/bzrlib/tests/test_smart.py	2011-11-17 12:49:07 +0000
@@ -30,6 +30,7 @@
     branch as _mod_branch,
     bzrdir,
     errors,
+    gpg,
     tests,
     transport,
     urlutils,
@@ -1549,6 +1550,53 @@
             request.execute('', rev_id_utf8))
 
 
+class TestSmartServerRequestHasSignatureForRevisionId(
+        tests.TestCaseWithMemoryTransport):
+
+    def test_missing_revision(self):
+        """For a missing revision, NoSuchRevision is returned."""
+        backing = self.get_transport()
+        request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
+            backing)
+        self.make_repository('.')
+        self.assertEqual(
+            smart_req.FailedSmartServerResponse(
+                ('nosuchrevision', 'revid'), None),
+            request.execute('', 'revid'))
+
+    def test_missing_signature(self):
+        """For a missing signature, ('no', ) is returned."""
+        backing = self.get_transport()
+        request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
+            backing)
+        tree = self.make_branch_and_memory_tree('.')
+        tree.lock_write()
+        tree.add('')
+        r1 = tree.commit('a commit', rev_id='A')
+        tree.unlock()
+        self.assertTrue(tree.branch.repository.has_revision('A'))
+        self.assertEqual(smart_req.SmartServerResponse(('no', )),
+            request.execute('', 'A'))
+
+    def test_present_signature(self):
+        """For a present signature, ('yes', ) is returned."""
+        backing = self.get_transport()
+        request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
+            backing)
+        strategy = gpg.LoopbackGPGStrategy(None)
+        tree = self.make_branch_and_memory_tree('.')
+        tree.lock_write()
+        tree.add('')
+        r1 = tree.commit('a commit', rev_id='A')
+        tree.branch.repository.start_write_group()
+        tree.branch.repository.sign_revision('A', strategy)
+        tree.branch.repository.commit_write_group()
+        tree.unlock()
+        self.assertTrue(tree.branch.repository.has_revision('A'))
+        self.assertEqual(smart_req.SmartServerResponse(('yes', )),
+            request.execute('', 'A'))
+
+
 class TestSmartServerRepositoryGatherStats(tests.TestCaseWithMemoryTransport):
 
     def test_empty_revid(self):

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2011-11-17 12:59:55 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2011-11-17 13:06:58 +0000
@@ -64,8 +64,8 @@
 .. Major internal changes, unlikely to be visible to users or plugin 
    developers, but interesting for bzr developers.
 
-* Add hpss call ``Repository.make_working_trees``.
-  (Jelmer Vernooij)
+* New HPSS calls ``Repository.has_signature_for_revision_id`` and
+  ``Repository.make_working_trees``.  (Jelmer Vernooij)
 
 Testing
 *******




More information about the bazaar-commits mailing list