[PATCH 5 of 9 STABLE] mq: use "dirstateguard" instead of "dirstate.invalidate" (qpush)

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Wed Oct 1 11:18:32 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 10fcdb8b9280c28048bcd9f6b298705a0b428b53
# Parent  6675629ec0d25dc2a198a714e0c5ebed8f854303
mq: use "dirstateguard" instead of "dirstate.invalidate" (qpush)

Before this patch, "mq.queue.apply" uses "dirstate.invalidate()" to
restore dirstate to original status at failure. But it doesn't work
correctly, if "dirstate.write()" is executed while applying patches.

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/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -723,9 +723,10 @@
     def apply(self, repo, series, list=False, update_status=True,
               strict=False, patchdir=None, merge=None, all_files=None,
               tobackup=None, keepchanges=False):
-        wlock = lock = tr = None
+        wlock = dsguard = lock = tr = None
         try:
             wlock = repo.wlock()
+            dsguard = cmdutil.dirstateguard(repo, 'mq.apply')
             lock = repo.lock()
             tr = repo.transaction("qpush")
             try:
@@ -733,10 +734,12 @@
                                   strict, patchdir, merge, all_files=all_files,
                                   tobackup=tobackup, keepchanges=keepchanges)
                 tr.close()
+                dsguard.close()
                 self.savedirty()
                 return ret
             except AbortNoCleanup:
                 tr.close()
+                dsguard.close()
                 self.savedirty()
                 return 2, repo.dirstate.p1()
             except: # re-raises
@@ -744,11 +747,10 @@
                     tr.abort()
                 finally:
                     repo.invalidate()
-                    repo.dirstate.invalidate()
                     self.invalidate()
                 raise
         finally:
-            release(tr, lock, wlock)
+            release(tr, lock, dsguard, wlock)
             self.removeundo(repo)
 
     def _apply(self, repo, series, list=False, update_status=True,


More information about the Mercurial-devel mailing list