Rev 3223: * New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for in http://people.ubuntu.com/~robertc/baz2.0/shallow-branch
Robert Collins
robertc at robertcollins.net
Tue Feb 12 04:53:11 GMT 2008
At http://people.ubuntu.com/~robertc/baz2.0/shallow-branch
------------------------------------------------------------
revno: 3223
revision-id:robertc at robertcollins.net-20080212045218-2yo8xf84u7458320
parent: robertc at robertcollins.net-20080212023827-019lghqbrm3tukgl
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository-stackable-flag
timestamp: Tue 2008-02-12 15:52:18 +1100
message:
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
detecting external lookup support on remote repositories.
(Robert Collins)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/smart/bzrdir.py bzrdir.py-20061122024551-ol0l0o0oofsu9b3t-1
bzrlib/smart/request.py request.py-20061108095550-gunadhxmzkdjfeek-1
bzrlib/tests/test_smart.py test_smart.py-20061122024551-ol0l0o0oofsu9b3t-2
=== modified file 'NEWS'
--- a/NEWS 2008-02-12 02:38:27 +0000
+++ b/NEWS 2008-02-12 04:52:18 +0000
@@ -170,6 +170,10 @@
which will split out ghosts and present parents into two separate sets,
useful for code which needs to be aware of ghosts (e.g. fetching data
cares about ghosts during revision selection). (Robert Collins)
+
+ * New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
+ detecting external lookup support on remote repositories.
+ (Robert Collins)
* Record a timestamp against each mutter to the trace file, relative to the
first import of bzrlib. (Andrew Bennetts)
=== modified file 'bzrlib/smart/bzrdir.py'
--- a/bzrlib/smart/bzrdir.py 2007-04-24 12:20:09 +0000
+++ b/bzrlib/smart/bzrdir.py 2008-02-12 04:52:18 +0000
@@ -44,35 +44,83 @@
class SmartServerRequestFindRepository(SmartServerRequest):
- def do(self, path):
+ def _boolean_to_yes_no(self, a_boolean):
+ if a_boolean:
+ return 'yes'
+ else:
+ return 'no'
+
+ def _find(self, path):
"""try to find a repository from path upwards
This operates precisely like 'bzrdir.find_repository'.
- If a bzrdir is not present, an exception is propogated
- rather than 'no branch' because these are different conditions.
-
- :return: norepository or ok, relpath.
+ :return: (relpath, rich_root, tree_ref, external_lookup) flags. All are
+ strings, relpath is a / prefixed path, and the other three are
+ either 'yes' or 'no'.
+ :raises errors.NoRepositoryPresent: When there is no repository
+ present.
"""
bzrdir = BzrDir.open_from_transport(self._backing_transport.clone(path))
- try:
- repository = bzrdir.find_repository()
- # the relpath of the bzrdir in the found repository gives us the
- # path segments to pop-out.
- relpath = repository.bzrdir.root_transport.relpath(bzrdir.root_transport.base)
- if len(relpath):
- segments = ['..'] * len(relpath.split('/'))
- else:
- segments = []
- if repository.supports_rich_root():
- rich_root = 'yes'
- else:
- rich_root = 'no'
- if repository._format.supports_tree_reference:
- tree_ref = 'yes'
- else:
- tree_ref = 'no'
- return SuccessfulSmartServerResponse(('ok', '/'.join(segments), rich_root, tree_ref))
+ repository = bzrdir.find_repository()
+ # the relpath of the bzrdir in the found repository gives us the
+ # path segments to pop-out.
+ relpath = repository.bzrdir.root_transport.relpath(bzrdir.root_transport.base)
+ if len(relpath):
+ segments = ['..'] * len(relpath.split('/'))
+ else:
+ segments = []
+ rich_root = self._boolean_to_yes_no(repository.supports_rich_root())
+ tree_ref = self._boolean_to_yes_no(
+ repository._format.supports_tree_reference)
+ external_lookup = self._boolean_to_yes_no(
+ repository._format.supports_external_lookups)
+ return '/'.join(segments), rich_root, tree_ref, external_lookup
+
+
+class SmartServerRequestFindRepositoryV1(SmartServerRequestFindRepository):
+
+ def do(self, path):
+ """try to find a repository from path upwards
+
+ This operates precisely like 'bzrdir.find_repository'.
+
+ If a bzrdir is not present, an exception is propogated
+ rather than 'no branch' because these are different conditions.
+
+ This is the initial version of this method introduced with the smart
+ server. Modern clients will try the V2 method that adds support for the
+ supports_external_lookups attribute.
+
+ :return: norepository or ok, relpath.
+ """
+ try:
+ path, rich_root, tree_ref, external_lookup = self._find(path)
+ return SuccessfulSmartServerResponse(('ok', path, rich_root, tree_ref))
+ except errors.NoRepositoryPresent:
+ return FailedSmartServerResponse(('norepository', ))
+
+
+class SmartServerRequestFindRepositoryV2(SmartServerRequestFindRepository):
+
+ def do(self, path):
+ """try to find a repository from path upwards
+
+ This operates precisely like 'bzrdir.find_repository'.
+
+ If a bzrdir is not present, an exception is propogated
+ rather than 'no branch' because these are different conditions.
+
+ This is the second edition of this method introduced in bzr 1.2, which
+ returns information about the supports_external_lookups format
+ attribute too.
+
+ :return: norepository or ok, relpath.
+ """
+ try:
+ path, rich_root, tree_ref, external_lookup = self._find(path)
+ return SuccessfulSmartServerResponse(
+ ('ok', path, rich_root, tree_ref, external_lookup))
except errors.NoRepositoryPresent:
return FailedSmartServerResponse(('norepository', ))
=== modified file 'bzrlib/smart/request.py'
--- a/bzrlib/smart/request.py 2008-01-17 07:47:52 +0000
+++ b/bzrlib/smart/request.py 2008-02-12 04:52:18 +0000
@@ -286,7 +286,9 @@
request_handlers.register_lazy(
'Branch.unlock', 'bzrlib.smart.branch', 'SmartServerBranchRequestUnlock')
request_handlers.register_lazy(
- 'BzrDir.find_repository', 'bzrlib.smart.bzrdir', 'SmartServerRequestFindRepository')
+ 'BzrDir.find_repository', 'bzrlib.smart.bzrdir', 'SmartServerRequestFindRepositoryV1')
+request_handlers.register_lazy(
+ 'BzrDir.find_repositoryV2', 'bzrlib.smart.bzrdir', 'SmartServerRequestFindRepositoryV2')
request_handlers.register_lazy(
'BzrDirFormat.initialize', 'bzrlib.smart.bzrdir', 'SmartServerRequestInitializeBzrDir')
request_handlers.register_lazy(
=== modified file 'bzrlib/tests/test_smart.py'
--- a/bzrlib/tests/test_smart.py 2008-02-05 22:42:47 +0000
+++ b/bzrlib/tests/test_smart.py 2008-02-12 04:52:18 +0000
@@ -38,9 +38,37 @@
import bzrlib.smart.bzrdir
import bzrlib.smart.branch
import bzrlib.smart.repository
+from bzrlib.tests import (
+ iter_suite_tests,
+ split_suite_by_re,
+ TestScenarioApplier,
+ )
from bzrlib.util import bencode
+def load_tests(standard_tests, module, loader):
+ """Multiply tests version and protocol consistency."""
+ # FindRepository tests.
+ bzrdir_mod = bzrlib.smart.bzrdir
+ applier = TestScenarioApplier()
+ applier.scenarios = [
+ ("find_repository", {
+ "_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV1}),
+ ("find_repositoryV2", {
+ "_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV2}),
+ ]
+ to_adapt, result = split_suite_by_re(standard_tests,
+ "TestSmartServerRequestFindRepository")
+ v2_only, v1_and_2 = split_suite_by_re(to_adapt,
+ "_v2")
+ for test in iter_suite_tests(v1_and_2):
+ result.addTests(applier.adapt(test))
+ del applier.scenarios[0]
+ for test in iter_suite_tests(v2_only):
+ result.addTests(applier.adapt(test))
+ return result
+
+
class TestCaseWithSmartMedium(tests.TestCaseWithTransport):
def setUp(self):
@@ -77,7 +105,7 @@
def test_no_repository(self):
"""When there is no repository to be found, ('norepository', ) is returned."""
backing = self.get_transport()
- request = smart.bzrdir.SmartServerRequestFindRepository(backing)
+ request = self._request_class(backing)
self.make_bzrdir('.')
self.assertEqual(SmartServerResponse(('norepository', )),
request.execute(backing.local_abspath('')))
@@ -87,7 +115,7 @@
# path the repository is being searched on is the same as that that
# the repository is at.
backing = self.get_transport()
- request = smart.bzrdir.SmartServerRequestFindRepository(backing)
+ request = self._request_class(backing)
result = self._make_repository_and_result()
self.assertEqual(result, request.execute(backing.local_abspath('')))
self.make_bzrdir('subdir')
@@ -108,12 +136,19 @@
subtrees = 'yes'
else:
subtrees = 'no'
- return SmartServerResponse(('ok', '', rich_root, subtrees))
+ if (smart.bzrdir.SmartServerRequestFindRepositoryV2 ==
+ self._request_class):
+ # All tests so far are on formats, and for non-external
+ # repositories.
+ return SuccessfulSmartServerResponse(
+ ('ok', '', rich_root, subtrees, 'no'))
+ else:
+ return SuccessfulSmartServerResponse(('ok', '', rich_root, subtrees))
def test_shared_repository(self):
"""When there is a shared repository, we get 'ok', 'relpath-to-repo'."""
backing = self.get_transport()
- request = smart.bzrdir.SmartServerRequestFindRepository(backing)
+ request = self._request_class(backing)
result = self._make_repository_and_result(shared=True)
self.assertEqual(result, request.execute(backing.local_abspath('')))
self.make_bzrdir('subdir')
@@ -128,13 +163,22 @@
def test_rich_root_and_subtree_encoding(self):
"""Test for the format attributes for rich root and subtree support."""
backing = self.get_transport()
- request = smart.bzrdir.SmartServerRequestFindRepository(backing)
+ request = self._request_class(backing)
result = self._make_repository_and_result(format='dirstate-with-subtree')
# check the test will be valid
self.assertEqual('yes', result.args[2])
self.assertEqual('yes', result.args[3])
self.assertEqual(result, request.execute(backing.local_abspath('')))
+ def test_supports_external_lookups_no_v2(self):
+ """Test for the supports_external_lookups attribute."""
+ backing = self.get_transport()
+ request = self._request_class(backing)
+ result = self._make_repository_and_result(format='dirstate-with-subtree')
+ # check the test will be valid
+ self.assertEqual('no', result.args[4])
+ self.assertEqual(result, request.execute(backing.local_abspath('')))
+
class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithTransport):
@@ -922,7 +966,10 @@
smart.branch.SmartServerBranchRequestUnlock)
self.assertEqual(
smart.request.request_handlers.get('BzrDir.find_repository'),
- smart.bzrdir.SmartServerRequestFindRepository)
+ smart.bzrdir.SmartServerRequestFindRepositoryV1)
+ self.assertEqual(
+ smart.request.request_handlers.get('BzrDir.find_repositoryV2'),
+ smart.bzrdir.SmartServerRequestFindRepositoryV2)
self.assertEqual(
smart.request.request_handlers.get('BzrDirFormat.initialize'),
smart.bzrdir.SmartServerRequestInitializeBzrDir)
More information about the bazaar-commits
mailing list