graft: use context manager for config override
authorMartin von Zweigbergk <martinvonz@google.com>
Thu, 14 Jun 2018 15:45:16 -0700
changeset 38324 79dcaad9d145
parent 38323 565074cc9ac6
child 38325 7e34fc78701a
graft: use context manager for config override Differential Revision: https://phab.mercurial-scm.org/D3738
mercurial/commands.py
--- a/mercurial/commands.py	Thu Jun 14 11:49:10 2018 -0400
+++ b/mercurial/commands.py	Thu Jun 14 15:45:16 2018 -0700
@@ -2358,14 +2358,9 @@
         # we don't merge the first commit when continuing
         if not cont:
             # perform the graft merge with p1(rev) as 'ancestor'
-            try:
-                # ui.forcemerge is an internal variable, do not document
-                repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
-                                  'graft')
-                stats = mergemod.graft(repo, ctx, ctx.p1(),
-                                       ['local', 'graft'])
-            finally:
-                repo.ui.setconfig('ui', 'forcemerge', '', 'graft')
+            overrides = {('ui', 'forcemerge'): opts.get('tool', '')}
+            with ui.configoverride(overrides, 'graft'):
+                stats = mergemod.graft(repo, ctx, ctx.p1(), ['local', 'graft'])
             # report any conflicts
             if stats.unresolvedcount > 0:
                 # write out state for --continue