Rev 5365: Merge lockable-config-files into remove-gratuitous-ensure-config-dir-exist-calls in file:///home/vila/src/bzr/bugs/525571-lock-bazaar-conf-files/

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Jul 22 09:01:06 BST 2010


At file:///home/vila/src/bzr/bugs/525571-lock-bazaar-conf-files/

------------------------------------------------------------
revno: 5365 [merge]
revision-id: v.ladeuil+lp at free.fr-20100722080106-2dzh6l5g0n1rf1vc
parent: v.ladeuil+lp at free.fr-20100722072038-m4xr03ddn086ymj1
parent: v.ladeuil+lp at free.fr-20100722080002-0jeq5fuanka2hpsh
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: remove-gratuitous-ensure-config-dir-exist-calls
timestamp: Thu 2010-07-22 10:01:06 +0200
message:
  Merge lockable-config-files into remove-gratuitous-ensure-config-dir-exist-calls
modified:
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
  bzrlib/tests/blackbox/test_break_lock.py test_break_lock.py-20060303014503-a90e07d38d042d1d
  bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2010-07-22 06:53:02 +0000
+++ b/bzrlib/config.py	2010-07-22 08:01:06 +0000
@@ -403,10 +403,17 @@
             self._parser = ConfigObj(co_input, encoding='utf-8')
         except configobj.ConfigObjError, e:
             raise errors.ParseConfigError(e.errors, e.config.filename)
-        # Make sure self._parser.reload() will use the right file name
+        # Make sure self.reload() will use the right file name
         self._parser.filename = self.file_name
         return self._parser
 
+    def reload(self):
+        """Reload the config file from disk."""
+        if self.file_name is None:
+            raise AssertionError('We need a file name to reload the config')
+        if self._parser is not None:
+            self._parser.reload()
+
     def _get_matching_sections(self):
         """Return an ordered list of (section_name, extra_path) pairs.
 
@@ -560,10 +567,8 @@
         self._write_config_file()
 
     def _set_option(self, option, value, section):
-        # FIXME: RBC 20051029 This should refresh the parser and also take a
-        # file lock on bazaar.conf.
-        if self._parser is not None:
-            self._parser.reload()
+        # FIXME: RBC 20051029 This should take a file lock on bazaar.conf.
+        self.reload()
         self._get_parser().setdefault(section, {})[option] = value
         self._write_config_file()
 
@@ -682,10 +687,8 @@
                          STORE_LOCATION_APPENDPATH]:
             raise ValueError('bad storage policy %r for %r' %
                 (store, option))
-        if self._parser is not None:
-            self._parser.reload()
-        # FIXME: RBC 20051029 This should refresh the parser and also take a
-        # file lock on locations.conf.
+        self.reload()
+        # FIXME: RBC 20051029 This should take a file lock on locations.conf.
         location = self.location
         if location.endswith('/'):
             location = location[:-1]

=== modified file 'bzrlib/tests/blackbox/test_break_lock.py'
--- a/bzrlib/tests/blackbox/test_break_lock.py	2010-07-21 13:32:27 +0000
+++ b/bzrlib/tests/blackbox/test_break_lock.py	2010-07-22 08:00:02 +0000
@@ -73,7 +73,7 @@
         # however, we dont test breaking the working tree because we
         # cannot accurately do so right now: the dirstate lock is held
         # by an os lock, and we need to spawn a separate process to lock it
-        # thne kill -9 it.
+        # then kill -9 it.
         # sketch of test:
         # lock most of the dir:
         self.wt.branch.lock_write()

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2010-07-22 06:53:02 +0000
+++ b/bzrlib/tests/test_config.py	2010-07-22 08:01:06 +0000
@@ -415,6 +415,26 @@
         self.assertFileEqual(content, 'test.conf')
 
 
+class TestIniBaseConfigOnDisk(tests.TestCaseInTempDir):
+
+    def test_cannot_reload_without_name(self):
+        conf = config.IniBasedConfig(_content=sample_config_text)
+        self.assertRaises(AssertionError, conf.reload)
+
+    def test_reload_see_new_value(self):
+        c1 = config.IniBasedConfig(file_name='./test/conf',
+                                   _content='editor=vim\n')
+        c1._write_config_file()
+        c2 = config.IniBasedConfig(file_name='./test/conf',
+                                   _content='editor=emacs\n')
+        c2._write_config_file()
+        self.assertEqual('vim', c1.get_user_option('editor'))
+        self.assertEqual('emacs', c2.get_user_option('editor'))
+        # Make sure we get the Right value
+        c1.reload()
+        self.assertEqual('emacs', c1.get_user_option('editor'))
+
+
 class TestLockableConfig(tests.TestCaseInTempDir):
 
     config_class = config.GlobalConfig



More information about the bazaar-commits mailing list