Rev 2236: Add a _server_formats flag to BzrDir.open_from_transport and BzrDirFormat.find_format, make RemoteBranch.control_files into a property. in sftp://bazaar.launchpad.net/%7Ebzr/bzr/hpss/
Andrew Bennetts
andrew.bennetts at canonical.com
Wed Apr 18 12:29:14 BST 2007
At sftp://bazaar.launchpad.net/%7Ebzr/bzr/hpss/
------------------------------------------------------------
revno: 2236
revision-id: andrew.bennetts at canonical.com-20070418112756-0sqsp5yxemwt3mrg
parent: andrew.bennetts at canonical.com-20070418112453-r2711iqib94kutx0
committer: Andrew Bennetts <andrew.bennetts at canonical.com>
branch nick: hpss
timestamp: Wed 2007-04-18 21:27:56 +1000
message:
Add a _server_formats flag to BzrDir.open_from_transport and BzrDirFormat.find_format, make RemoteBranch.control_files into a property.
modified:
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/tests/test_remote.py test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py 2007-04-17 09:01:53 +0000
+++ b/bzrlib/bzrdir.py 2007-04-18 11:27:56 +0000
@@ -527,7 +527,8 @@
return BzrDir.open_from_transport(t, _unsupported=_unsupported)
@staticmethod
- def open_from_transport(transport, _unsupported=False):
+ def open_from_transport(transport, _unsupported=False,
+ _server_formats=True):
"""Open a bzrdir within a particular directory.
:param transport: Transport containing the bzrdir.
@@ -536,7 +537,8 @@
base = transport.base
def find_format(transport):
- return transport, BzrDirFormat.find_format(transport)
+ return transport, BzrDirFormat.find_format(
+ transport, _server_formats=_server_formats)
def redirected(transport, e, redirection_notice):
qualified_source = e.get_source_url()
@@ -1213,15 +1215,25 @@
This is a list of BzrDirFormat objects.
"""
+ _control_server_formats = []
+ """The registered control server formats, e.g. RemoteBzrDirs.
+
+ This is a list of BzrDirFormat objects.
+ """
+
_lock_file_name = 'branch-lock'
# _lock_class must be set in subclasses to the lock type, typ.
# TransportLock or LockDir
@classmethod
- def find_format(klass, transport):
+ def find_format(klass, transport, _server_formats=True):
"""Return the format present at transport."""
- for format in klass._control_formats:
+ if _server_formats:
+ formats = klass._control_server_formats + klass._control_formats
+ else:
+ formats = klass._control_formats
+ for format in formats:
try:
return format.probe_transport(transport)
except errors.NotBranchError:
@@ -1385,7 +1397,7 @@
chance to grab it before anything looks at the contents of the format
file.
"""
- klass._control_formats.insert(0, format)
+ klass._control_server_formats.append(format)
@classmethod
@symbol_versioning.deprecated_method(symbol_versioning.zero_fourteen)
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2007-04-18 05:10:19 +0000
+++ b/bzrlib/remote.py 2007-04-18 11:27:56 +0000
@@ -69,12 +69,8 @@
Used before calls to self._real_bzrdir.
"""
if not self._real_bzrdir:
- # XXX: We can't use BzrDir.open_from_transport here because it
- # causes infinite recursion, so just try opening the bzrdir with the
- # default format.
- default_format = BzrDirFormat.get_default_format()
- self._real_bzrdir = default_format.open(self.root_transport,
- _found=True)
+ self._real_bzrdir = BzrDir.open_from_transport(
+ self.root_transport, _server_formats=False)
def create_repository(self, shared=False):
self._ensure_real()
@@ -709,7 +705,7 @@
# Fill out expected attributes of branch for bzrlib api users.
self._format = RemoteBranchFormat()
self.base = self.bzrdir.root_transport.base
- self.control_files = RemoteBranchLockableFiles(self.bzrdir, self._client)
+ self._control_files = None
self._lock_mode = None
self._lock_token = None
self._lock_count = 0
@@ -736,6 +732,15 @@
if self._lock_mode == 'r':
self._real_branch.lock_read()
+ @property
+ def control_files(self):
+ # Defer actually creating RemoteBranchLockableFiles until its needed,
+ # because it triggers an _ensure_real that we otherwise might not need.
+ if self._control_files is None:
+ self._control_files = RemoteBranchLockableFiles(
+ self.bzrdir, self._client)
+ return self._control_files
+
def _get_checkout_format(self):
self._ensure_real()
return self._real_branch._get_checkout_format()
=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py 2007-04-18 05:10:19 +0000
+++ b/bzrlib/tests/test_remote.py 2007-04-18 11:27:56 +0000
@@ -88,7 +88,8 @@
def test_find_correct_format(self):
"""Should open a RemoteBzrDir over a RemoteTransport"""
fmt = BzrDirFormat.find_format(self.transport)
- self.assertTrue(RemoteBzrDirFormat in BzrDirFormat._control_formats)
+ self.assertTrue(RemoteBzrDirFormat
+ in BzrDirFormat._control_server_formats)
self.assertIsInstance(fmt, remote.RemoteBzrDirFormat)
def test_open_detected_smart_format(self):
@@ -323,10 +324,10 @@
branch.unlock()
-class TestBranchControlGetBranchConf(tests.TestCase):
+class TestBranchControlGetBranchConf(tests.TestCaseWithMemoryTransport):
"""Test branch.control_files api munging...
- we special case RemoteBranch.control_files.get('branch.conf') to
+ We special case RemoteBranch.control_files.get('branch.conf') to
call a specific API so that RemoteBranch's can intercept configuration
file reading, allowing them to signal to the client about things like
'email is configured for commits'.
@@ -335,9 +336,10 @@
def test_get_branch_conf(self):
# in an empty branch we decode the response properly
client = FakeClient([(('ok', ), 'config file body')])
- transport = MemoryTransport()
- transport.mkdir('quack')
- transport = transport.clone('quack')
+ # we need to make a real branch because the remote_branch.control_files
+ # will trigger _ensure_real.
+ branch = self.make_branch('quack')
+ transport = branch.bzrdir.root_transport
# we do not want bzrdir to make any remote calls
bzrdir = RemoteBzrDir(transport, _client=False)
branch = RemoteBranch(bzrdir, None, _client=client)
More information about the bazaar-commits
mailing list