Rev 4295: Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations. in http://people.ubuntu.com/~robertc/baz2.0/pending/push.roundtrips
Robert Collins
robertc at robertcollins.net
Wed Apr 15 03:07:38 BST 2009
At http://people.ubuntu.com/~robertc/baz2.0/pending/push.roundtrips
------------------------------------------------------------
revno: 4295
revision-id: robertc at robertcollins.net-20090415020735-poizrhi1b98mtdgk
parent: robertc at robertcollins.net-20090415020527-yyh3muljj0kftcjr
committer: Robert Collins <robertc at robertcollins.net>
branch nick: push.roundtrips
timestamp: Wed 2009-04-15 12:07:35 +1000
message:
Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.
=== modified file 'NEWS'
--- a/NEWS 2009-04-15 00:00:35 +0000
+++ b/NEWS 2009-04-15 02:07:35 +0000
@@ -54,6 +54,10 @@
class and will call ``_set_parent_location`` after doing unicode
encoding. (Robert Collins)
+* ``bzrlib.remote.RemoteBranch._set_parent_location`` will use a new verb
+ ``Branch.set_parent_location`` removing further VFS operations.
+ (Robert Collins)
+
* ``bzrlib.bzrdir.BzrDir._get_config`` now returns a ``TransportConfig``
or similar when the dir supports configuration settings. The base class
defaults to None. There is a matching new server verb
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2009-04-15 00:00:35 +0000
+++ b/bzrlib/remote.py 2009-04-15 02:07:35 +0000
@@ -2301,6 +2301,23 @@
return self._real_branch._get_parent_location()
def _set_parent_location(self, url):
+ medium = self._client._medium
+ if medium._is_remote_before((1, 15)):
+ return self._vfs_set_parent_location(url)
+ try:
+ call_url = url or ''
+ if type(call_url) is not str:
+ raise AssertionError('url must be a str or None (%s)' % url)
+ response = self._call('Branch.set_parent_location',
+ self._remote_path(), self._lock_token, self._repo_lock_token,
+ call_url)
+ except errors.UnknownSmartMethod:
+ medium._remember_remote_is_before((1, 15))
+ return self._vfs_set_parent_location(url)
+ if response != ():
+ raise errors.UnexpectedSmartServerResponse(response)
+
+ def _vfs_set_parent_location(self, url):
self._ensure_real()
return self._real_branch._set_parent_location(url)
=== modified file 'bzrlib/smart/branch.py'
--- a/bzrlib/smart/branch.py 2009-04-03 00:37:53 +0000
+++ b/bzrlib/smart/branch.py 2009-04-15 02:07:35 +0000
@@ -237,6 +237,17 @@
return SuccessfulSmartServerResponse(('ok',))
+class SmartServerBranchRequestSetParentLocation(SmartServerLockedBranchRequest):
+ """Set the parent location for a branch.
+
+ Takes a location to set, which must be utf8 encoded.
+ """
+
+ def do_with_locked_branch(self, branch, location):
+ branch._set_parent_location(location)
+ return SuccessfulSmartServerResponse(())
+
+
class SmartServerBranchRequestLockWrite(SmartServerBranchRequest):
def do_with_branch(self, branch, branch_token='', repo_token=''):
=== modified file 'bzrlib/smart/request.py'
--- a/bzrlib/smart/request.py 2009-04-14 04:33:41 +0000
+++ b/bzrlib/smart/request.py 2009-04-15 02:07:35 +0000
@@ -461,6 +461,9 @@
'Branch.set_last_revision_ex', 'bzrlib.smart.branch',
'SmartServerBranchRequestSetLastRevisionEx')
request_handlers.register_lazy(
+ 'Branch.set_parent_location', 'bzrlib.smart.branch',
+ 'SmartServerBranchRequestSetParentLocation')
+request_handlers.register_lazy(
'Branch.unlock', 'bzrlib.smart.branch', 'SmartServerBranchRequestUnlock')
request_handlers.register_lazy(
'BzrDir.cloning_metadir', 'bzrlib.smart.bzrdir',
=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- a/bzrlib/tests/blackbox/test_branch.py 2009-04-14 07:11:01 +0000
+++ b/bzrlib/tests/blackbox/test_branch.py 2009-04-15 02:07:35 +0000
@@ -272,7 +272,7 @@
# being too low. If rpc_count increases, more network roundtrips have
# become necessary for this use case. Please do not adjust this number
# upwards without agreement from bzr's network support maintainers.
- self.assertLength(47, self.hpss_calls)
+ self.assertLength(41, self.hpss_calls)
def test_branch_from_trivial_branch_streaming_acceptance(self):
self.setup_smart_server_with_call_log()
=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py 2009-04-15 00:00:35 +0000
+++ b/bzrlib/tests/blackbox/test_push.py 2009-04-15 02:07:35 +0000
@@ -217,7 +217,7 @@
# being too low. If rpc_count increases, more network roundtrips have
# become necessary for this use case. Please do not adjust this number
# upwards without agreement from bzr's network support maintainers.
- self.assertLength(37, self.hpss_calls)
+ self.assertLength(28, self.hpss_calls)
remote = Branch.open('public')
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py 2009-04-14 04:33:41 +0000
+++ b/bzrlib/tests/test_remote.py 2009-04-15 02:07:35 +0000
@@ -844,6 +844,54 @@
branch = self.make_remote_branch(transport, client)
result = branch.get_parent()
self.assertEqual('http://foo/', result)
+ client.finished_test()
+
+
+class TestBranchSetParentLocation(RemoteBranchTestCase):
+
+ def test_no_parent(self):
+ # We call the verb when setting parent to None
+ transport = MemoryTransport()
+ client = FakeClient(transport.base)
+ client.add_expected_call(
+ 'Branch.get_stacked_on_url', ('quack/',),
+ 'error', ('NotStacked',))
+ client.add_expected_call(
+ 'Branch.set_parent_location', ('quack/', 'b', 'r', ''),
+ 'success', ())
+ transport.mkdir('quack')
+ transport = transport.clone('quack')
+ branch = self.make_remote_branch(transport, client)
+ branch._lock_token = 'b'
+ branch._repo_lock_token = 'r'
+ branch._set_parent_location(None)
+ client.finished_test()
+
+ def test_parent(self):
+ transport = MemoryTransport()
+ client = FakeClient(transport.base)
+ client.add_expected_call(
+ 'Branch.get_stacked_on_url', ('kwaak/',),
+ 'error', ('NotStacked',))
+ client.add_expected_call(
+ 'Branch.set_parent_location', ('kwaak/', 'b', 'r', 'foo'),
+ 'success', ())
+ transport.mkdir('kwaak')
+ transport = transport.clone('kwaak')
+ branch = self.make_remote_branch(transport, client)
+ branch._lock_token = 'b'
+ branch._repo_lock_token = 'r'
+ branch._set_parent_location('foo')
+ client.finished_test()
+
+ def test_backwards_compat(self):
+ self.setup_smart_server_with_call_log()
+ branch = self.make_branch('.')
+ self.reset_smart_call_log()
+ verb = 'Branch.set_parent_location'
+ self.disable_verb(verb)
+ branch.set_parent('http://foo/')
+ self.assertLength(12, self.hpss_calls)
class TestBranchGetTagsBytes(RemoteBranchTestCase):
=== modified file 'bzrlib/tests/test_smart.py'
--- a/bzrlib/tests/test_smart.py 2009-04-14 04:33:41 +0000
+++ b/bzrlib/tests/test_smart.py 2009-04-15 02:07:35 +0000
@@ -792,6 +792,39 @@
response)
+class TestSmartServerBranchRequestSetParent(tests.TestCaseWithMemoryTransport):
+
+ def test_set_parent_none(self):
+ branch = self.make_branch('base', format="1.9")
+ branch._set_parent_location('foo')
+ request = smart.branch.SmartServerBranchRequestSetParentLocation(
+ self.get_transport())
+ branch_token = branch.lock_write()
+ repo_token = branch.repository.lock_write()
+ try:
+ response = request.execute('base', branch_token, repo_token, '')
+ finally:
+ branch.repository.unlock()
+ branch.unlock()
+ self.assertEqual(SuccessfulSmartServerResponse(()), response)
+ self.assertEqual(None, branch.get_parent())
+
+ def test_set_parent_something(self):
+ branch = self.make_branch('base', format="1.9")
+ request = smart.branch.SmartServerBranchRequestSetParentLocation(
+ self.get_transport())
+ branch_token = branch.lock_write()
+ repo_token = branch.repository.lock_write()
+ try:
+ response = request.execute('base', branch_token, repo_token,
+ 'http://bar/')
+ finally:
+ branch.repository.unlock()
+ branch.unlock()
+ self.assertEqual(SuccessfulSmartServerResponse(()), response)
+ self.assertEqual('http://bar/', branch.get_parent())
+
+
class TestSmartServerBranchRequestGetTagsBytes(tests.TestCaseWithMemoryTransport):
# Only called when the branch format and tags match [yay factory
# methods] so only need to test straight forward cases.
@@ -1432,6 +1465,10 @@
smart.branch.SmartServerBranchRequestSetLastRevision)
self.assertHandlerEqual('Branch.set_last_revision_info',
smart.branch.SmartServerBranchRequestSetLastRevisionInfo)
+ self.assertHandlerEqual('Branch.set_last_revision_ex',
+ smart.branch.SmartServerBranchRequestSetLastRevisionEx)
+ self.assertHandlerEqual('Branch.set_parent_location',
+ smart.branch.SmartServerBranchRequestSetParentLocation)
self.assertHandlerEqual('Branch.unlock',
smart.branch.SmartServerBranchRequestUnlock)
self.assertHandlerEqual('BzrDir.find_repository',
More information about the bazaar-commits
mailing list