Patchwork [3,of,4] lock: factor out lock testing into a separate function

login
register
mail settings
Submitter Siddharth Agarwal
Date Sept. 22, 2015, 4:33 a.m.
Message ID <8fecc2f74b6417f508eb.1442896396@dev6666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/10566/
State Accepted
Headers show

Comments

Siddharth Agarwal - Sept. 22, 2015, 4:33 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1442458326 25200
#      Wed Sep 16 19:52:06 2015 -0700
# Node ID 8fecc2f74b6417f508eb4fc8e1358dad44bc396b
# Parent  9a99a53a7f7c818dd41370dcbd86d4e237f98552
lock: factor out lock testing into a separate function

This is going to be needed for upcoming work with lock inheritance.

Patch

diff --git a/mercurial/lock.py b/mercurial/lock.py
--- a/mercurial/lock.py
+++ b/mercurial/lock.py
@@ -113,18 +113,7 @@  class lock(object):
                 return None
             raise
 
-    def testlock(self):
-        """return id of locker if lock is valid, else None.
-
-        If old-style lock, we cannot tell what machine locker is on.
-        with new-style lock, if locker is on this machine, we can
-        see if locker is alive.  If locker is on this machine but
-        not alive, we can safely break lock.
-
-        The lock file is only deleted when None is returned.
-
-        """
-        locker = self._readlock()
+    def _testlock(self, locker):
         if locker is None:
             return None
         try:
@@ -148,6 +137,20 @@  class lock(object):
         except error.LockError:
             return locker
 
+    def testlock(self):
+        """return id of locker if lock is valid, else None.
+
+        If old-style lock, we cannot tell what machine locker is on.
+        with new-style lock, if locker is on this machine, we can
+        see if locker is alive.  If locker is on this machine but
+        not alive, we can safely break lock.
+
+        The lock file is only deleted when None is returned.
+
+        """
+        locker = self._readlock()
+        return self._testlock(locker)
+
     def release(self):
         """release the lock and execute callback function if any