Patchwork D3742: backout: use context manager for config override

login
register
mail settings
Submitter phabricator
Date June 14, 2018, 11:34 p.m.
Message ID <differential-rev-PHID-DREV-ajmpbknhhetmkxp7fo6t-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/32152/
State Superseded
Headers show

Comments

phabricator - June 14, 2018, 11:34 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3742

AFFECTED FILES
  mercurial/commands.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -619,18 +619,17 @@ 
     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)
             if stats.unresolvedcount:
                 repo.ui.status(_("use 'hg resolve' to retry unresolved "
                                  "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',