comparison mercurial/ui.py @ 15919:69e792cf7851

config: have a way to backup and restore value in config This is introduce to allow temporary overwriting of a config value while being able to reinstall the old value once done. The main advantage over using ``config`` and ``setconfig`` is that backup and restore will properly restore the lack of any config. Restoring the fact that there was no value is important to allow config user to keep using meaniful default value. A more naive approach will result in the following scenario:: Before: config(section, item, my_default) --> my_default temporal overwrite old = config(section, item) … setconfig(section, item, old) After config(section, item, my_default) --> None The first user of this feature should be mq to overwriting minimal phase of future commit.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Wed, 18 Jan 2012 16:52:26 +0100
parents ee112eb69d2a
children ae5f92e154d3 c14898df3b92
comparison
equal deleted inserted replaced
15918:4f9853e7f690 15919:69e792cf7851
139 139
140 if section in (None, 'trusted'): 140 if section in (None, 'trusted'):
141 # update trust information 141 # update trust information
142 self._trustusers.update(self.configlist('trusted', 'users')) 142 self._trustusers.update(self.configlist('trusted', 'users'))
143 self._trustgroups.update(self.configlist('trusted', 'groups')) 143 self._trustgroups.update(self.configlist('trusted', 'groups'))
144
145 def backupconfig(self, section, item):
146 return (self._ocfg.backup(section, item),
147 self._tcfg.backup(section, item),
148 self._ucfg.backup(section, item),)
149 def restoreconfig(self, data):
150 self._ocfg.restore(data[0])
151 self._tcfg.restore(data[1])
152 self._ucfg.restore(data[2])
144 153
145 def setconfig(self, section, name, value, overlay=True): 154 def setconfig(self, section, name, value, overlay=True):
146 if overlay: 155 if overlay:
147 self._ocfg.set(section, name, value) 156 self._ocfg.set(section, name, value)
148 self._tcfg.set(section, name, value) 157 self._tcfg.set(section, name, value)