Rev 4713: (andrew) Remove last two HPSS VFS calls during incremental push. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Thu Sep 24 07:44:19 BST 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4713 [merge]
revision-id: pqm at pqm.ubuntu.com-20090924064418-h9ke4tfywi57otzi
parent: pqm at pqm.ubuntu.com-20090923065414-vue8c7speunw9wbq
parent: andrew.bennetts at canonical.com-20090924053123-ztws4evq98lfgbr2
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2009-09-24 07:44:18 +0100
message:
(andrew) Remove last two HPSS VFS calls during incremental push.
modified:
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/smart/bzrdir.py bzrdir.py-20061122024551-ol0l0o0oofsu9b3t-1
bzrlib/smart/request.py request.py-20061108095550-gunadhxmzkdjfeek-1
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
bzrlib/tests/blackbox/test_shared_repository.py test_shared_repository.py-20060317053531-ed30c0d79325e483
bzrlib/tests/per_branch/test_push.py test_push.py-20070130153159-fhfap8uoifevg30j-1
bzrlib/tests/test_remote.py test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
bzrlib/tests/test_smart.py test_smart.py-20061122024551-ol0l0o0oofsu9b3t-2
bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py 2009-08-21 02:10:06 +0000
+++ b/bzrlib/bzrdir.py 2009-09-24 04:10:39 +0000
@@ -1537,6 +1537,10 @@
This is a deprecated format and may be removed after sept 2006.
"""
+ def has_workingtree(self):
+ """See BzrDir.has_workingtree."""
+ return True
+
def open_repository(self):
"""See BzrDir.open_repository."""
from bzrlib.repofmt.weaverepo import RepositoryFormat5
@@ -1558,6 +1562,10 @@
This is a deprecated format and may be removed after sept 2006.
"""
+ def has_workingtree(self):
+ """See BzrDir.has_workingtree."""
+ return True
+
def open_repository(self):
"""See BzrDir.open_repository."""
from bzrlib.repofmt.weaverepo import RepositoryFormat6
@@ -1683,6 +1691,22 @@
pass
return self.transport.clone('checkout')
+ def has_workingtree(self):
+ """Tell if this bzrdir contains a working tree.
+
+ This will still raise an exception if the bzrdir has a workingtree that
+ is remote & inaccessible.
+
+ Note: if you're going to open the working tree, you should just go
+ ahead and try, and not ask permission first.
+ """
+ from bzrlib.workingtree import WorkingTreeFormat
+ try:
+ WorkingTreeFormat.find_format(self)
+ except errors.NoWorkingTree:
+ return False
+ return True
+
def needs_format_conversion(self, format=None):
"""See BzrDir.needs_format_conversion()."""
if format is None:
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2009-09-15 01:52:34 +0000
+++ b/bzrlib/remote.py 2009-09-24 05:31:23 +0000
@@ -89,7 +89,7 @@
class RemoteBzrDir(BzrDir, _RpcHelper):
"""Control directory on a remote server, accessed via bzr:// or similar."""
- def __init__(self, transport, format, _client=None):
+ def __init__(self, transport, format, _client=None, _force_probe=False):
"""Construct a RemoteBzrDir.
:param _client: Private parameter for testing. Disables probing and the
@@ -99,6 +99,7 @@
# this object holds a delegated bzrdir that uses file-level operations
# to talk to the other side
self._real_bzrdir = None
+ self._has_working_tree = None
# 1-shot cache for the call pattern 'create_branch; open_branch' - see
# create_branch for details.
self._next_open_branch_result = None
@@ -108,14 +109,44 @@
self._client = client._SmartClient(medium)
else:
self._client = _client
- return
-
+ if not _force_probe:
+ return
+
+ self._probe_bzrdir()
+
+ def _probe_bzrdir(self):
+ medium = self._client._medium
path = self._path_for_remote_call(self._client)
+ if medium._is_remote_before((2, 1)):
+ self._rpc_open(path)
+ return
+ try:
+ self._rpc_open_2_1(path)
+ return
+ except errors.UnknownSmartMethod:
+ medium._remember_remote_is_before((2, 1))
+ self._rpc_open(path)
+
+ def _rpc_open_2_1(self, path):
+ response = self._call('BzrDir.open_2.1', path)
+ if response == ('no',):
+ raise errors.NotBranchError(path=self.root_transport.base)
+ elif response[0] == 'yes':
+ if response[1] == 'yes':
+ self._has_working_tree = True
+ elif response[1] == 'no':
+ self._has_working_tree = False
+ else:
+ raise errors.UnexpectedSmartServerResponse(response)
+ else:
+ raise errors.UnexpectedSmartServerResponse(response)
+
+ def _rpc_open(self, path):
response = self._call('BzrDir.open', path)
if response not in [('yes',), ('no',)]:
raise errors.UnexpectedSmartServerResponse(response)
if response == ('no',):
- raise errors.NotBranchError(path=transport.base)
+ raise errors.NotBranchError(path=self.root_transport.base)
def _ensure_real(self):
"""Ensure that there is a _real_bzrdir set.
@@ -355,9 +386,14 @@
else:
raise errors.NoRepositoryPresent(self)
+ def has_workingtree(self):
+ if self._has_working_tree is None:
+ self._ensure_real()
+ self._has_working_tree = self._real_bzrdir.has_workingtree()
+ return self._has_working_tree
+
def open_workingtree(self, recommend_upgrade=True):
- self._ensure_real()
- if self._real_bzrdir.has_workingtree():
+ if self.has_workingtree():
raise errors.NotLocalUrl(self.root_transport)
else:
raise errors.NoWorkingTree(self.root_transport.base)
=== modified file 'bzrlib/smart/bzrdir.py'
--- a/bzrlib/smart/bzrdir.py 2009-06-12 01:48:43 +0000
+++ b/bzrlib/smart/bzrdir.py 2009-09-22 00:34:10 +0000
@@ -34,7 +34,6 @@
class SmartServerRequestOpenBzrDir(SmartServerRequest):
def do(self, path):
- from bzrlib.bzrdir import BzrDirFormat
try:
t = self.transport_from_client_path(path)
except errors.PathNotChild:
@@ -56,6 +55,32 @@
return SuccessfulSmartServerResponse((answer,))
+class SmartServerRequestOpenBzrDir_2_1(SmartServerRequest):
+
+ def do(self, path):
+ """Is there a BzrDir present, and if so does it have a working tree?
+
+ New in 2.1.
+ """
+ try:
+ t = self.transport_from_client_path(path)
+ except errors.PathNotChild:
+ # The client is trying to ask about a path that they have no access
+ # to.
+ return SuccessfulSmartServerResponse(('no',))
+ try:
+ bd = BzrDir.open_from_transport(t)
+ except errors.NotBranchError:
+ answer = ('no',)
+ else:
+ answer = ('yes',)
+ if bd.has_workingtree():
+ answer += ('yes',)
+ else:
+ answer += ('no',)
+ return SuccessfulSmartServerResponse(answer)
+
+
class SmartServerRequestBzrDir(SmartServerRequest):
def do(self, path, *args):
=== modified file 'bzrlib/smart/request.py'
--- a/bzrlib/smart/request.py 2009-09-14 01:48:19 +0000
+++ b/bzrlib/smart/request.py 2009-09-24 05:31:23 +0000
@@ -501,6 +501,8 @@
request_handlers.register_lazy(
'BzrDir.open', 'bzrlib.smart.bzrdir', 'SmartServerRequestOpenBzrDir')
request_handlers.register_lazy(
+ 'BzrDir.open_2.1', 'bzrlib.smart.bzrdir', 'SmartServerRequestOpenBzrDir_2_1')
+request_handlers.register_lazy(
'BzrDir.open_branch', 'bzrlib.smart.bzrdir',
'SmartServerRequestOpenBranch')
request_handlers.register_lazy(
=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py 2009-08-27 22:17:35 +0000
+++ b/bzrlib/tests/blackbox/test_push.py 2009-09-24 05:31:23 +0000
@@ -253,6 +253,22 @@
# upwards without agreement from bzr's network support maintainers.
self.assertLength(11, self.hpss_calls)
+ def test_push_smart_incremental_acceptance(self):
+ self.setup_smart_server_with_call_log()
+ t = self.make_branch_and_tree('from')
+ rev_id1 = t.commit(allow_pointless=True, message='first commit')
+ rev_id2 = t.commit(allow_pointless=True, message='second commit')
+ self.run_bzr(
+ ['push', self.get_url('to-one'), '-r1'], working_dir='from')
+ self.reset_smart_call_log()
+ self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
+ # This figure represent the amount of work to perform this use case. It
+ # is entirely ok to reduce this number if a test fails due to rpc_count
+ # 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(11, self.hpss_calls)
+
def test_push_smart_with_default_stacking_url_path_segment(self):
# If the default stacked-on location is a path element then branches
# we push there over the smart server are stacked and their
=== modified file 'bzrlib/tests/blackbox/test_shared_repository.py'
--- a/bzrlib/tests/blackbox/test_shared_repository.py 2009-08-12 23:52:15 +0000
+++ b/bzrlib/tests/blackbox/test_shared_repository.py 2009-09-23 23:58:10 +0000
@@ -119,4 +119,4 @@
# 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(16, self.hpss_calls)
+ self.assertLength(15, self.hpss_calls)
=== modified file 'bzrlib/tests/per_branch/test_push.py'
--- a/bzrlib/tests/per_branch/test_push.py 2009-08-27 22:17:35 +0000
+++ b/bzrlib/tests/per_branch/test_push.py 2009-09-24 05:31:23 +0000
@@ -413,7 +413,7 @@
target = Branch.open_from_transport(transport)
self.empty_branch.push(target)
self.assertEqual(
- ['BzrDir.open',
+ ['BzrDir.open_2.1',
'BzrDir.open_branchV2',
'BzrDir.find_repositoryV3',
'Branch.get_stacked_on_url',
=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py 2009-09-17 11:54:41 +0000
+++ b/bzrlib/tests/test_remote.py 2009-09-24 05:31:23 +0000
@@ -474,6 +474,57 @@
self.assertFinished(client)
+class TestBzrDirOpen(TestRemote):
+
+ def make_fake_client_and_transport(self, path='quack'):
+ transport = MemoryTransport()
+ transport.mkdir(path)
+ transport = transport.clone(path)
+ client = FakeClient(transport.base)
+ return client, transport
+
+ def test_absent(self):
+ client, transport = self.make_fake_client_and_transport()
+ client.add_expected_call(
+ 'BzrDir.open_2.1', ('quack/',), 'success', ('no',))
+ self.assertRaises(errors.NotBranchError, RemoteBzrDir, transport,
+ remote.RemoteBzrDirFormat(), _client=client, _force_probe=True)
+ self.assertFinished(client)
+
+ def test_present_without_workingtree(self):
+ client, transport = self.make_fake_client_and_transport()
+ client.add_expected_call(
+ 'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'no'))
+ bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
+ _client=client, _force_probe=True)
+ self.assertIsInstance(bd, RemoteBzrDir)
+ self.assertFalse(bd.has_workingtree())
+ self.assertRaises(errors.NoWorkingTree, bd.open_workingtree)
+ self.assertFinished(client)
+
+ def test_present_with_workingtree(self):
+ client, transport = self.make_fake_client_and_transport()
+ client.add_expected_call(
+ 'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'yes'))
+ bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
+ _client=client, _force_probe=True)
+ self.assertIsInstance(bd, RemoteBzrDir)
+ self.assertTrue(bd.has_workingtree())
+ self.assertRaises(errors.NotLocalUrl, bd.open_workingtree)
+ self.assertFinished(client)
+
+ def test_backwards_compat(self):
+ client, transport = self.make_fake_client_and_transport()
+ client.add_expected_call(
+ 'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
+ client.add_expected_call(
+ 'BzrDir.open', ('quack/',), 'success', ('yes',))
+ bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
+ _client=client, _force_probe=True)
+ self.assertIsInstance(bd, RemoteBzrDir)
+ self.assertFinished(client)
+
+
class TestBzrDirOpenBranch(TestRemote):
def test_backwards_compat(self):
=== modified file 'bzrlib/tests/test_smart.py'
--- a/bzrlib/tests/test_smart.py 2009-09-04 00:49:55 +0000
+++ b/bzrlib/tests/test_smart.py 2009-09-24 05:31:23 +0000
@@ -52,7 +52,7 @@
from bzrlib.tests import (
split_suite_by_re,
)
-from bzrlib.transport import chroot, get_transport
+from bzrlib.transport import chroot, get_transport, local, memory
def load_tests(standard_tests, module, loader):
@@ -81,6 +81,7 @@
class TestCaseWithChrootedTransport(tests.TestCaseWithTransport):
def setUp(self):
+ self.vfs_transport_factory = memory.MemoryServer
tests.TestCaseWithTransport.setUp(self)
self._chroot_server = None
@@ -95,7 +96,7 @@
return t
-class TestCaseWithSmartMedium(tests.TestCaseWithTransport):
+class TestCaseWithSmartMedium(tests.TestCaseWithMemoryTransport):
def setUp(self):
super(TestCaseWithSmartMedium, self).setUp()
@@ -413,6 +414,73 @@
'False', 'False', 'False', '', '', '', '', 'False')
+class TestSmartServerRequestOpenBzrDir(tests.TestCaseWithMemoryTransport):
+
+ def test_no_directory(self):
+ backing = self.get_transport()
+ request = smart.bzrdir.SmartServerRequestOpenBzrDir(backing)
+ self.assertEqual(SmartServerResponse(('no', )),
+ request.execute('does-not-exist'))
+
+ def test_empty_directory(self):
+ backing = self.get_transport()
+ backing.mkdir('empty')
+ request = smart.bzrdir.SmartServerRequestOpenBzrDir(backing)
+ self.assertEqual(SmartServerResponse(('no', )),
+ request.execute('empty'))
+
+ def test_outside_root_client_path(self):
+ backing = self.get_transport()
+ request = smart.bzrdir.SmartServerRequestOpenBzrDir(backing,
+ root_client_path='root')
+ self.assertEqual(SmartServerResponse(('no', )),
+ request.execute('not-root'))
+
+
+class TestSmartServerRequestOpenBzrDir_2_1(tests.TestCaseWithMemoryTransport):
+
+ def test_no_directory(self):
+ backing = self.get_transport()
+ request = smart.bzrdir.SmartServerRequestOpenBzrDir_2_1(backing)
+ self.assertEqual(SmartServerResponse(('no', )),
+ request.execute('does-not-exist'))
+
+ def test_empty_directory(self):
+ backing = self.get_transport()
+ backing.mkdir('empty')
+ request = smart.bzrdir.SmartServerRequestOpenBzrDir_2_1(backing)
+ self.assertEqual(SmartServerResponse(('no', )),
+ request.execute('empty'))
+
+ def test_present_without_workingtree(self):
+ backing = self.get_transport()
+ request = smart.bzrdir.SmartServerRequestOpenBzrDir_2_1(backing)
+ self.make_bzrdir('.')
+ self.assertEqual(SmartServerResponse(('yes', 'no')),
+ request.execute(''))
+
+ def test_outside_root_client_path(self):
+ backing = self.get_transport()
+ request = smart.bzrdir.SmartServerRequestOpenBzrDir_2_1(backing,
+ root_client_path='root')
+ self.assertEqual(SmartServerResponse(('no',)),
+ request.execute('not-root'))
+
+
+class TestSmartServerRequestOpenBzrDir_2_1_disk(TestCaseWithChrootedTransport):
+
+ def test_present_with_workingtree(self):
+ self.vfs_transport_factory = local.LocalURLServer
+ backing = self.get_transport()
+ request = smart.bzrdir.SmartServerRequestOpenBzrDir_2_1(backing)
+ bd = self.make_bzrdir('.')
+ bd.create_repository()
+ bd.create_branch()
+ bd.create_workingtree()
+ self.assertEqual(SmartServerResponse(('yes', 'yes')),
+ request.execute(''))
+
+
class TestSmartServerRequestOpenBranch(TestCaseWithChrootedTransport):
def test_no_branch(self):
@@ -433,6 +501,7 @@
def test_branch_reference(self):
"""When there is a branch reference, the reference URL is returned."""
+ self.vfs_transport_factory = local.LocalURLServer
backing = self.get_transport()
request = smart.bzrdir.SmartServerRequestOpenBranch(backing)
branch = self.make_branch('branch')
@@ -463,6 +532,7 @@
def test_branch_reference(self):
"""When there is a branch reference, the reference URL is returned."""
+ self.vfs_transport_factory = local.LocalURLServer
backing = self.get_transport()
request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
branch = self.make_branch('branch')
=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py 2009-09-17 11:54:41 +0000
+++ b/bzrlib/tests/test_smart_transport.py 2009-09-24 05:31:23 +0000
@@ -997,7 +997,11 @@
# tests wanting a server. The latter should be updated to use
# self.vfs_transport_factory etc.
if not backing_transport:
- self.backing_transport = memory.MemoryTransport()
+ mem_server = memory.MemoryServer()
+ mem_server.setUp()
+ self.addCleanup(mem_server.tearDown)
+ self.permit_url(mem_server.get_url())
+ self.backing_transport = get_transport(mem_server.get_url())
else:
self.backing_transport = backing_transport
if readonly:
More information about the bazaar-commits
mailing list