Rev 4291: (robertc) 6 less round trips on smart push by using a verb to get in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Apr 15 04:10:41 BST 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4291
revision-id: pqm at pqm.ubuntu.com-20090415031036-ikndntbkaaj5zjya
parent: pqm at pqm.ubuntu.com-20090415013357-4e1qhuragbp9b8qu
parent: robertc at robertcollins.net-20090415020527-yyh3muljj0kftcjr
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2009-04-15 04:10:36 +0100
message:
(robertc) 6 less round trips on smart push by using a verb to get
bzrdir stacking policy and inheriting set_parent for
RemoteBranch. (Robert Collins)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/config.py config.py-20051011043216-070c74f4e9e338e8
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_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
bzrlib/tests/bzrdir_implementations/test_bzrdir.py test_bzrdir.py-20060131065642-0ebeca5e30e30866
bzrlib/tests/test_config.py testconfig.py-20051011041908-742d0c15d8d8c8eb
bzrlib/tests/test_remote.py test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
bzrlib/tests/test_smart.py test_smart.py-20061122024551-ol0l0o0oofsu9b3t-2
------------------------------------------------------------
revno: 4288.1.6
revision-id: robertc at robertcollins.net-20090415020527-yyh3muljj0kftcjr
parent: robertc at robertcollins.net-20090415000035-h0xsked0o73un7gi
committer: Robert Collins <robertc at robertcollins.net>
branch nick: push.roundtrips
timestamp: Wed 2009-04-15 12:05:27 +1000
message:
Fix bzrdir implementation tests to handle read only bzrdir configs.
modified:
bzrlib/tests/bzrdir_implementations/test_bzrdir.py test_bzrdir.py-20060131065642-0ebeca5e30e30866
------------------------------------------------------------
revno: 4288.1.5
revision-id: robertc at robertcollins.net-20090415000035-h0xsked0o73un7gi
parent: robertc at robertcollins.net-20090414071101-kmlsxria9ok4ldx5
parent: pqm at pqm.ubuntu.com-20090414031543-gqbs23oebd68p7h7
committer: Robert Collins <robertc at robertcollins.net>
branch nick: push.roundtrips
timestamp: Wed 2009-04-15 10:00:35 +1000
message:
Merge with .dev.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/branchbuilder.py branchbuilder.py-20070427022007-zlxpqz2lannhk6y8-1
bzrlib/fetch.py fetch.py-20050818234941-26fea6105696365d
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/repository.py rev_storage.py-20051111201905-119e9401e46257e3
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
bzrlib/tests/interrepository_implementations/__init__.py __init__.py-20060220054744-baf49a1f88f17b1a
bzrlib/tests/interrepository_implementations/test_fetch.py test_fetch.py-20080425213627-j60cjh782ufm83ry-1
------------------------------------------------------------
revno: 4288.1.4
revision-id: robertc at robertcollins.net-20090414071101-kmlsxria9ok4ldx5
parent: robertc at robertcollins.net-20090414065058-ca0aptbxp6zzkzat
committer: Robert Collins <robertc at robertcollins.net>
branch nick: push.roundtrips
timestamp: Tue 2009-04-14 17:11:01 +1000
message:
Remove the explicit set_parent method on RemoteBranch in favour of inheriting from Branch.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
------------------------------------------------------------
revno: 4288.1.3
revision-id: robertc at robertcollins.net-20090414065058-ca0aptbxp6zzkzat
parent: robertc at robertcollins.net-20090414043341-wirhw8dgd28nmcq1
committer: Robert Collins <robertc at robertcollins.net>
branch nick: push.roundtrips
timestamp: Tue 2009-04-14 16:50:58 +1000
message:
Fix BzrDirConfig tests.
modified:
bzrlib/tests/test_config.py testconfig.py-20051011041908-742d0c15d8d8c8eb
------------------------------------------------------------
revno: 4288.1.2
revision-id: robertc at robertcollins.net-20090414043341-wirhw8dgd28nmcq1
parent: robertc at robertcollins.net-20090414023507-935t0u7ab2rt7kfk
committer: Robert Collins <robertc at robertcollins.net>
branch nick: push.roundtrips
timestamp: Tue 2009-04-14 14:33:41 +1000
message:
Create a server verb for doing BzrDir.get_config()
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/config.py config.py-20051011043216-070c74f4e9e338e8
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_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
bzrlib/tests/test_remote.py test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
bzrlib/tests/test_smart.py test_smart.py-20061122024551-ol0l0o0oofsu9b3t-2
------------------------------------------------------------
revno: 4288.1.1
revision-id: robertc at robertcollins.net-20090414023507-935t0u7ab2rt7kfk
parent: pqm at pqm.ubuntu.com-20090413175307-kzfbzfxgscia4sto
committer: Robert Collins <robertc at robertcollins.net>
branch nick: push.roundtrips
timestamp: Tue 2009-04-14 12:35:07 +1000
message:
Add support for a RemoteBzrDirConfig to support optimising push operations which need to look for default stacking locations.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/config.py config.py-20051011043216-070c74f4e9e338e8
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
bzrlib/tests/test_remote.py test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
=== modified file 'NEWS'
--- a/NEWS 2009-04-15 01:33:57 +0000
+++ b/NEWS 2009-04-15 03:10:36 +0000
@@ -50,6 +50,16 @@
Internals
*********
+* ``bzrlib.branch.Branch.set_parent`` is now present on the base branch
+ class and will call ``_set_parent_location`` after doing unicode
+ encoding. (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
+ ``BzrDir.get-config_file`` to reduce roundtrips for getting BzrDir
+ configuration. (Robert Collins)
+
* ``bzrlib.tests.ExtendedTestResult`` has new methods ``startTests``
called before the first test is started, ``done`` called after the last
test completes, and a new parameter ``strict``. (Robert Collins)
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2009-04-04 02:50:01 +0000
+++ b/bzrlib/branch.py 2009-04-14 07:11:01 +0000
@@ -590,6 +590,24 @@
def set_revision_history(self, rev_history):
raise NotImplementedError(self.set_revision_history)
+ @needs_write_lock
+ def set_parent(self, url):
+ """See Branch.set_parent."""
+ # TODO: Maybe delete old location files?
+ # URLs should never be unicode, even on the local fs,
+ # FIXUP this and get_parent in a future branch format bump:
+ # read and rewrite the file. RBC 20060125
+ if url is not None:
+ if isinstance(url, unicode):
+ try:
+ url = url.encode('ascii')
+ except UnicodeEncodeError:
+ raise errors.InvalidURL(url,
+ "Urls must be 7-bit ascii, "
+ "use bzrlib.urlutils.escape")
+ url = urlutils.relative_url(self.base, url)
+ self._set_parent_location(url)
+
def set_stacked_on_url(self, url):
"""Set the URL this branch is stacked against.
@@ -944,9 +962,6 @@
raise errors.HookFailed(
'pre_change_branch_tip', hook_name, exc_info)
- def set_parent(self, url):
- raise NotImplementedError(self.set_parent)
-
@needs_write_lock
def update(self):
"""Synchronise this branch with the master branch if any.
@@ -2194,24 +2209,6 @@
'push_location', location,
store=_mod_config.STORE_LOCATION_NORECURSE)
- @needs_write_lock
- def set_parent(self, url):
- """See Branch.set_parent."""
- # TODO: Maybe delete old location files?
- # URLs should never be unicode, even on the local fs,
- # FIXUP this and get_parent in a future branch format bump:
- # read and rewrite the file. RBC 20060125
- if url is not None:
- if isinstance(url, unicode):
- try:
- url = url.encode('ascii')
- except UnicodeEncodeError:
- raise errors.InvalidURL(url,
- "Urls must be 7-bit ascii, "
- "use bzrlib.urlutils.escape")
- url = urlutils.relative_url(self.base, url)
- self._set_parent_location(url)
-
def _set_parent_location(self, url):
if url is None:
self._transport.delete('parent')
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py 2009-04-13 17:53:07 +0000
+++ b/bzrlib/bzrdir.py 2009-04-14 02:35:07 +0000
@@ -408,11 +408,10 @@
stack_on_pwd = None
config = found_bzrdir.get_config()
stop = False
- if config is not None:
- stack_on = config.get_default_stack_on()
- if stack_on is not None:
- stack_on_pwd = found_bzrdir.root_transport.base
- stop = True
+ stack_on = config.get_default_stack_on()
+ if stack_on is not None:
+ stack_on_pwd = found_bzrdir.root_transport.base
+ stop = True
# does it have a repository ?
try:
repository = found_bzrdir.open_repository()
@@ -744,9 +743,12 @@
raise NotImplementedError(self.get_workingtree_transport)
def get_config(self):
- if getattr(self, '_get_config', None) is None:
- return None
- return self._get_config()
+ """Get configuration for this BzrDir."""
+ return config.BzrDirConfig(self)
+
+ def _get_config(self):
+ """By default, no configuration is available."""
+ return None
def __init__(self, _transport, _format):
"""Initialize a Bzr control dir object.
@@ -1696,8 +1698,7 @@
return format.open(self, _found=True)
def _get_config(self):
- return config.BzrDirConfig(self.transport)
-
+ return config.TransportConfig(self.transport, 'control.conf')
class BzrDirFormat(object):
"""An encapsulation of the initialization and open routines for a format.
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2009-04-11 13:01:19 +0000
+++ b/bzrlib/config.py 2009-04-14 04:33:41 +0000
@@ -1346,8 +1346,9 @@
class BzrDirConfig(object):
- def __init__(self, transport):
- self._config = TransportConfig(transport, 'control.conf')
+ def __init__(self, bzrdir):
+ self._bzrdir = bzrdir
+ self._config = bzrdir._get_config()
def set_default_stack_on(self, value):
"""Set the default stacking location.
@@ -1357,6 +1358,8 @@
This policy affects all branches contained by this bzrdir, except for
those under repositories.
"""
+ if self._config is None:
+ raise errors.BzrError("Cannot set configuration in %s" % self._bzrdir)
if value is None:
self._config.set_option('', 'default_stack_on')
else:
@@ -1370,6 +1373,8 @@
This policy affects all branches contained by this bzrdir, except for
those under repositories.
"""
+ if self._config is None:
+ return None
value = self._config.get_option('default_stack_on')
if value == '':
value = None
@@ -1420,12 +1425,14 @@
configobj.setdefault(section, {})[name] = value
self._set_configobj(configobj)
+ def _get_config_file(self):
+ try:
+ return self._transport.get(self._filename)
+ except errors.NoSuchFile:
+ return StringIO()
+
def _get_configobj(self):
- try:
- return ConfigObj(self._transport.get(self._filename),
- encoding='utf-8')
- except errors.NoSuchFile:
- return ConfigObj(encoding='utf-8')
+ return ConfigObj(self._get_config_file(), encoding='utf-8')
def _set_configobj(self, configobj):
out_file = StringIO()
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2009-04-14 03:15:43 +0000
+++ b/bzrlib/remote.py 2009-04-15 00:00:35 +0000
@@ -392,9 +392,8 @@
return self._real_bzrdir.clone(url, revision_id=revision_id,
force_new_repo=force_new_repo, preserve_stacking=preserve_stacking)
- def get_config(self):
- self._ensure_real()
- return self._real_bzrdir.get_config()
+ def _get_config(self):
+ return RemoteBzrDirConfig(self)
class RemoteRepositoryFormat(repository.RepositoryFormat):
@@ -2301,17 +2300,9 @@
self._ensure_real()
return self._real_branch._get_parent_location()
- def set_parent(self, url):
- self._ensure_real()
- return self._real_branch.set_parent(url)
-
def _set_parent_location(self, url):
- # Used by tests, to poke bad urls into branch configurations
- if url is None:
- self.set_parent(url)
- else:
- self._ensure_real()
- return self._real_branch._set_parent_location(url)
+ self._ensure_real()
+ return self._real_branch._set_parent_location(url)
@needs_write_lock
def pull(self, source, overwrite=False, stop_revision=None,
@@ -2385,17 +2376,14 @@
return self._real_branch.set_push_location(location)
-class RemoteBranchConfig(object):
- """A Config that reads from a smart branch and writes via smart methods.
+class RemoteConfig(object):
+ """A Config that reads and writes from smart verbs.
It is a low-level object that considers config data to be name/value pairs
that may be associated with a section. Assigning meaning to the these
values is done at higher levels like bzrlib.config.TreeConfig.
"""
- def __init__(self, branch):
- self._branch = branch
-
def get_option(self, name, section=None, default=None):
"""Return the value associated with a named option.
@@ -2404,24 +2392,37 @@
:param default: The value to return if the value is not set
:return: The value or default value
"""
- configobj = self._get_configobj()
- if section is None:
- section_obj = configobj
- else:
- try:
- section_obj = configobj[section]
- except KeyError:
- return default
- return section_obj.get(name, default)
+ try:
+ configobj = self._get_configobj()
+ if section is None:
+ section_obj = configobj
+ else:
+ try:
+ section_obj = configobj[section]
+ except KeyError:
+ return default
+ return section_obj.get(name, default)
+ except errors.UnknownSmartMethod:
+ return self._vfs_get_option(name, section, default)
+
+ def _response_to_configobj(self, response):
+ if len(response[0]) and response[0][0] != 'ok':
+ raise errors.UnexpectedSmartServerResponse(response)
+ lines = response[1].read_body_bytes().splitlines()
+ return config.ConfigObj(lines, encoding='utf-8')
+
+
+class RemoteBranchConfig(RemoteConfig):
+ """A RemoteConfig for Branches."""
+
+ def __init__(self, branch):
+ self._branch = branch
def _get_configobj(self):
path = self._branch._remote_path()
response = self._branch._client.call_expecting_body(
'Branch.get_config_file', path)
- if response[0][0] != 'ok':
- raise UnexpectedSmartServerResponse(response)
- lines = response[1].read_body_bytes().splitlines()
- return config.ConfigObj(lines, encoding='utf-8')
+ return self._response_to_configobj(response)
def set_option(self, value, name, section=None):
"""Set the value associated with a named option.
@@ -2444,10 +2445,49 @@
if response != ():
raise errors.UnexpectedSmartServerResponse(response)
+ def _real_object(self):
+ self._branch._ensure_real()
+ return self._branch._real_branch
+
def _vfs_set_option(self, value, name, section=None):
- self._branch._ensure_real()
- return self._branch._real_branch._get_config().set_option(
- value, name, section)
+ return self._real_object()._get_config().set_option(
+ value, name, section)
+
+
+class RemoteBzrDirConfig(RemoteConfig):
+ """A RemoteConfig for BzrDirs."""
+
+ def __init__(self, bzrdir):
+ self._bzrdir = bzrdir
+
+ def _get_configobj(self):
+ medium = self._bzrdir._client._medium
+ verb = 'BzrDir.get_config_file'
+ if medium._is_remote_before((1, 15)):
+ raise errors.UnknownSmartMethod(verb)
+ path = self._bzrdir._path_for_remote_call(self._bzrdir._client)
+ response = self._bzrdir._call_expecting_body(
+ verb, path)
+ return self._response_to_configobj(response)
+
+ def _vfs_get_option(self, name, section, default):
+ return self._real_object()._get_config().get_option(
+ name, section, default)
+
+ def set_option(self, value, name, section=None):
+ """Set the value associated with a named option.
+
+ :param value: The value to set
+ :param name: The name of the value to set
+ :param section: The section the option is in (if any)
+ """
+ return self._real_object()._get_config().set_option(
+ value, name, section)
+
+ def _real_object(self):
+ self._bzrdir._ensure_real()
+ return self._bzrdir._real_bzrdir
+
def _extract_tar(tar, to_dir):
=== modified file 'bzrlib/smart/bzrdir.py'
--- a/bzrlib/smart/bzrdir.py 2009-04-04 02:50:01 +0000
+++ b/bzrlib/smart/bzrdir.py 2009-04-14 04:33:41 +0000
@@ -297,6 +297,21 @@
return FailedSmartServerResponse(('norepository', ))
+class SmartServerBzrDirRequestConfigFile(SmartServerRequestBzrDir):
+
+ def do_bzrdir_request(self):
+ """Get the configuration bytes for a config file in bzrdir.
+
+ The body is not utf8 decoded - it is the literal bytestream from disk.
+ """
+ config = self._bzrdir._get_config()
+ if config is None:
+ content = ''
+ else:
+ content = config._get_config_file().read()
+ return SuccessfulSmartServerResponse((), content)
+
+
class SmartServerRequestInitializeBzrDir(SmartServerRequest):
def do(self, path):
=== modified file 'bzrlib/smart/request.py'
--- a/bzrlib/smart/request.py 2009-04-02 05:22:42 +0000
+++ b/bzrlib/smart/request.py 2009-04-14 04:33:41 +0000
@@ -481,9 +481,14 @@
'BzrDir.find_repositoryV3', 'bzrlib.smart.bzrdir',
'SmartServerRequestFindRepositoryV3')
request_handlers.register_lazy(
+ 'BzrDir.get_config_file', 'bzrlib.smart.bzrdir',
+ 'SmartServerBzrDirRequestConfigFile')
+request_handlers.register_lazy(
'BzrDirFormat.initialize', 'bzrlib.smart.bzrdir',
'SmartServerRequestInitializeBzrDir')
request_handlers.register_lazy(
+ 'BzrDir.open', 'bzrlib.smart.bzrdir', 'SmartServerRequestOpenBzrDir')
+request_handlers.register_lazy(
'BzrDir.open_branch', 'bzrlib.smart.bzrdir',
'SmartServerRequestOpenBranch')
request_handlers.register_lazy(
@@ -553,5 +558,3 @@
'stat', 'bzrlib.smart.vfs', 'StatRequest')
request_handlers.register_lazy(
'Transport.is_readonly', 'bzrlib.smart.request', 'SmartServerIsReadonly')
-request_handlers.register_lazy(
- 'BzrDir.open', 'bzrlib.smart.bzrdir', 'SmartServerRequestOpenBzrDir')
=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- a/bzrlib/tests/blackbox/test_branch.py 2009-04-08 03:34:31 +0000
+++ b/bzrlib/tests/blackbox/test_branch.py 2009-04-14 07:11:01 +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(53, self.hpss_calls)
+ self.assertLength(47, 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-09 00:44:52 +0000
+++ b/bzrlib/tests/blackbox/test_push.py 2009-04-15 00:00:35 +0000
@@ -201,7 +201,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(20, self.hpss_calls)
+ self.assertLength(19, self.hpss_calls)
def test_push_smart_stacked_streaming_acceptance(self):
self.setup_smart_server_with_call_log()
@@ -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(43, self.hpss_calls)
+ self.assertLength(37, self.hpss_calls)
remote = Branch.open('public')
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
=== modified file 'bzrlib/tests/bzrdir_implementations/test_bzrdir.py'
--- a/bzrlib/tests/bzrdir_implementations/test_bzrdir.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/bzrdir_implementations/test_bzrdir.py 2009-04-15 02:05:27 +0000
@@ -1712,13 +1712,17 @@
def test_get_config(self):
my_dir = self.make_bzrdir('.')
config = my_dir.get_config()
- if config is None:
- self.assertFalse(
- isinstance(my_dir, (bzrdir.BzrDirMeta1, RemoteBzrDir)),
- "%r should support configs" % my_dir)
- raise TestNotApplicable(
- 'This BzrDir format does not support configs.')
- config.set_default_stack_on('http://example.com')
+ try:
+ config.set_default_stack_on('http://example.com')
+ except errors.BzrError, e:
+ if 'Cannot set config' in str(e):
+ self.assertFalse(
+ isinstance(my_dir, (bzrdir.BzrDirMeta1, RemoteBzrDir)),
+ "%r should support configs" % my_dir)
+ raise TestNotApplicable(
+ 'This BzrDir format does not support configs.')
+ else:
+ raise
self.assertEqual('http://example.com', config.get_default_stack_on())
my_dir2 = bzrdir.BzrDir.open(self.get_url('.'))
config2 = my_dir2.get_config()
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2009-04-11 13:01:19 +0000
+++ b/bzrlib/tests/test_config.py 2009-04-14 06:50:58 +0000
@@ -1211,7 +1211,7 @@
def test_set_unset_default_stack_on(self):
my_dir = self.make_bzrdir('.')
- bzrdir_config = config.BzrDirConfig(my_dir.transport)
+ bzrdir_config = config.BzrDirConfig(my_dir)
self.assertIs(None, bzrdir_config.get_default_stack_on())
bzrdir_config.set_default_stack_on('Foo')
self.assertEqual('Foo', bzrdir_config._config.get_option(
=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py 2009-04-10 19:37:20 +0000
+++ b/bzrlib/tests/test_remote.py 2009-04-14 04:33:41 +0000
@@ -770,7 +770,15 @@
return OldSmartClient()
-class RemoteBranchTestCase(TestRemote):
+class RemoteBzrDirTestCase(TestRemote):
+
+ def make_remote_bzrdir(self, transport, client):
+ """Make a RemotebzrDir using 'client' as the _client."""
+ return RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
+ _client=client)
+
+
+class RemoteBranchTestCase(RemoteBzrDirTestCase):
def make_remote_branch(self, transport, client):
"""Make a RemoteBranch using 'client' as its _SmartClient.
@@ -781,8 +789,7 @@
# we do not want bzrdir to make any remote calls, so use False as its
# _client. If it tries to make a remote call, this will fail
# immediately.
- bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
- _client=False)
+ bzrdir = self.make_remote_bzrdir(transport, False)
repo = RemoteRepository(bzrdir, None, _client=client)
branch_format = self.get_branch_format()
format = RemoteBranchFormat(network_name=branch_format.network_name())
@@ -1419,6 +1426,38 @@
client.finished_test()
+class TestBzrDirGetSetConfig(RemoteBzrDirTestCase):
+
+ def test__get_config(self):
+ client = FakeClient()
+ client.add_success_response_with_body('default_stack_on = /\n', 'ok')
+ transport = MemoryTransport()
+ bzrdir = self.make_remote_bzrdir(transport, client)
+ config = bzrdir.get_config()
+ self.assertEqual('/', config.get_default_stack_on())
+ self.assertEqual(
+ [('call_expecting_body', 'BzrDir.get_config_file', ('memory:///',))],
+ client._calls)
+
+ def test_set_option_uses_vfs(self):
+ self.setup_smart_server_with_call_log()
+ bzrdir = self.make_bzrdir('.')
+ self.reset_smart_call_log()
+ config = bzrdir.get_config()
+ config.set_default_stack_on('/')
+ self.assertLength(3, self.hpss_calls)
+
+ def test_backwards_compat_get_option(self):
+ self.setup_smart_server_with_call_log()
+ bzrdir = self.make_bzrdir('.')
+ verb = 'BzrDir.get_config_file'
+ self.disable_verb(verb)
+ self.reset_smart_call_log()
+ self.assertEqual(None,
+ bzrdir._get_config().get_option('default_stack_on'))
+ self.assertLength(3, self.hpss_calls)
+
+
class TestTransportIsReadonly(tests.TestCase):
def test_true(self):
@@ -2410,7 +2449,7 @@
try:
# it should have an appropriate fallback repository, which should also
# be a RemoteRepository
- self.assertEquals(len(remote_repo._fallback_repositories), 1)
+ self.assertLength(1, remote_repo._fallback_repositories)
self.assertIsInstance(remote_repo._fallback_repositories[0],
RemoteRepository)
# and it has the revision committed to the underlying repository;
=== modified file 'bzrlib/tests/test_smart.py'
--- a/bzrlib/tests/test_smart.py 2009-04-02 05:22:42 +0000
+++ b/bzrlib/tests/test_smart.py 2009-04-14 04:33:41 +0000
@@ -296,6 +296,29 @@
self.assertEqual(result, request.execute(''))
+class TestSmartServerBzrDirRequestGetConfigFile(
+ tests.TestCaseWithMemoryTransport):
+ """Tests for BzrDir.get_config_file."""
+
+ def test_present(self):
+ backing = self.get_transport()
+ dir = self.make_bzrdir('.')
+ dir.get_config().set_default_stack_on("/")
+ local_result = dir._get_config()._get_config_file().read()
+ request_class = smart_dir.SmartServerBzrDirRequestConfigFile
+ request = request_class(backing)
+ expected = SuccessfulSmartServerResponse((), local_result)
+ self.assertEqual(expected, request.execute(''))
+
+ def test_missing(self):
+ backing = self.get_transport()
+ dir = self.make_bzrdir('.')
+ request_class = smart_dir.SmartServerBzrDirRequestConfigFile
+ request = request_class(backing)
+ expected = SuccessfulSmartServerResponse((), '')
+ self.assertEqual(expected, request.execute(''))
+
+
class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithMemoryTransport):
def test_empty_dir(self):
@@ -1386,93 +1409,68 @@
for key, item in smart.request.request_handlers.iteritems():
pass
+ def assertHandlerEqual(self, verb, handler):
+ self.assertEqual(smart.request.request_handlers.get(verb), handler)
+
def test_registered_methods(self):
"""Test that known methods are registered to the correct object."""
- self.assertEqual(
- smart.request.request_handlers.get('Branch.get_config_file'),
+ self.assertHandlerEqual('Branch.get_config_file',
smart.branch.SmartServerBranchGetConfigFile)
- self.assertEqual(
- smart.request.request_handlers.get('Branch.get_parent'),
+ self.assertHandlerEqual('Branch.get_parent',
smart.branch.SmartServerBranchGetParent)
- self.assertEqual(
- smart.request.request_handlers.get('Branch.get_tags_bytes'),
+ self.assertHandlerEqual('Branch.get_tags_bytes',
smart.branch.SmartServerBranchGetTagsBytes)
- self.assertEqual(
- smart.request.request_handlers.get('Branch.lock_write'),
+ self.assertHandlerEqual('Branch.lock_write',
smart.branch.SmartServerBranchRequestLockWrite)
- self.assertEqual(
- smart.request.request_handlers.get('Branch.last_revision_info'),
+ self.assertHandlerEqual('Branch.last_revision_info',
smart.branch.SmartServerBranchRequestLastRevisionInfo)
- self.assertEqual(
- smart.request.request_handlers.get('Branch.revision_history'),
+ self.assertHandlerEqual('Branch.revision_history',
smart.branch.SmartServerRequestRevisionHistory)
- self.assertEqual(
- smart.request.request_handlers.get('Branch.set_config_option'),
+ self.assertHandlerEqual('Branch.set_config_option',
smart.branch.SmartServerBranchRequestSetConfigOption)
- self.assertEqual(
- smart.request.request_handlers.get('Branch.set_last_revision'),
+ self.assertHandlerEqual('Branch.set_last_revision',
smart.branch.SmartServerBranchRequestSetLastRevision)
- self.assertEqual(
- smart.request.request_handlers.get('Branch.set_last_revision_info'),
+ self.assertHandlerEqual('Branch.set_last_revision_info',
smart.branch.SmartServerBranchRequestSetLastRevisionInfo)
- self.assertEqual(
- smart.request.request_handlers.get('Branch.unlock'),
+ self.assertHandlerEqual('Branch.unlock',
smart.branch.SmartServerBranchRequestUnlock)
- self.assertEqual(
- smart.request.request_handlers.get('BzrDir.find_repository'),
+ self.assertHandlerEqual('BzrDir.find_repository',
smart.bzrdir.SmartServerRequestFindRepositoryV1)
- self.assertEqual(
- smart.request.request_handlers.get('BzrDir.find_repositoryV2'),
+ self.assertHandlerEqual('BzrDir.find_repositoryV2',
smart.bzrdir.SmartServerRequestFindRepositoryV2)
- self.assertEqual(
- smart.request.request_handlers.get('BzrDirFormat.initialize'),
+ self.assertHandlerEqual('BzrDirFormat.initialize',
smart.bzrdir.SmartServerRequestInitializeBzrDir)
- self.assertEqual(
- smart.request.request_handlers.get('BzrDir.cloning_metadir'),
+ self.assertHandlerEqual('BzrDir.cloning_metadir',
smart.bzrdir.SmartServerBzrDirRequestCloningMetaDir)
- self.assertEqual(
- smart.request.request_handlers.get('BzrDir.open_branch'),
+ self.assertHandlerEqual('BzrDir.get_config_file',
+ smart.bzrdir.SmartServerBzrDirRequestConfigFile)
+ self.assertHandlerEqual('BzrDir.open_branch',
smart.bzrdir.SmartServerRequestOpenBranch)
- self.assertEqual(
- smart.request.request_handlers.get('BzrDir.open_branchV2'),
+ self.assertHandlerEqual('BzrDir.open_branchV2',
smart.bzrdir.SmartServerRequestOpenBranchV2)
- self.assertEqual(
- smart.request.request_handlers.get('PackRepository.autopack'),
+ self.assertHandlerEqual('PackRepository.autopack',
smart.packrepository.SmartServerPackRepositoryAutopack)
- self.assertEqual(
- smart.request.request_handlers.get('Repository.gather_stats'),
+ self.assertHandlerEqual('Repository.gather_stats',
smart.repository.SmartServerRepositoryGatherStats)
- self.assertEqual(
- smart.request.request_handlers.get('Repository.get_parent_map'),
+ self.assertHandlerEqual('Repository.get_parent_map',
smart.repository.SmartServerRepositoryGetParentMap)
- self.assertEqual(
- smart.request.request_handlers.get(
- 'Repository.get_revision_graph'),
+ self.assertHandlerEqual('Repository.get_revision_graph',
smart.repository.SmartServerRepositoryGetRevisionGraph)
- self.assertEqual(
- smart.request.request_handlers.get('Repository.get_stream'),
+ self.assertHandlerEqual('Repository.get_stream',
smart.repository.SmartServerRepositoryGetStream)
- self.assertEqual(
- smart.request.request_handlers.get('Repository.has_revision'),
+ self.assertHandlerEqual('Repository.has_revision',
smart.repository.SmartServerRequestHasRevision)
- self.assertEqual(
- smart.request.request_handlers.get('Repository.insert_stream'),
+ self.assertHandlerEqual('Repository.insert_stream',
smart.repository.SmartServerRepositoryInsertStream)
- self.assertEqual(
- smart.request.request_handlers.get('Repository.insert_stream_locked'),
+ self.assertHandlerEqual('Repository.insert_stream_locked',
smart.repository.SmartServerRepositoryInsertStreamLocked)
- self.assertEqual(
- smart.request.request_handlers.get('Repository.is_shared'),
+ self.assertHandlerEqual('Repository.is_shared',
smart.repository.SmartServerRepositoryIsShared)
- self.assertEqual(
- smart.request.request_handlers.get('Repository.lock_write'),
+ self.assertHandlerEqual('Repository.lock_write',
smart.repository.SmartServerRepositoryLockWrite)
- self.assertEqual(
- smart.request.request_handlers.get('Repository.tarball'),
+ self.assertHandlerEqual('Repository.tarball',
smart.repository.SmartServerRepositoryTarball)
- self.assertEqual(
- smart.request.request_handlers.get('Repository.unlock'),
+ self.assertHandlerEqual('Repository.unlock',
smart.repository.SmartServerRepositoryUnlock)
- self.assertEqual(
- smart.request.request_handlers.get('Transport.is_readonly'),
+ self.assertHandlerEqual('Transport.is_readonly',
smart.request.SmartServerIsReadonly)
More information about the bazaar-commits
mailing list