D7198: lock: refactor in preparation for next commit

valentin.gatienbaron (Valentin Gatien-Baron) phabricator at mercurial-scm.org
Mon Nov 18 23:05:42 EST 2019


Closed by commit rHGcd822413b9aa: lock: refactor in preparation for next commit (authored by valentin.gatienbaron).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7198?vs=17495&id=18231

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7198/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7198

AFFECTED FILES
  mercurial/lock.py

CHANGE DETAILS

diff --git a/mercurial/lock.py b/mercurial/lock.py
--- a/mercurial/lock.py
+++ b/mercurial/lock.py
@@ -330,27 +330,32 @@
                 return None
             raise
 
-    def _testlock(self, locker):
+    def _lockshouldbebroken(self, locker):
         if locker is None:
-            return None
+            return False
         try:
             host, pid = locker.split(b":", 1)
         except ValueError:
-            return locker
+            return False
         if host != lock._host:
-            return locker
+            return False
         try:
             pid = int(pid)
         except ValueError:
-            return locker
+            return False
         if procutil.testpid(pid):
+            return False
+        return True
+
+    def _testlock(self, locker):
+        if not self._lockshouldbebroken(locker):
             return locker
+
         # if locker dead, break lock.  must do this with another lock
         # held, or can race and break valid lock.
         try:
-            l = lock(self.vfs, self.f + b'.break', timeout=0)
-            self.vfs.unlink(self.f)
-            l.release()
+            with lock(self.vfs, self.f + b'.break', timeout=0):
+                self.vfs.unlink(self.f)
         except error.LockError:
             return locker
 



To: valentin.gatienbaron, #hg-reviewers, indygreg
Cc: indygreg, pulkit, marmoute, mercurial-devel


More information about the Mercurial-devel mailing list