diff --git a/mercurial/ui.py b/mercurial/ui.py index a8feb88ddc..cdbd6ba7e0 100644 --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -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.