Patchwork [STABLE] commit: create new amend changeset as secret correctly for "--secret" option

login
register
mail settings
Submitter Katsunori FUJIWARA
Date March 13, 2014, 10:52 a.m.
Message ID <1dfa466be5bfb7fad741.1394707932@feefifofum>
Download mbox | patch
Permalink /patch/3936/
State Accepted
Commit b0153cb8b64efb546cbf3bd6bba5a6770ab2563f
Headers show

Comments

Katsunori FUJIWARA - March 13, 2014, 10:52 a.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1394707721 -32400
#      Thu Mar 13 19:48:41 2014 +0900
# Branch stable
# Node ID 1dfa466be5bfb7fad741648bd833f6e6fc88873f
# Parent  5ab28a2e9962f78f90cf3e38483af1bd24035e1a
commit: create new amend changeset as secret correctly for "--secret" option

Before this patch, "hg commit --amend --secret" doesn't create new
amend changeset as secret, even though the internal function
"commitfunc()" passed to "cmdutil.amend()" make "phases.new-commit"
configuration as "secret" temporarily.

"cmdutil.amend()" uses specified "commitfunc" only for temporary amend
commit, and creates the final amend commit changeset by
"localrepository.commitctx()" directly with memctx.

This patch creates new amend changeset as secret correctly for
"--secret" option, by changing "phases.new-commit" configuration
temporarily before "localrepository.commitctx()".
Matt Mackall - March 13, 2014, 3:52 p.m.
On Thu, 2014-03-13 at 19:52 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1394707721 -32400
> #      Thu Mar 13 19:48:41 2014 +0900
> # Branch stable
> # Node ID 1dfa466be5bfb7fad741648bd833f6e6fc88873f
> # Parent  5ab28a2e9962f78f90cf3e38483af1bd24035e1a
> commit: create new amend changeset as secret correctly for "--secret" option

Queued for stable, thanks.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1797,7 +1797,11 @@ 
 
             ph = repo.ui.config('phases', 'new-commit', phases.draft)
             try:
-                repo.ui.setconfig('phases', 'new-commit', old.phase())
+                if opts.get('secret'):
+                    commitphase = 'secret'
+                else:
+                    commitphase = old.phase()
+                repo.ui.setconfig('phases', 'new-commit', commitphase)
                 newid = repo.commitctx(new)
             finally:
                 repo.ui.setconfig('phases', 'new-commit', ph)
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1397,6 +1397,7 @@ 
         if opts.get('force_editor'):
             e = cmdutil.commitforceeditor
 
+        # commitfunc is used only for temporary amend commit by cmdutil.amend
         def commitfunc(ui, repo, message, match, opts):
             editor = e
             # message contains text from -m or -l, if it's empty,
@@ -1404,18 +1405,12 @@ 
             if not message:
                 message = old.description()
                 editor = cmdutil.commitforceeditor
-            try:
-                if opts.get('secret'):
-                    ui.setconfig('phases', 'new-commit', 'secret')
-
-                return repo.commit(message,
-                                   opts.get('user') or old.user(),
-                                   opts.get('date') or old.date(),
-                                   match,
-                                   editor=editor,
-                                   extra=extra)
-            finally:
-                ui.setconfig('phases', 'new-commit', oldcommitphase)
+            return repo.commit(message,
+                               opts.get('user') or old.user(),
+                               opts.get('date') or old.date(),
+                               match,
+                               editor=editor,
+                               extra=extra)
 
         current = repo._bookmarkcurrent
         marks = old.bookmarks()
diff --git a/tests/test-commit-amend.t b/tests/test-commit-amend.t
--- a/tests/test-commit-amend.t
+++ b/tests/test-commit-amend.t
@@ -765,3 +765,14 @@ 
   $ hg ci --close-branch -m'open and close'
   abort: can only close branch heads
   [255]
+
+Test that amend with --secret creates new secret changeset forcibly
+---------------------------------------------------------------------
+
+  $ hg phase '.^::.'
+  35: draft
+  36: draft
+  $ hg commit --amend --secret -m 'amend as secret' -q
+  $ hg phase '.^::.'
+  35: draft
+  38: secret