Patchwork [STABLE] amend: invalidate dirstate in case of failure (issue3670)

login
register
mail settings
Submitter Pierre-Yves David
Date Dec. 29, 2012, 5:10 p.m.
Message ID <a51a5199a672e3789240.1356801049@yamac.lan>
Download mbox | patch
Permalink /patch/333/
State Accepted
Commit 153659e86a5f441cc04544f71a34715bc161c28f
Headers show

Comments

Pierre-Yves David - Dec. 29, 2012, 5:10 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1356800418 -3600
# Branch stable
# Node ID a51a5199a672e378924066cd5103afef8de26fb8
# Parent  52581d2b98ac5355c3b2ea304595f8cfee4cce59
amend: invalidate dirstate in case of failure (issue3670)

The temporary commit created by amend update the dirstate. If the final commit
fails, we need to invalidate the change made to the dirstate, otherwise the
release of the wlock will write the dirstate created after the rollbacked
temporary commit.

This dirstate writing logic should probably be handled in the same object than
the transaction one. However such change are too big for stable.
Idan Kamara - Dec. 29, 2012, 6:46 p.m.
On Sat, Dec 29, 2012 at 7:10 PM, Pierre-Yves David <
pierre-yves.david at ens-lyon.org> wrote:
>
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
> # Date 1356800418 -3600
> # Branch stable
> # Node ID a51a5199a672e378924066cd5103afef8de26fb8
> # Parent  52581d2b98ac5355c3b2ea304595f8cfee4cce59
> amend: invalidate dirstate in case of failure (issue3670)
>
> The temporary commit created by amend update the dirstate. If the final
> commit
> fails, we need to invalidate the change made to the dirstate, otherwise
> the
> release of the wlock will write the dirstate created after the rollbacked
> temporary commit.

It also moves the active bookmark, which causes it to vanish
to thin air if the transaction is aborted (since it points to a
non existing node).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20121229/f0595771/attachment.html>

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1617,11 +1617,11 @@  def commit(ui, repo, commitfunc, pats, o
 
 def amend(ui, repo, commitfunc, old, extra, pats, opts):
     ui.note(_('amending changeset %s\n') % old)
     base = old.p1()
 
-    wlock = lock = None
+    wlock = lock = newid = None
     try:
         wlock = repo.wlock()
         lock = repo.lock()
         tr = repo.transaction('amend')
         try:
@@ -1780,10 +1780,12 @@  def amend(ui, repo, commitfunc, old, ext
             if node:
                 ui.note(_('stripping intermediate changeset %s\n') % ctx)
             ui.note(_('stripping amended changeset %s\n') % old)
             repair.strip(ui, repo, old.node(), topic='amend-backup')
     finally:
+        if newid is None:
+            repo.dirstate.invalidate()
         lockmod.release(wlock, lock)
     return newid
 
 def commiteditor(repo, ctx, subs):
     if ctx.description():
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
@@ -56,15 +56,38 @@  Amending changeset with changes in worki
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     base
   
 
+Check proper abort for empty message
+
+  $ cat > editor.sh << '__EOF__'
+  > #!/bin/sh
+  > echo "" > "$1"
+  > __EOF__
+  $ echo b > b
+  $ hg add b
+  $ hg summary
+  parent: 1:43f1ba15f28a tip
+   amend base1
+  branch: default
+  commit: 1 added, 1 unknown
+  update: (current)
+  $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit --amend
+  transaction abort!
+  rollback completed
+  abort: empty commit message
+  [255]
+  $ hg summary
+  parent: 1:43f1ba15f28a tip
+   amend base1
+  branch: default
+  commit: 1 added, 1 unknown
+  update: (current)
+
 Add new file:
-
-  $ echo b > b
-  $ hg ci --amend -Am 'amend base1 new file'
-  adding b
+  $ hg ci --amend -m 'amend base1 new file'
   saved backup bundle to $TESTTMP/.hg/strip-backup/43f1ba15f28a-amend-backup.hg (glob)
 
 Remove file that was added in amended commit:
 (and test logfile option)
 (and test that logfile option do not trigger an editor)