changeset 34081:5dc6ac6555e6

amend: use context manager for config override Differential Revision: https://phab.mercurial-scm.org/D639
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 06 Sep 2017 10:41:13 -0700
parents 4059b10d7490
children ba6e14f9a2d8
files mercurial/cmdutil.py
diffstat 1 files changed, 6 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Wed Sep 06 10:42:02 2017 -0700
+++ b/mercurial/cmdutil.py	Wed Sep 06 10:41:13 2017 -0700
@@ -35,7 +35,6 @@
     obsolete,
     patch,
     pathutil,
-    phases,
     pycompat,
     registrar,
     revlog,
@@ -3162,16 +3161,13 @@
             # This not what we expect from amend.
             return old.node()
 
-        ph = repo.ui.config('phases', 'new-commit', phases.draft)
-        try:
-            if opts.get('secret'):
-                commitphase = 'secret'
-            else:
-                commitphase = old.phase()
-            repo.ui.setconfig('phases', 'new-commit', commitphase, 'amend')
+        if opts.get('secret'):
+            commitphase = 'secret'
+        else:
+            commitphase = old.phase()
+        overrides = {('phases', 'new-commit'): commitphase}
+        with ui.configoverride(overrides, 'amend'):
             newid = repo.commitctx(new)
-        finally:
-            repo.ui.setconfig('phases', 'new-commit', ph, 'amend')
 
         # Reroute the working copy parent to the new changeset
         repo.setparents(newid, nullid)