Rev 5534: Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate. in file:///home/vila/src/bzr/experimental/config/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon Nov 8 16:22:55 GMT 2010
At file:///home/vila/src/bzr/experimental/config/
------------------------------------------------------------
revno: 5534
revision-id: v.ladeuil+lp at free.fr-20101108162255-bhrd40znoldmip1n
parent: pqm at pqm.ubuntu.com-20101108134551-sxvk77ehmegkrwmm
fixes bug(s): https://launchpad.net/bugs/671050
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 671050-config-policy
timestamp: Mon 2010-11-08 17:22:55 +0100
message:
Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2010-11-05 11:13:05 +0000
+++ b/bzrlib/config.py 2010-11-08 16:22:55 +0000
@@ -1864,8 +1864,10 @@
break
for (oname, value, section, conf_id) in c._get_options():
if name == oname:
- # Display only the first value and exit
- self.outf.write('%s\n' % (value))
+ # Display only the first value and exit (We need to use
+ # get_user_option to take policies into account and we need
+ # to make sure the option exists too :-/)
+ self.outf.write('%s\n' % c.get_user_option(name))
displayed = True
break
if not displayed:
@@ -1877,6 +1879,7 @@
# avoid the delay introduced by the lazy regexp.
name._compile_and_collapse()
cur_conf_id = None
+ cur_section = None
for c in self._get_configs(directory, scope):
for (oname, value, section, conf_id) in c._get_options():
if name.search(oname):
@@ -1884,6 +1887,13 @@
# Explain where the options are defined
self.outf.write('%s:\n' % (conf_id,))
cur_conf_id = conf_id
+ cur_section = None
+ if (section not in (None, 'DEFAULT')
+ and cur_section != section):
+ # Display the section if it's not the default (or only)
+ # one.
+ self.outf.write(' [%s]\n' % section)
+ cur_section = section
self.outf.write(' %s = %s\n' % (oname, value))
def _set_config_option(self, name, value, directory, scope):
=== modified file 'bzrlib/tests/blackbox/test_config.py'
--- a/bzrlib/tests/blackbox/test_config.py 2010-11-05 11:13:05 +0000
+++ b/bzrlib/tests/blackbox/test_config.py 2010-11-08 16:22:55 +0000
@@ -88,6 +88,7 @@
script.run_script(self, '''\
$ bzr config -d tree
locations:
+ [.../tree]
hello = world
branch:
hello = you
@@ -102,6 +103,33 @@
hello = world
''')
+class TestConfigDisplayWithPolicy(tests.TestCaseWithTransport):
+
+ def test_location_with_policy(self):
+ # LocationConfig is the only one dealing with policies so far.
+ self.make_branch_and_tree('tree')
+ config_text = """\
+[%(dir)s]
+url = dir
+url:policy = appendpath
+[%(dir)s/tree]
+url = tree
+""" % {'dir': self.test_dir}
+ # We don't use the config directly so we save it to disk
+ config.LocationConfig.from_string(config_text, 'tree', save=True)
+ # policies are displayed with their options since they are part of
+ # their definition, likewise the path is not appended, we are just
+ # presenting the relevant portions of the config files
+ script.run_script(self, '''\
+ $ bzr config -d tree --all url
+ locations:
+ [.../work/tree]
+ url = tree
+ [.../work]
+ url = dir
+ url:policy = appendpath
+ ''')
+
class TestConfigActive(tests.TestCaseWithTransport):
@@ -162,6 +190,7 @@
$ bzr config -d tree --scope locations hello=world
$ bzr config -d tree --all hello
locations:
+ [.../work/tree]
hello = world
''')
@@ -197,6 +226,7 @@
$ bzr config --scope bazaar --remove file
$ bzr config -d tree --all file
locations:
+ [.../work/tree]
file = locations
branch:
file = branch
@@ -207,6 +237,7 @@
$ bzr config -d tree --scope bazaar --remove file
$ bzr config -d tree --all file
locations:
+ [.../work/tree]
file = locations
branch:
file = branch
@@ -243,6 +274,7 @@
$ bzr config -d tree --scope branch --remove file
$ bzr config -d tree --all file
locations:
+ [.../work/tree]
file = locations
bazaar:
file = bazaar
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2010-10-29 16:53:22 +0000
+++ b/bzrlib/tests/test_config.py 2010-11-08 16:22:55 +0000
@@ -1016,6 +1016,21 @@
'http://www.example.com', 'appendpath_option'),
config.POLICY_APPENDPATH)
+ def test__get_options_with_policy(self):
+ self.get_branch_config('/dir/subdir',
+ location_config="""\
+[/dir]
+other_url = /other-dir
+other_url:policy = appendpath
+[/dir/subdir]
+other_url = /other-subdir
+""")
+ self.assertEqual(
+ [(u'other_url', u'/other-subdir', u'/dir/subdir', 'locations'),
+ (u'other_url', u'/other-dir', u'/dir', 'locations'),
+ (u'other_url:policy', u'appendpath', u'/dir', 'locations')],
+ list(self.my_location_config._get_options()))
+
def test_location_without_username(self):
self.get_branch_config('http://www.example.com/ignoreparent')
self.assertEqual(u'Erik B\u00e5gfors <erik at bagfors.nu>',
@@ -1157,15 +1172,18 @@
self.assertEqual('bzrlib.tests.test_config.post_commit',
self.my_config.post_commit())
- def get_branch_config(self, location, global_config=None):
+ def get_branch_config(self, location, global_config=None,
+ location_config=None):
my_branch = FakeBranch(location)
if global_config is None:
global_config = sample_config_text
+ if location_config is None:
+ location_config = sample_branches_text
my_global_config = config.GlobalConfig.from_string(global_config,
save=True)
my_location_config = config.LocationConfig.from_string(
- sample_branches_text, my_branch.base, save=True)
+ location_config, my_branch.base, save=True)
my_config = config.BranchConfig(my_branch)
self.my_config = my_config
self.my_location_config = my_config._get_location_config()
=== modified file 'doc/en/release-notes/bzr-2.3.txt'
--- a/doc/en/release-notes/bzr-2.3.txt 2010-11-08 11:01:20 +0000
+++ b/doc/en/release-notes/bzr-2.3.txt 2010-11-08 16:22:55 +0000
@@ -37,6 +37,10 @@
.. Fixes for situations where bzr would previously crash or give incorrect
or undesirable results.
+* ``bzr config`` will now respect option policies when displaying the value
+ and display the definition sections when appropriate.
+ (Vincent Ladeuil, #671050)
+
* ``bzr resolve --take-other <file>`` will not crash anymore if ``<file>``
is involved in a text conflict (but the conflict is still not
resolved). (Vincent Ladeuil, #646961)
More information about the bazaar-commits
mailing list