Rev 6469: Change default for ``bzr.config.expand`` to True in file:///home/vila/src/bzr/experimental/expand-default-true/

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Feb 16 09:52:46 UTC 2012


At file:///home/vila/src/bzr/experimental/expand-default-true/

------------------------------------------------------------
revno: 6469
revision-id: v.ladeuil+lp at free.fr-20120216095246-xeeqb1knm3mpa0bs
parent: pqm at pqm.ubuntu.com-20120214182943-vso6j0mqdnxfkp7s
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: expand-default-true
timestamp: Thu 2012-02-16 10:52:46 +0100
message:
  Change default for ``bzr.config.expand`` to True
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2012-02-14 17:22:37 +0000
+++ b/bzrlib/config.py	2012-02-16 09:52:46 +0000
@@ -195,27 +195,6 @@
         return self[section][name]
 
 
-# FIXME: Until we can guarantee that each config file is loaded once and
-# only once for a given bzrlib session, we don't want to re-read the file every
-# time we query for an option so we cache the value (bad ! watch out for tests
-# needing to restore the proper value). -- vila 20110219
-_expand_default_value = None
-def _get_expand_default_value():
-    global _expand_default_value
-    if _expand_default_value is not None:
-        return _expand_default_value
-    conf = GlobalConfig()
-    # Note that we must not use None for the expand value below or we'll run
-    # into infinite recursion. Using False really would be quite silly ;)
-    expand = conf.get_user_option_as_bool('bzr.config.expand', expand=True)
-    if expand is None:
-        # This is an opt-in feature, you *really* need to clearly say you want
-        # to activate it !
-        expand = False
-    _expand_default_value = expand
-    return expand
-
-
 class Config(object):
     """A configuration policy - what username, editor, gpg needs etc."""
 
@@ -373,7 +352,7 @@
         """Template method to provide a user option."""
         return None
 
-    def get_user_option(self, option_name, expand=None):
+    def get_user_option(self, option_name, expand=True):
         """Get a generic option - no special process, no default.
 
         :param option_name: The queried option.
@@ -382,8 +361,6 @@
 
         :returns: The value of the option.
         """
-        if expand is None:
-            expand = _get_expand_default_value()
         value = self._get_user_option(option_name)
         if expand:
             if isinstance(value, list):
@@ -637,7 +614,7 @@
         for (oname, value, section, conf_id, parser) in self._get_options():
             if oname.startswith('bzr.mergetool.'):
                 tool_name = oname[len('bzr.mergetool.'):]
-                tools[tool_name] = self.get_user_option(oname)
+                tools[tool_name] = self.get_user_option(oname, False)
         trace.mutter('loaded merge tools: %r' % tools)
         return tools
 
@@ -3643,7 +3620,7 @@
         self.store = store
         self.mutable_section_id = mutable_section_id
 
-    def get(self, name, expand=None):
+    def get(self, name, expand=True):
         """Return the *first* option value found in the sections.
 
         This is where we guarantee that sections coming from Store are loaded
@@ -3659,8 +3636,6 @@
         :returns: The value of the option.
         """
         # FIXME: No caching of options nor sections yet -- vila 20110503
-        if expand is None:
-            expand = _get_expand_default_value()
         value = None
         found_store = None # Where the option value has been found
         # If the option is registered, it may provide additional info about

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2012-02-02 23:46:45 +0000
+++ b/bzrlib/tests/__init__.py	2012-02-16 09:52:46 +0000
@@ -1026,10 +1026,6 @@
         # between tests.  We should get rid of this altogether: bug 656694. --
         # mbp 20101008
         self.overrideAttr(bzrlib.trace, '_verbosity_level', 0)
-        # Isolate config option expansion until its default value for bzrlib is
-        # settled on or a the FIXME associated with _get_expand_default_value
-        # is addressed -- vila 20110219
-        self.overrideAttr(config, '_expand_default_value', None)
         self._log_files = set()
         # Each key in the ``_counters`` dict holds a value for a different
         # counter. When the test ends, addDetail() should be used to output the

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2012-02-14 17:22:37 +0000
+++ b/bzrlib/tests/test_config.py	2012-02-16 09:52:46 +0000
@@ -689,63 +689,6 @@
         self.assertFileEqual(content, 'test.conf')
 
 
-class TestIniConfigOptionExpansionDefaultValue(tests.TestCaseInTempDir):
-    """What is the default value of expand for config options.
-
-    This is an opt-in beta feature used to evaluate whether or not option
-    references can appear in dangerous place raising exceptions, disapearing
-    (and as such corrupting data) or if it's safe to activate the option by
-    default.
-
-    Note that these tests relies on config._expand_default_value being already
-    overwritten in the parent class setUp.
-    """
-
-    def setUp(self):
-        super(TestIniConfigOptionExpansionDefaultValue, self).setUp()
-        self.config = None
-        self.warnings = []
-        def warning(*args):
-            self.warnings.append(args[0] % args[1:])
-        self.overrideAttr(trace, 'warning', warning)
-
-    def get_config(self, expand):
-        c = config.GlobalConfig.from_string('bzr.config.expand=%s' % (expand,),
-                                            save=True)
-        return c
-
-    def assertExpandIs(self, expected):
-        actual = config._get_expand_default_value()
-        #self.config.get_user_option_as_bool('bzr.config.expand')
-        self.assertEquals(expected, actual)
-
-    def test_default_is_None(self):
-        self.assertEquals(None, config._expand_default_value)
-
-    def test_default_is_False_even_if_None(self):
-        self.config = self.get_config(None)
-        self.assertExpandIs(False)
-
-    def test_default_is_False_even_if_invalid(self):
-        self.config = self.get_config('<your choice>')
-        self.assertExpandIs(False)
-        # ...
-        # Huh ? My choice is False ? Thanks, always happy to hear that :D
-        # Wait, you've been warned !
-        self.assertLength(1, self.warnings)
-        self.assertEquals(
-            'Value "<your choice>" is not a boolean for "bzr.config.expand"',
-            self.warnings[0])
-
-    def test_default_is_True(self):
-        self.config = self.get_config(True)
-        self.assertExpandIs(True)
-
-    def test_default_is_False(self):
-        self.config = self.get_config(False)
-        self.assertExpandIs(False)
-
-
 class TestIniConfigOptionExpansion(tests.TestCase):
     """Test option expansion from the IniConfig level.
 

=== modified file 'doc/en/release-notes/bzr-2.6.txt'
--- a/doc/en/release-notes/bzr-2.6.txt	2012-02-14 17:49:28 +0000
+++ b/doc/en/release-notes/bzr-2.6.txt	2012-02-16 09:52:46 +0000
@@ -70,6 +70,11 @@
 .. Major internal changes, unlikely to be visible to users or plugin 
    developers, but interesting for bzr developers.
 
+* Turn config option expansion on by default. The only options for which
+  this should be disable are templates which should already have used
+  conf.get(option, expand=False) or conf.get_user_option(option,
+  expand=False). (Vincent Ladeuil)
+
 Testing
 *******
 



More information about the bazaar-commits mailing list