topic: use ui.configoverride() instead of ui.backupconfig()
authorMartin von Zweigbergk <martinvonz@google.com>
Mon, 09 Dec 2019 10:31:34 -0800
changeset 5008 848ca807f83a
parent 5007 de0151ba3e46
child 5009 0ab3b94562ab
topic: use ui.configoverride() instead of ui.backupconfig() ui.configoverride() was added in hg 4.1. util.nullcontextmanager() was added in hg 4.4.
hgext3rd/topic/__init__.py
--- a/hgext3rd/topic/__init__.py	Mon Dec 09 10:28:58 2019 -0800
+++ b/hgext3rd/topic/__init__.py	Mon Dec 09 10:31:34 2019 -0800
@@ -1261,14 +1261,13 @@
 def checkt0(orig, ui, repo, node=None, rev=None, *args, **kwargs):
 
     thezeros = set([b't0', b'b0', b's0'])
-    backup = repo.ui.backupconfig(b'_internal', b'keep-topic')
-    try:
-        if node in thezeros or rev in thezeros:
-            repo.ui.setconfig(b'_internal', b'keep-topic', b'yes',
-                              source=b'topic-extension')
+    configoverride = util.nullcontextmanager()
+    if node in thezeros or rev in thezeros:
+        configoverride = repo.ui.configoverride({
+            (b'_internal', b'keep-topic'): b'yes'
+        }, source=b'topic-extension')
+    with configoverride:
         return orig(ui, repo, node=node, rev=rev, *args, **kwargs)
-    finally:
-        repo.ui.restoreconfig(backup)
 
 def _fixrebase(loaded):
     if not loaded: