topic: use ui.configoverride() instead of ui.backupconfig()
authorMartin von Zweigbergk <martinvonz@google.com>
Mon, 09 Dec 2019 10:28:58 -0800
changeset 5007 de0151ba3e46
parent 5006 93014d9726d5
child 5008 848ca807f83a
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:33:48 2019 -0800
+++ b/hgext3rd/topic/__init__.py	Mon Dec 09 10:28:58 2019 -0800
@@ -385,14 +385,14 @@
             return caps
 
         def commit(self, *args, **kwargs):
-            backup = self.ui.backupconfig(b'ui', b'allowemptycommit')
-            try:
-                if self.currenttopic != self[b'.'].topic():
-                    # bypass the core "nothing changed" logic
-                    self.ui.setconfig(b'ui', b'allowemptycommit', True)
+            configoverride = util.nullcontextmanager()
+            if self.currenttopic != self[b'.'].topic():
+                # bypass the core "nothing changed" logic
+                configoverride = self.ui.configoverride({
+                    (b'ui', b'allowemptycommit'): True
+                })
+            with configoverride:
                 return super(topicrepo, self).commit(*args, **kwargs)
-            finally:
-                self.ui.restoreconfig(backup)
 
         def commitctx(self, ctx, *args, **kwargs):
             topicfilter = topicmap.topicfilter(self.filtername)