Rev 5177: (vila) Warn if a config variable can't be interpreted as a boolean in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Apr 23 09:35:40 BST 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5177 [merge]
revision-id: pqm at pqm.ubuntu.com-20100423083538-2fokv22a7e596kmb
parent: pqm at pqm.ubuntu.com-20100423015148-zim5rd4e1bwxfbxb
parent: v.ladeuil+lp at free.fr-20100423071523-khsaqe1brhzlworp
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2010-04-23 09:35:38 +0100
message:
  (vila) Warn if a config variable can't be interpreted as a boolean
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
  bzrlib/help_topics/en/configuration.txt configuration.txt-20060314161707-868350809502af01
  bzrlib/tests/blackbox/test_init.py test_init.py-20060309032856-a292116204d86eb7
  bzrlib/tests/test_branch.py    test_branch.py-20060116013032-97819aa07b8ab3b5
  bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
=== modified file 'NEWS'
--- a/NEWS	2010-04-22 19:05:14 +0000
+++ b/NEWS	2010-04-23 07:15:23 +0000
@@ -6,7 +6,7 @@
    :depth: 1
 
 bzr 2.2b3
-##########
+#########
 
 :2.2b3: NOT RELEASED YET
 
@@ -567,6 +567,18 @@
 Improvements
 ************
 
+* ``append_revisions_only`` will no be interpreted as a boolean and a
+  warning emitted if illegal values are used. Note that for projects
+  that needs to maintain compatibility with previsous bzr versions,
+  only 'True' and 'False' strings must be used (previous versions of
+  bzr will interpret all strings differing from 'True'
+  (case-sensitive) as false.
+  (Brian de Alwis, Vincent Ladeuil)
+
+* ``Config.get_user_option_as_bool`` will now warn if a value cannot
+  be interpreted as a boolean.
+  (Vincent Ladeuil)
+
 * Fetching into experimental formats will now print a warning. (Jelmer
   Vernooij)
 

=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2010-04-22 17:08:27 +0000
+++ b/bzrlib/branch.py	2010-04-23 07:15:23 +0000
@@ -2870,8 +2870,8 @@
         return stacked_url
 
     def _get_append_revisions_only(self):
-        value = self.get_config().get_user_option('append_revisions_only')
-        return value == 'True'
+        return self.get_config(
+            ).get_user_option_as_bool('append_revisions_only')
 
     @needs_write_lock
     def generate_revision_history(self, revision_id, last_rev=None,

=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2010-03-06 05:28:17 +0000
+++ b/bzrlib/config.py	2010-04-23 07:15:23 +0000
@@ -193,7 +193,15 @@
             interpreted as a boolean. Returns True or False otherwise.
         """
         s = self._get_user_option(option_name)
-        return ui.bool_from_string(s)
+        if s is None:
+            # The option doesn't exist
+            return None
+        val = ui.bool_from_string(s)
+        if val is None:
+            # The value can't be interpreted as a boolean
+            trace.warning('Value "%s" is not a boolean for "%s"',
+                          s, option_name)
+        return val
 
     def get_user_option_as_list(self, option_name):
         """Get a generic option as a list - no special process, no default.

=== modified file 'bzrlib/help_topics/en/configuration.txt'
--- a/bzrlib/help_topics/en/configuration.txt	2010-03-24 13:58:37 +0000
+++ b/bzrlib/help_topics/en/configuration.txt	2010-04-23 07:15:23 +0000
@@ -495,9 +495,11 @@
 ~~~~~~~~~~~~~~~~~~~~~
 
 If set to "True" then revisions can only be appended to the log, not
-removed.  A branch with this setting enabled can only pull from
-another branch if the other branch's log is a longer version of its
-own.  This is normally set by ``bzr init --append-revisions-only``.
+removed.  A branch with this setting enabled can only pull from another
+branch if the other branch's log is a longer version of its own.  This is
+normally set by ``bzr init --append-revisions-only``. If you set it
+manually, use either 'True' or 'False' (case-sensitive) to maintain
+compatibility with previous bzr versions (older than 2.2).
 
 parent_location
 ~~~~~~~~~~~~~~~

=== modified file 'bzrlib/tests/blackbox/test_init.py'
--- a/bzrlib/tests/blackbox/test_init.py	2010-02-17 17:11:16 +0000
+++ b/bzrlib/tests/blackbox/test_init.py	2010-04-23 07:15:23 +0000
@@ -196,7 +196,7 @@
     def test_init_append_revisions_only(self):
         self.run_bzr('init --dirstate-tags normal_branch6')
         branch = _mod_branch.Branch.open('normal_branch6')
-        self.assertEqual(False, branch._get_append_revisions_only())
+        self.assertEqual(None, branch._get_append_revisions_only())
         self.run_bzr('init --append-revisions-only --dirstate-tags branch6')
         branch = _mod_branch.Branch.open('branch6')
         self.assertEqual(True, branch._get_append_revisions_only())

=== modified file 'bzrlib/tests/test_branch.py'
--- a/bzrlib/tests/test_branch.py	2010-03-25 14:22:41 +0000
+++ b/bzrlib/tests/test_branch.py	2010-04-23 07:15:23 +0000
@@ -515,6 +515,45 @@
         self.assertTrue(hasattr(params, 'to_branch'))
         self.assertTrue(hasattr(params, 'revision_id'))
 
+
+class TestBranchOptions(tests.TestCaseWithTransport):
+
+    def setUp(self):
+        super(TestBranchOptions, self).setUp()
+        self.branch = self.make_branch('.')
+        self.config = self.branch.get_config()
+
+    def check_append_revisions_only(self, expected_value, value=None):
+        """Set append_revisions_only in config and check its interpretation."""
+        if value is not None:
+            self.config.set_user_option('append_revisions_only', value)
+        self.assertEqual(expected_value,
+                         self.branch._get_append_revisions_only())
+
+    def test_valid_append_revisions_only(self):
+        self.assertEquals(None,
+                          self.config.get_user_option('append_revisions_only'))
+        self.check_append_revisions_only(None)
+        self.check_append_revisions_only(False, 'False')
+        self.check_append_revisions_only(True, 'True')
+        # The following values will cause compatibility problems on projects
+        # using older bzr versions (<2.2) but are accepted
+        self.check_append_revisions_only(False, 'false')
+        self.check_append_revisions_only(True, 'true')
+
+    def test_invalid_append_revisions_only(self):
+        """Ensure warning is noted on invalid settings"""
+        self.warnings = []
+        def warning(*args):
+            self.warnings.append(args[0] % args[1:])
+        self.overrideAttr(trace, 'warning', warning)
+        self.check_append_revisions_only(None, 'not-a-bool')
+        self.assertLength(1, self.warnings)
+        self.assertEqual(
+            'Value "not-a-bool" is not a boolean for "append_revisions_only"',
+            self.warnings[0])
+
+
 class TestPullResult(tests.TestCase):
 
     def test_pull_result_to_int(self):

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2010-02-23 07:43:11 +0000
+++ b/bzrlib/tests/test_config.py	2010-04-23 07:15:23 +0000
@@ -406,9 +406,16 @@
         get_bool = conf.get_user_option_as_bool
         self.assertEqual(True, get_bool('a_true_bool'))
         self.assertEqual(False, get_bool('a_false_bool'))
+        warnings = []
+        def warning(*args):
+            warnings.append(args[0] % args[1:])
+        self.overrideAttr(trace, 'warning', warning)
+        msg = 'Value "%s" is not a boolean for "%s"'
         self.assertIs(None, get_bool('an_invalid_bool'))
+        self.assertEquals(msg % ('maybe', 'an_invalid_bool'), warnings[0])
+        warnings = []
         self.assertIs(None, get_bool('not_defined_in_this_config'))
-
+        self.assertEquals([], warnings)
 
     def test_get_user_option_as_list(self):
         conf, parser = self.make_config_parser("""




More information about the bazaar-commits mailing list