Patchwork D204: commit: don't let failed commit with --addremove update dirstate (issue5645)

login
register
mail settings
Submitter phabricator
Date July 31, 2017, 11:59 p.m.
Message ID <differential-rev-PHID-DREV-aou2xm5ib2h33cltdr2p-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/22597/
State Superseded
Headers show

Comments

phabricator - July 31, 2017, 11:59 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D204

AFFECTED FILES
  mercurial/cmdutil.py
  tests/test-commit.t
  tests/test-flagprocessor.t
  tests/test-username-newline.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/tests/test-username-newline.t b/tests/test-username-newline.t
--- a/tests/test-username-newline.t
+++ b/tests/test-username-newline.t
@@ -14,10 +14,12 @@ 
   $ rm .hg/hgrc
 
   $ HGUSER=`(echo foo; echo bar2)` hg ci -Am m
+  adding a
   abort: username 'foo\nbar2' contains a newline
   
   [255]
   $ hg ci -Am m -u "`(echo foo; echo bar3)`"
+  adding a
   transaction abort!
   rollback completed
   abort: username 'foo\nbar3' contains a newline!
diff --git a/tests/test-flagprocessor.t b/tests/test-flagprocessor.t
--- a/tests/test-flagprocessor.t
+++ b/tests/test-flagprocessor.t
@@ -152,7 +152,6 @@ 
   $ hg commit -Aqm 'fail+base64+gzip+noop'
   abort: missing processor for flag '0x1'!
   [255]
-  $ hg forget fail-base64-gzip-noop
   $ rm fail-base64-gzip-noop
 
 # TEST: ensure we cannot register several flag processors on the same flag
diff --git a/tests/test-commit.t b/tests/test-commit.t
--- a/tests/test-commit.t
+++ b/tests/test-commit.t
@@ -157,7 +157,7 @@ 
   abort: edit failed: false exited with status 1
   [255]
   $ hg status
-  A newfile
+  ? newfile
 
 Make sure we do not obscure unknown requires file entries (issue2649)
 
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -26,6 +26,7 @@ 
     changelog,
     copies,
     crecord as crecordmod,
+    dirstateguard,
     encoding,
     error,
     formatter,
@@ -2888,14 +2889,23 @@ 
     message = logmessage(ui, opts)
     matcher = scmutil.match(repo[None], pats, opts)
 
+    dsguard = None
     # extract addremove carefully -- this function can be called from a command
     # that doesn't support addremove
-    if opts.get('addremove'):
-        if scmutil.addremove(repo, matcher, "", opts) != 0:
-            raise error.Abort(
-                _("failed to mark all new/missing files as added/removed"))
-
-    return commitfunc(ui, repo, message, matcher, opts)
+    try:
+        if opts.get('addremove'):
+            dsguard = dirstateguard.dirstateguard(repo, 'commit')
+            if scmutil.addremove(repo, matcher, "", opts) != 0:
+                raise error.Abort(
+                    _("failed to mark all new/missing files as added/removed"))
+
+        r = commitfunc(ui, repo, message, matcher, opts)
+        if dsguard:
+            dsguard.close()
+        return r
+    finally:
+        if dsguard:
+            dsguard.release()
 
 def samefile(f, ctx1, ctx2):
     if f in ctx1.manifest():