commit: update the --secret code to use backupconfig and restoreconfig
authorPierre-Yves David <pierre-yves.david@fb.com>
Tue, 05 Aug 2014 18:53:05 -0700
changeset 22039 0aa2cb965f4c
parent 22038 021becbf024a
child 22040 122fa73657c6
commit: update the --secret code to use backupconfig and restoreconfig Those dedicated methods also preserve all associated data (eg: sources, lack of value).
mercurial/commands.py
--- a/mercurial/commands.py	Tue Aug 05 13:22:44 2014 -0700
+++ b/mercurial/commands.py	Tue Aug 05 18:53:05 2014 -0700
@@ -1386,9 +1386,6 @@
         # Let --subrepos on the command line override config setting.
         ui.setconfig('ui', 'commitsubrepos', True, 'commit')
 
-    # Save this for restoring it later
-    oldcommitphase = ui.config('phases', 'new-commit')
-
     cmdutil.checkunfinished(repo, commit=True)
 
     branch = repo[None].branch()
@@ -1442,12 +1439,14 @@
             newmarks.write()
     else:
         def commitfunc(ui, repo, message, match, opts):
+            backup = ui.backupconfig('phases', 'new-commit')
+            baseui = repo.baseui
+            basebackup = baseui.backupconfig('phases', 'new-commit')
             try:
                 if opts.get('secret'):
                     ui.setconfig('phases', 'new-commit', 'secret', 'commit')
                     # Propagate to subrepos
-                    repo.baseui.setconfig('phases', 'new-commit', 'secret',
-                                          'commit')
+                    baseui.setconfig('phases', 'new-commit', 'secret', 'commit')
 
                 editform = 'commit.normal'
                 editor = cmdutil.getcommiteditor(editform=editform, **opts)
@@ -1456,9 +1455,8 @@
                                    editor=editor,
                                    extra=extra)
             finally:
-                ui.setconfig('phases', 'new-commit', oldcommitphase, 'commit')
-                repo.baseui.setconfig('phases', 'new-commit', oldcommitphase,
-                                      'commit')
+                ui.restoreconfig(backup)
+                repo.baseui.restoreconfig(basebackup)
 
 
         node = cmdutil.commit(ui, repo, commitfunc, pats, opts)