[PATCH 7 of 9 V2] mq: use dirstateguard instead of dirstate.invalidate (qrefresh)

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Sat May 2 10:59:42 CDT 2015


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1430582197 -32400
#      Sun May 03 00:56:37 2015 +0900
# Node ID 7dff0d9e15588471bc31488e1d6f17a8788e123e
# Parent  ab0a35bdac68de0d93544799e93a914b339f1aa3
mq: use dirstateguard instead of dirstate.invalidate (qrefresh)

Before this patch, "mq.queue.refresh()" uses "dirstate.invalidate()"
as a kind of "restore .hg/dirstate to the original status" at failure.

But it just discards changes in memory, and doesn't actually restore
".hg/dirstate". Then, it can't work as expected, if "dirstate.write()"
is executed while processing.

This patch uses "dirstateguard" instead of "dirstate.invalidate()" to
restore ".hg/dirstate" at failure even if "dirstate.write()" is
executed before failure.

This patch also removes "beginparentchage()" and "endparentchange()",
because "dirstateguard" makes them useless, too.

This is a part of preparations to fix the issue that recent (in
memory) dirstate isn't visible to external process (e.g. "precommit"
hook).

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -1683,8 +1683,9 @@
 
             bmlist = repo[top].bookmarks()
 
+            dsguard = None
             try:
-                repo.dirstate.beginparentchange()
+                dsguard = cmdutil.dirstateguard(repo, 'mq.refresh')
                 if diffopts.git or diffopts.upgrade:
                     copies = {}
                     for dst in a:
@@ -1737,13 +1738,12 @@
 
                 # assumes strip can roll itself back if interrupted
                 repo.setparents(*cparents)
-                repo.dirstate.endparentchange()
                 self.applied.pop()
                 self.applieddirty = True
                 strip(self.ui, repo, [top], update=False, backup=False)
-            except: # re-raises
-                repo.dirstate.invalidate()
-                raise
+                dsguard.close()
+            finally:
+                release(dsguard)
 
             try:
                 # might be nice to attempt to roll back strip after this


More information about the Mercurial-devel mailing list