--- a/mercurial/ui.py Mon Nov 21 18:17:02 2016 -0500
+++ b/mercurial/ui.py Mon Nov 21 16:22:26 2016 -0800
@@ -7,6 +7,7 @@
from __future__ import absolute_import
+import contextlib
import errno
import getpass
import inspect
@@ -1193,6 +1194,23 @@
" update your code.)") % version
self.develwarn(msg, stacklevel=2, config='deprec-warn')
+ @contextlib.contextmanager
+ def configoverride(self, overrides, source=""):
+ """Context manager for temporary config overrides
+ `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')
+
class paths(dict):
"""Represents a collection of paths and their configs.