[PATCH 3 of 6] commit: update the --secret code to use backupconfig and restoreconfig

pierre-yves.david at ens-lyon.org pierre-yves.david at ens-lyon.org
Tue Aug 5 23:27:31 CDT 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1407289985 25200
#      Tue Aug 05 18:53:05 2014 -0700
# Node ID e55c90663515bf11cce9fdf6459c7d6b6789015e
# Parent  78b7329fcb845f6c2603104a688ead6ef4f88c77
commit: update the --secret code to use backupconfig and restoreconfig

Those dedicated methods also preserver all associated data (eg: as sources, lack of value).

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1383,13 +1383,10 @@ def commit(ui, repo, *pats, **opts):
         if opts.get('amend'):
             raise util.Abort(_('cannot amend with --subrepos'))
         # 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()
     bheads = repo.branchheads(branch)
 
@@ -1439,25 +1436,26 @@ def commit(ui, repo, *pats, **opts):
                 if bm == current:
                     bookmarks.setcurrent(repo, bm)
             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')
 
                 return repo.commit(message, opts.get('user'), opts.get('date'),
                                    match,
                                    editor=cmdutil.getcommiteditor(**opts),
                                    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)
 
         if not node:


More information about the Mercurial-devel mailing list