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

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Oct. 1, 2014, 4:18 p.m.
Message ID <10fcdb8b9280c28048bc.1412180312@feefifofum>
Download mbox | patch
Permalink /patch/6062/
State Changes Requested
Headers show

Comments

Katsunori FUJIWARA - Oct. 1, 2014, 4:18 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@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).

Patch

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,