Rev 5369: Implement _save for LockableConfig too. in file:///home/vila/src/bzr/bugs/525571-lock-bazaar-conf-files/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon Aug 23 17:57:52 BST 2010
At file:///home/vila/src/bzr/bugs/525571-lock-bazaar-conf-files/
------------------------------------------------------------
revno: 5369
revision-id: v.ladeuil+lp at free.fr-20100823165752-uu7kdj3p69nn7q7z
parent: v.ladeuil+lp at free.fr-20100823163845-vp2ip6burcfvm1cs
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: remove-gratuitous-ensure-config-dir-exist-calls
timestamp: Mon 2010-08-23 18:57:52 +0200
message:
Implement _save for LockableConfig too.
* bzrlib/tests/test_config.py:
More simplifications.
* bzrlib/config.py:
(LockableConfig.__init__): Needs to override the IniConfig _save
handling.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2010-08-23 16:38:45 +0000
+++ b/bzrlib/config.py 2010-08-23 16:57:52 +0000
@@ -564,12 +564,18 @@
lock_name = 'lock'
- def __init__(self, file_name, _content=None):
+ def __init__(self, file_name, _content=None, _save=False):
super(LockableConfig, self).__init__(file_name=file_name,
- _content=_content)
+ _content=_content, _save=False)
self.dir = osutils.dirname(osutils.safe_unicode(self.file_name))
self.transport = transport.get_transport(self.dir)
self._lock = lockdir.LockDir(self.transport, 'lock')
+ if _save:
+ # We need to handle the saving here (as opposed to IniBasedConfig)
+ # to be able to lock
+ self.lock_write()
+ self._write_config_file()
+ self.unlock()
def lock_write(self, token=None):
"""Takes a write lock in the directory containing the config file.
@@ -755,6 +761,7 @@
location = self.location
if location.endswith('/'):
location = location[:-1]
+ parser = self._get_parser()
if not location in parser and not location + '/' in parser:
parser[location] = {}
elif location + '/' in parser:
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2010-08-23 16:38:45 +0000
+++ b/bzrlib/tests/test_config.py 2010-08-23 16:57:52 +0000
@@ -491,10 +491,7 @@
return self.config_class(*self.config_args)
def create_config(self, content):
- c = self.config_class(*self.config_args, _content=content)
- c.lock_write()
- c._write_config_file()
- c.unlock()
+ c = self.config_class(*self.config_args, _content=content, _save=True)
return c
def test_simple_read_access(self):
@@ -1168,16 +1165,10 @@
if global_config is None:
global_config = sample_config_text
- my_global_config = config.GlobalConfig(_content=global_config)
- my_global_config.lock_write()
- my_global_config._write_config_file()
- my_global_config.unlock()
+ my_global_config = config.GlobalConfig(_content=global_config,
+ _save=True)
my_location_config = config.LocationConfig(
- my_branch.base, _content=sample_branches_text)
- my_location_config.lock_write()
- my_location_config._write_config_file()
- my_location_config.unlock()
-
+ my_branch.base, _content=sample_branches_text, _save=True)
my_config = config.BranchConfig(my_branch)
self.my_config = my_config
self.my_location_config = my_config._get_location_config()
@@ -1248,16 +1239,12 @@
location_config=None, branch_data_config=None):
my_branch = FakeBranch(location)
if global_config is not None:
- my_global_config = config.GlobalConfig(_content=global_config)
- my_global_config.lock_write()
- my_global_config._write_config_file()
- my_global_config.unlock()
+ my_global_config = config.GlobalConfig(_content=global_config,
+ _save=True)
if location_config is not None:
my_location_config = config.LocationConfig(my_branch.base,
- _content=location_config)
- my_location_config.lock_write()
- my_location_config._write_config_file()
- my_location_config.unlock()
+ _content=location_config,
+ _save=True)
my_config = config.BranchConfig(my_branch)
if branch_data_config is not None:
my_config.branch.control_files.files['branch.conf'] = \
More information about the bazaar-commits
mailing list