[PATCH 2 of 9 STABLE] amend: use "dirstateguard" instead of "dirstate.invalidate"

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Wed Oct 1 11:18:29 CDT 2014


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1412179386 -32400
#      Thu Oct 02 01:03:06 2014 +0900
# Branch stable
# Node ID cd19d1707e37b038755dd5cf38a8d02494ea3434
# Parent  91da9ccf1671d004fd4738ea99126acf103294a6
amend: use "dirstateguard" instead of "dirstate.invalidate"

Before this patch, "cmdutil.amend" uses "dirstate.invalidate()" to
restore dirstate to original status at failure. But it doesn't work
correctly, if "dirstate.write()" is executed.

This patch uses "dirstateguard" instead of "dirstate.invalidate" to
restore dirstate easily and certainly, even if "dirstate.write()" is
executed.

This is the preparation for fixing the issue that recent (in memory)
dirstate isn't visible to external process (e.g. "precommit" hook).

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1998,9 +1998,10 @@
     ui.note(_('amending changeset %s\n') % old)
     base = old.p1()
 
-    wlock = lock = newid = None
+    wlock = dsguard = lock = newid = None
     try:
         wlock = repo.wlock()
+        dsguard = dirstateguard(repo, 'amend')
         lock = repo.lock()
         tr = repo.transaction('amend')
         try:
@@ -2167,6 +2168,7 @@
             tr.close()
         finally:
             tr.release()
+        dsguard.close()
         if (not obsolete._enabled) and newid != old.node():
             # Strip the intermediate commit (if there was one) and the amended
             # commit
@@ -2175,9 +2177,7 @@
             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(lock, wlock)
+        lockmod.release(lock, dsguard, wlock)
     return newid
 
 def commiteditor(repo, ctx, subs):


More information about the Mercurial-devel mailing list