Rev 6071: Migrate bzr.workingtree.worth_saving_limit to stack-based config. in file:///home/vila/src/bzr/experimental/migrate-config-options/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Aug 12 14:47:42 UTC 2011


At file:///home/vila/src/bzr/experimental/migrate-config-options/

------------------------------------------------------------
revno: 6071
revision-id: v.ladeuil+lp at free.fr-20110812144742-g12l2cgakyulg935
parent: v.ladeuil+lp at free.fr-20110812140943-253s5c9zxxa2nthc
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: migrate-config-options
timestamp: Fri 2011-08-12 16:47:42 +0200
message:
  Migrate bzr.workingtree.worth_saving_limit to stack-based config.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-08-12 14:09:43 +0000
+++ b/bzrlib/config.py	2011-08-12 14:47:42 +0000
@@ -2380,8 +2380,17 @@
 # Registered options in lexicographical order
 
 option_registry.register(
-    Option('dirstate.fdatasync', default=True, from_unicode=bool_from_store,
-           help='''
+    Option('bzr.workingtree.worth_saving_limit', default=10,
+           from_unicode=int_from_store,  invalid='warning',
+           help='''\
+How many changes before saving the dirstate.
+
+-1 means never save.
+'''))
+option_registry.register(
+    Option('dirstate.fdatasync', default=True,
+           from_unicode=bool_from_store,
+           help='''\
 Flush dirstate changes onto physical disk?
 
 If true (default), working tree metadata changes are flushed through the

=== modified file 'bzrlib/tests/per_workingtree/test_workingtree.py'
--- a/bzrlib/tests/per_workingtree/test_workingtree.py	2011-07-08 23:01:39 +0000
+++ b/bzrlib/tests/per_workingtree/test_workingtree.py	2011-08-12 14:47:42 +0000
@@ -24,10 +24,12 @@
     branch,
     branchbuilder,
     bzrdir,
+    config,
     errors,
     osutils,
     symbol_versioning,
     tests,
+    trace,
     urlutils,
     )
 from bzrlib.errors import (
@@ -1119,7 +1121,7 @@
 
 class TestControlComponent(TestCaseWithWorkingTree):
     """WorkingTree implementations adequately implement ControlComponent."""
-    
+
     def test_urls(self):
         wt = self.make_branch_and_tree('wt')
         self.assertIsInstance(wt.user_url, str)
@@ -1150,19 +1152,26 @@
 
     def test_set_in_branch(self):
         wt = self.make_wt_with_worth_saving_limit()
-        config = wt.branch.get_config()
-        config.set_user_option('bzr.workingtree.worth_saving_limit', '20')
+        conf = config.BranchStack(wt.branch)
+        conf.set('bzr.workingtree.worth_saving_limit', '20')
         self.assertEqual(20, wt._worth_saving_limit())
         ds = wt.current_dirstate()
         self.assertEqual(10, ds._worth_saving_limit)
 
     def test_invalid(self):
         wt = self.make_wt_with_worth_saving_limit()
-        config = wt.branch.get_config()
-        config.set_user_option('bzr.workingtree.worth_saving_limit', 'a')
+        conf = config.BranchStack(wt.branch)
+        conf.set('bzr.workingtree.worth_saving_limit', 'a')
         # If the config entry is invalid, default to 10
-        # TODO: This writes a warning to the user, trap it somehow
+        warnings = []
+        def warning(*args):
+            warnings.append(args[0] % args[1:])
+        self.overrideAttr(trace, 'warning', warning)
         self.assertEqual(10, wt._worth_saving_limit())
+        self.assertLength(1, warnings)
+        self.assertEquals('Value "a" is not valid for'
+                          ' "bzr.workingtree.worth_saving_limit"',
+                          warnings[0])
 
 
 class TestFormatAttributes(TestCaseWithWorkingTree):

=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py	2011-06-28 11:29:03 +0000
+++ b/bzrlib/workingtree_4.py	2011-08-12 14:47:42 +0000
@@ -34,6 +34,7 @@
 from bzrlib import (
     bzrdir,
     cache_utf8,
+    config,
     conflicts as _mod_conflicts,
     debug,
     dirstate,
@@ -76,8 +77,6 @@
 
 class DirStateWorkingTree(InventoryWorkingTree):
 
-    _DEFAULT_WORTH_SAVING_LIMIT = 10
-
     def __init__(self, basedir,
                  branch,
                  _control_files=None,
@@ -251,20 +250,9 @@
 
         :return: an integer. -1 means never save.
         """
-        config = self.branch.get_config()
-        val = config.get_user_option('bzr.workingtree.worth_saving_limit')
-        if val is None:
-            val = self._DEFAULT_WORTH_SAVING_LIMIT
-        else:
-            try:
-                val = int(val)
-            except ValueError, e:
-                trace.warning('Invalid config value for'
-                              ' "bzr.workingtree.worth_saving_limit"'
-                              ' value %r is not an integer.'
-                              % (val,))
-                val = self._DEFAULT_WORTH_SAVING_LIMIT
-        return val
+        # FIXME: We want a WorkingTreeStack here -- vila 20110812
+        conf = config.BranchStack(self.branch)
+        return conf.get('bzr.workingtree.worth_saving_limit')
 
     def filter_unversioned_files(self, paths):
         """Filter out paths that are versioned.



More information about the bazaar-commits mailing list