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

mail settings
Submitter Katsunori FUJIWARA
Date May 2, 2015, 3:59 p.m.
Message ID <7dff0d9e15588471bc31.1430582382@feefifofum>
Download mbox | patch
Permalink /patch/8859/
State Superseded
Headers show


Katsunori FUJIWARA - May 2, 2015, 3:59 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <>
# 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"


diff --git a/hgext/ b/hgext/
--- a/hgext/
+++ b/hgext/
@@ -1683,8 +1683,9 @@ 
             bmlist = repo[top].bookmarks()
+            dsguard = None
-                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.dirstate.endparentchange()
                 self.applieddirty = True
                 strip(self.ui, repo, [top], update=False, backup=False)
-            except: # re-raises
-                repo.dirstate.invalidate()
-                raise
+                dsguard.close()
+            finally:
+                release(dsguard)
                 # might be nice to attempt to roll back strip after this