Rev 2124: Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil). in file:///home/robertc/source/baz/hpss/
Robert Collins
robertc at robertcollins.net
Fri Feb 2 17:34:17 GMT 2007
------------------------------------------------------------
revno: 2124
revision-id: robertc at robertcollins.net-20070202173408-pt1fl00icfekufxi
parent: robertc at robertcollins.net-20070202170549-ykriy5021olx98eu
committer: Robert Collins <robertc at robertcollins.net>
branch nick: hpss
timestamp: Sat 2007-02-03 04:34:08 +1100
message:
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
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
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2007-02-02 06:15:27 +0000
+++ b/bzrlib/remote.py 2007-02-02 17:34:08 +0000
@@ -175,18 +175,23 @@
the transport.
"""
- def __init__(self, remote_bzrdir, real_repository=None):
+ def __init__(self, remote_bzrdir, real_repository=None, _client=None):
"""Create a RemoteRepository instance.
:param remote_bzrdir: The bzrdir hosting this repository.
:param real_repository: If not None, a local implementation of the
repository logic for the repository, usually accessing the data
via the VFS.
+ :param _client: Private testing parameter - override the smart client
+ to be used by the repository.
"""
if real_repository:
self._real_repository = real_repository
self.bzrdir = remote_bzrdir
- self._client = client.SmartClient(self.bzrdir.client)
+ if _client is None:
+ self._client = client.SmartClient(self.bzrdir.client)
+ else:
+ self._client = _client
self._format = RemoteRepositoryFormat()
def has_revision(self, revision_id):
@@ -196,6 +201,13 @@
assert response[0] in ('ok', 'no'), 'unexpected response code %s' % (response,)
return response[0] == 'ok'
+ def is_shared(self):
+ """See Repository.is_shared()."""
+ path = self.bzrdir._path_for_remote_call(self._client)
+ response = self._client.call('Repository.is_shared', path)
+ assert response[0] in ('yes', 'no'), 'unexpected response code %s' % (response,)
+ return response[0] == 'yes'
+
class RemoteBranchFormat(branch.BranchFormat):
=== modified file 'bzrlib/smart/repository.py'
--- a/bzrlib/smart/repository.py 2007-02-02 17:05:49 +0000
+++ b/bzrlib/smart/repository.py 2007-02-02 17:34:08 +0000
@@ -56,3 +56,18 @@
return SmartServerResponse(('ok', ))
else:
return SmartServerResponse(('no', ))
+
+
+class SmartServerRepositoryIsShared(SmartServerRepositoryRequest):
+
+ def do_repository_request(self, repository):
+ """Return the result of repository.is_shared().
+
+ :param repository: The repository to query in.
+ :return: A smart server response of ('yes', ) if the repository is
+ shared, and ('no', ) if it is not.
+ """
+ if repository.is_shared():
+ return SmartServerResponse(('yes', ))
+ else:
+ return SmartServerResponse(('no', ))
=== modified file 'bzrlib/smart/request.py'
--- a/bzrlib/smart/request.py 2007-02-01 17:40:38 +0000
+++ b/bzrlib/smart/request.py 2007-02-02 17:34:08 +0000
@@ -272,6 +272,8 @@
request_handlers.register_lazy(
'Repository.has_revision', 'bzrlib.smart.repository', 'SmartServerRequestHasRevision')
request_handlers.register_lazy(
+ 'Repository.is_shared', 'bzrlib.smart.repository', 'SmartServerRepositoryIsShared')
+request_handlers.register_lazy(
'rmdir', 'bzrlib.smart.vfs', 'RmdirRequest')
request_handlers.register_lazy(
'stat', 'bzrlib.smart.vfs', 'StatRequest')
=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py 2007-02-01 17:40:38 +0000
+++ b/bzrlib/tests/test_remote.py 2007-02-02 17:34:08 +0000
@@ -28,6 +28,7 @@
RemoteBranch,
RemoteBzrDir,
RemoteBzrDirFormat,
+ RemoteRepository,
)
from bzrlib.revision import NULL_REVISION
from bzrlib.smart import server
@@ -129,3 +130,41 @@
[('call', 'Branch.last_revision_info', ('///kwaak/',))],
client._calls)
self.assertEqual((2, u'\xc8'), result)
+
+
+class TestRepositoryIsShared(tests.TestCase):
+
+ def setup_fake_client_and_repository(self, responses, transport_path):
+ """Create the fake client and repository for testing with."""
+ client = FakeClient(responses)
+ transport = MemoryTransport()
+ transport.mkdir(transport_path)
+ transport = transport.clone(transport_path)
+ # we do not want bzrdir to make any remote calls
+ bzrdir = RemoteBzrDir(transport, _client=False)
+ repo = RemoteRepository(bzrdir, None, _client=client)
+ return repo, client
+
+ def test_is_shared(self):
+ # ('yes', ) for Repository.is_shared -> 'True'.
+ responses = [('yes', )]
+ transport_path = 'quack'
+ repo, client = self.setup_fake_client_and_repository(
+ responses, transport_path)
+ result = repo.is_shared()
+ self.assertEqual(
+ [('call', 'Repository.is_shared', ('///quack/',))],
+ client._calls)
+ self.assertEqual(True, result)
+
+ def test_is_not_shared(self):
+ # ('no', ) for Repository.is_shared -> 'False'.
+ responses = [('no', )]
+ transport_path = 'qwack'
+ repo, client = self.setup_fake_client_and_repository(
+ responses, transport_path)
+ result = repo.is_shared()
+ self.assertEqual(
+ [('call', 'Repository.is_shared', ('///qwack/',))],
+ client._calls)
+ self.assertEqual(False, result)
=== modified file 'bzrlib/tests/test_smart.py'
--- a/bzrlib/tests/test_smart.py 2007-02-02 17:05:49 +0000
+++ b/bzrlib/tests/test_smart.py 2007-02-02 17:34:08 +0000
@@ -250,6 +250,24 @@
u'\xc8abc'.encode('utf8')))
+class TestSmartServerRepositoryIsShared(tests.TestCaseWithTransport):
+
+ def test_is_shared(self):
+ """For a shared repository, ('yes', ) is returned."""
+ backing = self.get_transport()
+ request = smart.repository.SmartServerRepositoryIsShared(backing)
+ self.make_repository('.', shared=True)
+ self.assertEqual(SmartServerResponse(('yes', )),
+ request.execute(backing.local_abspath(''), ))
+
+ def test_is_not_shared(self):
+ """For a shared repository, ('yes', ) is returned."""
+ backing = self.get_transport()
+ request = smart.repository.SmartServerRepositoryIsShared(backing)
+ self.make_repository('.', shared=False)
+ self.assertEqual(SmartServerResponse(('no', )),
+ request.execute(backing.local_abspath(''), ))
+
class TestHandlers(tests.TestCase):
"""Tests for the request.request_handlers object."""
@@ -274,3 +292,6 @@
self.assertEqual(
smart.request.request_handlers.get('Repository.has_revision'),
smart.repository.SmartServerRequestHasRevision)
+ self.assertEqual(
+ smart.request.request_handlers.get('Repository.is_shared'),
+ smart.repository.SmartServerRepositoryIsShared)
More information about the bazaar-commits
mailing list