changeset 38328:0d6d0aa3c4bf

backout: use context manager for config override Differential Revision: https://phab.mercurial-scm.org/D3742
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 14 Jun 2018 15:26:18 -0700
parents 929405af558a
children eef4668be8a3
files mercurial/commands.py
diffstat 1 files changed, 5 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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',