Merge lp:~vila/bzr/expand-default-true into lp:bzr

Proposed by Vincent Ladeuil
Status: Merged
Approved by: Martin Packman
Approved revision: no longer in the source branch.
Merged at revision: 6488
Proposed branch: lp:~vila/bzr/expand-default-true
Merge into: lp:bzr
Diff against target: 174 lines (+8/-89)
4 files modified
bzrlib/config.py (+3/-28)
bzrlib/tests/__init__.py (+0/-4)
bzrlib/tests/test_config.py (+0/-57)
doc/en/release-notes/bzr-2.6.txt (+5/-0)
To merge this branch: bzr merge lp:~vila/bzr/expand-default-true
Reviewer Review Type Date Requested Status
Martin Packman (community) Approve
Review via email: mp+93367@code.launchpad.net

Commit message

This turns config option expansion on by default.

Description of the change

This turns config option expansion on by default.

This has been introduced as an opt-in feature long ago (well before we
started migrating options) and I've opt-in myself since day one.

There has been no negative feedback on this so I'd like to get rid of the
option all together since I've since never encountered a valid use case
where a refernce ({option}) needs to not be expanded.

It's trivially true for most of the options used inside brzlib *except* for
templates which obviously want to delay the option expansion.

Cleaning up the code revealed a single case where expand=False was required
(mergetools) and this was indeed a template.

I'm targetting trunk to ensure this doesn't break use cases I'm not aware of, but we may want to backport to 2.5 if nothing bad happens.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Seems reasonable for 2.6 where any remaining issues should get shaken out. The qbzr external merge should be sharing the same config now, I'm not sure what other plugins might do their own templating.

review: Approve
Revision history for this message
Vincent Ladeuil (vila) wrote :

sent to pqm by email

Revision history for this message
Vincent Ladeuil (vila) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/config.py'
2--- bzrlib/config.py 2012-03-06 19:49:19 +0000
3+++ bzrlib/config.py 2012-03-08 18:36:26 +0000
4@@ -195,27 +195,6 @@
5 return self[section][name]
6
7
8-# FIXME: Until we can guarantee that each config file is loaded once and
9-# only once for a given bzrlib session, we don't want to re-read the file every
10-# time we query for an option so we cache the value (bad ! watch out for tests
11-# needing to restore the proper value). -- vila 20110219
12-_expand_default_value = None
13-def _get_expand_default_value():
14- global _expand_default_value
15- if _expand_default_value is not None:
16- return _expand_default_value
17- conf = GlobalConfig()
18- # Note that we must not use None for the expand value below or we'll run
19- # into infinite recursion. Using False really would be quite silly ;)
20- expand = conf.get_user_option_as_bool('bzr.config.expand', expand=True)
21- if expand is None:
22- # This is an opt-in feature, you *really* need to clearly say you want
23- # to activate it !
24- expand = False
25- _expand_default_value = expand
26- return expand
27-
28-
29 class Config(object):
30 """A configuration policy - what username, editor, gpg needs etc."""
31
32@@ -373,7 +352,7 @@
33 """Template method to provide a user option."""
34 return None
35
36- def get_user_option(self, option_name, expand=None):
37+ def get_user_option(self, option_name, expand=True):
38 """Get a generic option - no special process, no default.
39
40 :param option_name: The queried option.
41@@ -382,8 +361,6 @@
42
43 :returns: The value of the option.
44 """
45- if expand is None:
46- expand = _get_expand_default_value()
47 value = self._get_user_option(option_name)
48 if expand:
49 if isinstance(value, list):
50@@ -637,7 +614,7 @@
51 for (oname, value, section, conf_id, parser) in self._get_options():
52 if oname.startswith('bzr.mergetool.'):
53 tool_name = oname[len('bzr.mergetool.'):]
54- tools[tool_name] = self.get_user_option(oname)
55+ tools[tool_name] = self.get_user_option(oname, False)
56 trace.mutter('loaded merge tools: %r' % tools)
57 return tools
58
59@@ -3658,7 +3635,7 @@
60 for store, section in sections():
61 yield store, section
62
63- def get(self, name, expand=None, convert=True):
64+ def get(self, name, expand=True, convert=True):
65 """Return the *first* option value found in the sections.
66
67 This is where we guarantee that sections coming from Store are loaded
68@@ -3677,8 +3654,6 @@
69 :returns: The value of the option.
70 """
71 # FIXME: No caching of options nor sections yet -- vila 20110503
72- if expand is None:
73- expand = _get_expand_default_value()
74 value = None
75 found_store = None # Where the option value has been found
76 # If the option is registered, it may provide additional info about
77
78=== modified file 'bzrlib/tests/__init__.py'
79--- bzrlib/tests/__init__.py 2012-02-23 23:26:35 +0000
80+++ bzrlib/tests/__init__.py 2012-03-08 18:36:26 +0000
81@@ -1026,10 +1026,6 @@
82 # between tests. We should get rid of this altogether: bug 656694. --
83 # mbp 20101008
84 self.overrideAttr(bzrlib.trace, '_verbosity_level', 0)
85- # Isolate config option expansion until its default value for bzrlib is
86- # settled on or a the FIXME associated with _get_expand_default_value
87- # is addressed -- vila 20110219
88- self.overrideAttr(config, '_expand_default_value', None)
89 self._log_files = set()
90 # Each key in the ``_counters`` dict holds a value for a different
91 # counter. When the test ends, addDetail() should be used to output the
92
93=== modified file 'bzrlib/tests/test_config.py'
94--- bzrlib/tests/test_config.py 2012-03-06 19:49:19 +0000
95+++ bzrlib/tests/test_config.py 2012-03-08 18:36:26 +0000
96@@ -689,63 +689,6 @@
97 self.assertFileEqual(content, 'test.conf')
98
99
100-class TestIniConfigOptionExpansionDefaultValue(tests.TestCaseInTempDir):
101- """What is the default value of expand for config options.
102-
103- This is an opt-in beta feature used to evaluate whether or not option
104- references can appear in dangerous place raising exceptions, disapearing
105- (and as such corrupting data) or if it's safe to activate the option by
106- default.
107-
108- Note that these tests relies on config._expand_default_value being already
109- overwritten in the parent class setUp.
110- """
111-
112- def setUp(self):
113- super(TestIniConfigOptionExpansionDefaultValue, self).setUp()
114- self.config = None
115- self.warnings = []
116- def warning(*args):
117- self.warnings.append(args[0] % args[1:])
118- self.overrideAttr(trace, 'warning', warning)
119-
120- def get_config(self, expand):
121- c = config.GlobalConfig.from_string('bzr.config.expand=%s' % (expand,),
122- save=True)
123- return c
124-
125- def assertExpandIs(self, expected):
126- actual = config._get_expand_default_value()
127- #self.config.get_user_option_as_bool('bzr.config.expand')
128- self.assertEquals(expected, actual)
129-
130- def test_default_is_None(self):
131- self.assertEquals(None, config._expand_default_value)
132-
133- def test_default_is_False_even_if_None(self):
134- self.config = self.get_config(None)
135- self.assertExpandIs(False)
136-
137- def test_default_is_False_even_if_invalid(self):
138- self.config = self.get_config('<your choice>')
139- self.assertExpandIs(False)
140- # ...
141- # Huh ? My choice is False ? Thanks, always happy to hear that :D
142- # Wait, you've been warned !
143- self.assertLength(1, self.warnings)
144- self.assertEquals(
145- 'Value "<your choice>" is not a boolean for "bzr.config.expand"',
146- self.warnings[0])
147-
148- def test_default_is_True(self):
149- self.config = self.get_config(True)
150- self.assertExpandIs(True)
151-
152- def test_default_is_False(self):
153- self.config = self.get_config(False)
154- self.assertExpandIs(False)
155-
156-
157 class TestIniConfigOptionExpansion(tests.TestCase):
158 """Test option expansion from the IniConfig level.
159
160
161=== modified file 'doc/en/release-notes/bzr-2.6.txt'
162--- doc/en/release-notes/bzr-2.6.txt 2012-03-06 18:54:54 +0000
163+++ doc/en/release-notes/bzr-2.6.txt 2012-03-08 18:36:26 +0000
164@@ -86,6 +86,11 @@
165 .. Major internal changes, unlikely to be visible to users or plugin
166 developers, but interesting for bzr developers.
167
168+* Turn config option expansion on by default. The only options for which
169+ this should be disabled are templates which should already have used
170+ conf.get(option, expand=False) or conf.get_user_option(option,
171+ expand=False). (Vincent Ladeuil)
172+
173 Testing
174 *******
175