Patchwork [1,of,3] pull: grab wlock during pull

login
register
mail settings
Submitter Pierre-Yves David
Date Oct. 3, 2016, 4:05 p.m.
Message ID <fbd46d349985f6baa9ea.1475510734@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/16834/
State Accepted
Headers show

Comments

Pierre-Yves David - Oct. 3, 2016, 4:05 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1471988879 -7200
#      Tue Aug 23 23:47:59 2016 +0200
# Node ID fbd46d349985f6baa9ea5439697920726757ad38
# Parent  3741a8f86e88702595c29f8ed824a28da0cfa961
# EXP-Topic vfs.ward
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.

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -1201,8 +1201,10 @@  def pull(repo, remote, heads=None, force
                     " %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 @@  def pull(repo, remote, heads=None, force
         _pullobsolete(pullop)
         pullop.trmanager.close()
     finally:
-        pullop.trmanager.release()
-        lock.release()
+        lockmod.release(pullop.trmanager, lock, wlock)
 
     return pullop
 
diff --git a/tests/lockdelay.py b/tests/lockdelay.py
--- a/tests/lockdelay.py
+++ b/tests/lockdelay.py
@@ -7,20 +7,16 @@  from __future__ import absolute_import
 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