Rev 4022: Review feedback - make RemoteRepository.initialize use helpers, and version-lock the new method to not attempt the method on older servers. in http://people.ubuntu.com/~robertc/baz2.0/push.roundtrips
Robert Collins
robertc at robertcollins.net
Fri Feb 20 03:27:11 GMT 2009
At http://people.ubuntu.com/~robertc/baz2.0/push.roundtrips
------------------------------------------------------------
revno: 4022
revision-id: robertc at robertcollins.net-20090220032708-83exgbd9tymcs051
parent: robertc at robertcollins.net-20090219072837-vznmfrq7lz1grtti
committer: Robert Collins <robertc at robertcollins.net>
branch nick: push.roundtrips
timestamp: Fri 2009-02-20 14:27:08 +1100
message:
Review feedback - make RemoteRepository.initialize use helpers, and version-lock the new method to not attempt the method on older servers.
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2009-02-19 07:28:37 +0000
+++ b/bzrlib/remote.py 2009-02-20 03:27:08 +0000
@@ -283,20 +283,40 @@
repository.RepositoryFormat.__init__(self)
self._custom_format = None
self._network_name = None
+ self._creating_bzrdir = None
+
+ def _vfs_initialize(self, a_bzrdir, shared):
+ """Helper for common code in initialize."""
+ if self._custom_format:
+ # Custom format requested
+ result = self._custom_format.initialize(a_bzrdir, shared=shared)
+ elif self._creating_bzrdir is not None:
+ # Use the format that the repository we were created to back
+ # has.
+ prior_repo = self._creating_bzrdir.open_repository()
+ prior_repo._ensure_real()
+ result = prior_repo._real_repository._format.initialize(
+ a_bzrdir, shared=shared)
+ else:
+ # assume that a_bzr is a RemoteBzrDir but the smart server didn't
+ # support remote initialization.
+ # We delegate to a real object at this point (as RemoteBzrDir
+ # delegate to the repository format which would lead to infinite
+ # recursion if we just called a_bzrdir.create_repository.
+ a_bzrdir._ensure_real()
+ result = a_bzrdir._real_bzrdir.create_repository(shared=shared)
+ if not isinstance(result, RemoteRepository):
+ return self.open(a_bzrdir)
+ else:
+ return result
def initialize(self, a_bzrdir, shared=False):
# Being asked to create on a non RemoteBzrDir:
if not isinstance(a_bzrdir, RemoteBzrDir):
- if self._custom_format:
- # Custom format requested
- return self._custom_format.initialize(a_bzrdir, shared=shared)
- else:
- # Use the format that the repository we were created to back
- # has.
- prior_repo = self._creating_bzrdir.open_repository()
- prior_repo._ensure_real()
- return prior_repo._real_repository._format.initialize(
- a_bzrdir, shared=shared)
+ return self._vfs_initialize(a_bzrdir, shared)
+ medium = a_bzrdir._client._medium
+ if medium._is_remote_before((1, 13)):
+ return self._vfs_initialize(a_bzrdir, shared)
# Creating on a remote bzr dir.
# 1) get the network name to use.
if self._custom_format:
@@ -316,19 +336,8 @@
try:
response = a_bzrdir._call(verb, path, network_name, shared_str)
except errors.UnknownSmartMethod:
- # Fallback - vfs methods
- if self._custom_format:
- # This returns a custom instance - e.g. a pack repo, not a remote
- # repo.
- return self._custom_format.initialize(a_bzrdir, shared=shared)
- # delegate to a real object at this point (remoteBzrDir delegate to the
- # repository format which would lead to infinite recursion).
- a_bzrdir._ensure_real()
- result = a_bzrdir._real_bzrdir.create_repository(shared=shared)
- if not isinstance(result, RemoteRepository):
- return self.open(a_bzrdir)
- else:
- return result
+ # Fallback - use vfs methods
+ return self._vfs_initialize(a_bzrdir, shared)
else:
# Turn the response into a RemoteRepository object.
format = RemoteRepositoryFormat()
=== modified file 'bzrlib/smart/medium.py'
--- a/bzrlib/smart/medium.py 2009-01-07 00:58:30 +0000
+++ b/bzrlib/smart/medium.py 2009-02-20 03:27:08 +0000
@@ -574,6 +574,10 @@
"""
if (self._remote_version_is_before is not None and
version_tuple > self._remote_version_is_before):
+ # We have been told that the remote side is older than some version
+ # which is newer than a previously supplied older-than version.
+ # This indicates that some smart verb call is not guarded
+ # appropriately (it should simply not have been tried).
raise AssertionError(
"_remember_remote_is_before(%r) called, but "
"_remember_remote_is_before(%r) was called previously."
More information about the bazaar-commits
mailing list