mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 00:14:35 +03:00
ui: use try..finally in configoverride
@contextmanager almost always have their "yield" inside a try..finally block. This is because if the calling code inside the activated context manager raises, the code after the "yield" won't get executed. A "finally" block, however, will get executed in this scenario.
This commit is contained in:
parent
8a9b1f64ab
commit
9f87ab8fca
@ -1201,16 +1201,18 @@ class ui(object):
|
||||
`overrides` must be a dict of the following structure:
|
||||
{(section, name) : value}"""
|
||||
backups = {}
|
||||
for (section, name), value in overrides.items():
|
||||
backups[(section, name)] = self.backupconfig(section, name)
|
||||
self.setconfig(section, name, value, source)
|
||||
yield
|
||||
for __, backup in backups.items():
|
||||
self.restoreconfig(backup)
|
||||
# just restoring ui.quiet config to the previous value is not enough
|
||||
# as it does not update ui.quiet class member
|
||||
if ('ui', 'quiet') in overrides:
|
||||
self.fixconfig(section='ui')
|
||||
try:
|
||||
for (section, name), value in overrides.items():
|
||||
backups[(section, name)] = self.backupconfig(section, name)
|
||||
self.setconfig(section, name, value, source)
|
||||
yield
|
||||
finally:
|
||||
for __, backup in backups.items():
|
||||
self.restoreconfig(backup)
|
||||
# just restoring ui.quiet config to the previous value is not enough
|
||||
# as it does not update ui.quiet class member
|
||||
if ('ui', 'quiet') in overrides:
|
||||
self.fixconfig(section='ui')
|
||||
|
||||
class paths(dict):
|
||||
"""Represents a collection of paths and their configs.
|
||||
|
Loading…
Reference in New Issue
Block a user