pull: grab wlock during pull
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Tue, 23 Aug 2016 23:47:59 +0200
changeset 30068 a76d5ba7ac43
parent 30067 6e88cd060ba2
child 30069 98b9846a131e
pull: grab wlock during pull because pull might move bookmarks and bookmark are protected by wlock, we have to grab wlock for pull :-( This required a small upgrade of the 'lockdelay' extension used by 'test-clone.t' because the delay must apply to a single lock only.
mercurial/exchange.py
tests/lockdelay.py
--- a/mercurial/exchange.py	Wed Aug 24 04:19:11 2016 +0200
+++ b/mercurial/exchange.py	Tue Aug 23 23:47:59 2016 +0200
@@ -1201,8 +1201,10 @@
                     " %s") % (', '.join(sorted(missing)))
             raise error.Abort(msg)
 
-    lock = pullop.repo.lock()
+    wlock = lock = None
     try:
+        wlock = pullop.repo.wlock()
+        lock = pullop.repo.lock()
         pullop.trmanager = transactionmanager(repo, 'pull', remote.url())
         streamclone.maybeperformlegacystreamclone(pullop)
         # This should ideally be in _pullbundle2(). However, it needs to run
@@ -1217,8 +1219,7 @@
         _pullobsolete(pullop)
         pullop.trmanager.close()
     finally:
-        pullop.trmanager.release()
-        lock.release()
+        lockmod.release(pullop.trmanager, lock, wlock)
 
     return pullop
 
--- a/tests/lockdelay.py	Wed Aug 24 04:19:11 2016 +0200
+++ b/tests/lockdelay.py	Tue Aug 23 23:47:59 2016 +0200
@@ -7,20 +7,16 @@
 import os
 import time
 
-from mercurial import (
-    lock as lockmod,
-)
+def reposetup(ui, repo):
 
-class delaylock(lockmod.lock):
-    def lock(self):
-        delay = float(os.environ.get('HGPRELOCKDELAY', '0.0'))
-        if delay:
-            time.sleep(delay)
-        res = super(delaylock, self).lock()
-        delay = float(os.environ.get('HGPOSTLOCKDELAY', '0.0'))
-        if delay:
-            time.sleep(delay)
-        return res
-
-def extsetup(ui):
-    lockmod.lock = delaylock
+    class delayedlockrepo(repo.__class__):
+        def lock(self):
+            delay = float(os.environ.get('HGPRELOCKDELAY', '0.0'))
+            if delay:
+                time.sleep(delay)
+            res = super(delayedlockrepo, self).lock()
+            delay = float(os.environ.get('HGPOSTLOCKDELAY', '0.0'))
+            if delay:
+                time.sleep(delay)
+            return res
+    repo.__class__ = delayedlockrepo