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
=== modified file 'bzrlib/config.py'
--- bzrlib/config.py 2012-03-06 19:49:19 +0000
+++ bzrlib/config.py 2012-03-08 18:36:26 +0000
@@ -195,27 +195,6 @@
195 return self[section][name]195 return self[section][name]
196196
197197
198# FIXME: Until we can guarantee that each config file is loaded once and
199# only once for a given bzrlib session, we don't want to re-read the file every
200# time we query for an option so we cache the value (bad ! watch out for tests
201# needing to restore the proper value). -- vila 20110219
202_expand_default_value = None
203def _get_expand_default_value():
204 global _expand_default_value
205 if _expand_default_value is not None:
206 return _expand_default_value
207 conf = GlobalConfig()
208 # Note that we must not use None for the expand value below or we'll run
209 # into infinite recursion. Using False really would be quite silly ;)
210 expand = conf.get_user_option_as_bool('bzr.config.expand', expand=True)
211 if expand is None:
212 # This is an opt-in feature, you *really* need to clearly say you want
213 # to activate it !
214 expand = False
215 _expand_default_value = expand
216 return expand
217
218
219class Config(object):198class Config(object):
220 """A configuration policy - what username, editor, gpg needs etc."""199 """A configuration policy - what username, editor, gpg needs etc."""
221200
@@ -373,7 +352,7 @@
373 """Template method to provide a user option."""352 """Template method to provide a user option."""
374 return None353 return None
375354
376 def get_user_option(self, option_name, expand=None):355 def get_user_option(self, option_name, expand=True):
377 """Get a generic option - no special process, no default.356 """Get a generic option - no special process, no default.
378357
379 :param option_name: The queried option.358 :param option_name: The queried option.
@@ -382,8 +361,6 @@
382361
383 :returns: The value of the option.362 :returns: The value of the option.
384 """363 """
385 if expand is None:
386 expand = _get_expand_default_value()
387 value = self._get_user_option(option_name)364 value = self._get_user_option(option_name)
388 if expand:365 if expand:
389 if isinstance(value, list):366 if isinstance(value, list):
@@ -637,7 +614,7 @@
637 for (oname, value, section, conf_id, parser) in self._get_options():614 for (oname, value, section, conf_id, parser) in self._get_options():
638 if oname.startswith('bzr.mergetool.'):615 if oname.startswith('bzr.mergetool.'):
639 tool_name = oname[len('bzr.mergetool.'):]616 tool_name = oname[len('bzr.mergetool.'):]
640 tools[tool_name] = self.get_user_option(oname)617 tools[tool_name] = self.get_user_option(oname, False)
641 trace.mutter('loaded merge tools: %r' % tools)618 trace.mutter('loaded merge tools: %r' % tools)
642 return tools619 return tools
643620
@@ -3658,7 +3635,7 @@
3658 for store, section in sections():3635 for store, section in sections():
3659 yield store, section3636 yield store, section
36603637
3661 def get(self, name, expand=None, convert=True):3638 def get(self, name, expand=True, convert=True):
3662 """Return the *first* option value found in the sections.3639 """Return the *first* option value found in the sections.
36633640
3664 This is where we guarantee that sections coming from Store are loaded3641 This is where we guarantee that sections coming from Store are loaded
@@ -3677,8 +3654,6 @@
3677 :returns: The value of the option.3654 :returns: The value of the option.
3678 """3655 """
3679 # FIXME: No caching of options nor sections yet -- vila 201105033656 # FIXME: No caching of options nor sections yet -- vila 20110503
3680 if expand is None:
3681 expand = _get_expand_default_value()
3682 value = None3657 value = None
3683 found_store = None # Where the option value has been found3658 found_store = None # Where the option value has been found
3684 # If the option is registered, it may provide additional info about3659 # If the option is registered, it may provide additional info about
36853660
=== modified file 'bzrlib/tests/__init__.py'
--- bzrlib/tests/__init__.py 2012-02-23 23:26:35 +0000
+++ bzrlib/tests/__init__.py 2012-03-08 18:36:26 +0000
@@ -1026,10 +1026,6 @@
1026 # between tests. We should get rid of this altogether: bug 656694. --1026 # between tests. We should get rid of this altogether: bug 656694. --
1027 # mbp 201010081027 # mbp 20101008
1028 self.overrideAttr(bzrlib.trace, '_verbosity_level', 0)1028 self.overrideAttr(bzrlib.trace, '_verbosity_level', 0)
1029 # Isolate config option expansion until its default value for bzrlib is
1030 # settled on or a the FIXME associated with _get_expand_default_value
1031 # is addressed -- vila 20110219
1032 self.overrideAttr(config, '_expand_default_value', None)
1033 self._log_files = set()1029 self._log_files = set()
1034 # Each key in the ``_counters`` dict holds a value for a different1030 # Each key in the ``_counters`` dict holds a value for a different
1035 # counter. When the test ends, addDetail() should be used to output the1031 # counter. When the test ends, addDetail() should be used to output the
10361032
=== modified file 'bzrlib/tests/test_config.py'
--- bzrlib/tests/test_config.py 2012-03-06 19:49:19 +0000
+++ bzrlib/tests/test_config.py 2012-03-08 18:36:26 +0000
@@ -689,63 +689,6 @@
689 self.assertFileEqual(content, 'test.conf')689 self.assertFileEqual(content, 'test.conf')
690690
691691
692class TestIniConfigOptionExpansionDefaultValue(tests.TestCaseInTempDir):
693 """What is the default value of expand for config options.
694
695 This is an opt-in beta feature used to evaluate whether or not option
696 references can appear in dangerous place raising exceptions, disapearing
697 (and as such corrupting data) or if it's safe to activate the option by
698 default.
699
700 Note that these tests relies on config._expand_default_value being already
701 overwritten in the parent class setUp.
702 """
703
704 def setUp(self):
705 super(TestIniConfigOptionExpansionDefaultValue, self).setUp()
706 self.config = None
707 self.warnings = []
708 def warning(*args):
709 self.warnings.append(args[0] % args[1:])
710 self.overrideAttr(trace, 'warning', warning)
711
712 def get_config(self, expand):
713 c = config.GlobalConfig.from_string('bzr.config.expand=%s' % (expand,),
714 save=True)
715 return c
716
717 def assertExpandIs(self, expected):
718 actual = config._get_expand_default_value()
719 #self.config.get_user_option_as_bool('bzr.config.expand')
720 self.assertEquals(expected, actual)
721
722 def test_default_is_None(self):
723 self.assertEquals(None, config._expand_default_value)
724
725 def test_default_is_False_even_if_None(self):
726 self.config = self.get_config(None)
727 self.assertExpandIs(False)
728
729 def test_default_is_False_even_if_invalid(self):
730 self.config = self.get_config('<your choice>')
731 self.assertExpandIs(False)
732 # ...
733 # Huh ? My choice is False ? Thanks, always happy to hear that :D
734 # Wait, you've been warned !
735 self.assertLength(1, self.warnings)
736 self.assertEquals(
737 'Value "<your choice>" is not a boolean for "bzr.config.expand"',
738 self.warnings[0])
739
740 def test_default_is_True(self):
741 self.config = self.get_config(True)
742 self.assertExpandIs(True)
743
744 def test_default_is_False(self):
745 self.config = self.get_config(False)
746 self.assertExpandIs(False)
747
748
749class TestIniConfigOptionExpansion(tests.TestCase):692class TestIniConfigOptionExpansion(tests.TestCase):
750 """Test option expansion from the IniConfig level.693 """Test option expansion from the IniConfig level.
751694
752695
=== modified file 'doc/en/release-notes/bzr-2.6.txt'
--- doc/en/release-notes/bzr-2.6.txt 2012-03-06 18:54:54 +0000
+++ doc/en/release-notes/bzr-2.6.txt 2012-03-08 18:36:26 +0000
@@ -86,6 +86,11 @@
86.. Major internal changes, unlikely to be visible to users or plugin 86.. Major internal changes, unlikely to be visible to users or plugin
87 developers, but interesting for bzr developers.87 developers, but interesting for bzr developers.
8888
89* Turn config option expansion on by default. The only options for which
90 this should be disabled are templates which should already have used
91 conf.get(option, expand=False) or conf.get_user_option(option,
92 expand=False). (Vincent Ladeuil)
93
89Testing94Testing
90*******95*******
9196