From patchwork Thu Mar 13 10:52:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [STABLE] commit: create new amend changeset as secret correctly for "--secret" option From: Katsunori FUJIWARA X-Patchwork-Id: 3936 Message-Id: <1dfa466be5bfb7fad741.1394707932@feefifofum> To: mercurial-devel@selenic.com Date: Thu, 13 Mar 2014 19:52:12 +0900 # HG changeset patch # User FUJIWARA Katsunori # 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()". 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