backout: use context manager for config override
authorMartin von Zweigbergk <martinvonz@google.com>
Thu, 14 Jun 2018 15:26:18 -0700
changeset 38319 0d6d0aa3c4bf
parent 38318 929405af558a
child 38320 eef4668be8a3
backout: use context manager for config override Differential Revision: https://phab.mercurial-scm.org/D3742
mercurial/commands.py
--- a/mercurial/commands.py	Thu Jun 14 15:46:31 2018 -0700
+++ b/mercurial/commands.py	Thu Jun 14 15:26:18 2018 -0700
@@ -619,9 +619,9 @@
     if not opts.get('merge') and op1 != node:
         dsguard = dirstateguard.dirstateguard(repo, 'backout')
         try:
-            ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
-                         'backout')
-            stats = mergemod.update(repo, parent, True, True, node, False)
+            overrides = {('ui', 'forcemerge'): opts.get('tool', '')}
+            with ui.configoverride(overrides, 'backout'):
+                stats = mergemod.update(repo, parent, True, True, node, False)
             repo.setparents(op1, op2)
             dsguard.close()
             hg._showstats(repo, stats)
@@ -630,7 +630,6 @@
                                  "file merges\n"))
                 return 1
         finally:
-            ui.setconfig('ui', 'forcemerge', '', '')
             lockmod.release(dsguard)
     else:
         hg.clean(repo, node, show_stats=False)
@@ -667,12 +666,9 @@
         hg.clean(repo, op1, show_stats=False)
         ui.status(_('merging with changeset %s\n')
                   % nice(repo.changelog.tip()))
-        try:
-            ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
-                         'backout')
+        overrides = {('ui', 'forcemerge'): opts.get('tool', '')}
+        with ui.configoverride(overrides, 'backout'):
             return hg.merge(repo, hex(repo.changelog.tip()))
-        finally:
-            ui.setconfig('ui', 'forcemerge', '', '')
     return 0
 
 @command('bisect',