lock: move lock._host calculation to a function
authorJun Wu <quark@fb.com>
Fri, 10 Feb 2017 13:35:21 -0800
changeset 30920 dc9f086c7691
parent 30919 e1fa5fe9f9d4
child 30921 1f151a33af8e
lock: move lock._host calculation to a function This allows customization per platform. See the next patch for why.
mercurial/lock.py
--- a/mercurial/lock.py	Wed Feb 01 17:33:46 2017 +0100
+++ b/mercurial/lock.py	Fri Feb 10 13:35:21 2017 -0800
@@ -18,6 +18,14 @@
     util,
 )
 
+def _getlockprefix():
+    """Return a string which is used to differentiate pid namespaces
+
+    It's useful to detect "dead" processes and remove stale locks with
+    confidence. Typically it's just hostname.
+    """
+    return socket.gethostname()
+
 class lock(object):
     '''An advisory lock held by one process to control access to a set
     of files.  Non-cooperating processes or incorrectly written scripts
@@ -99,7 +107,7 @@
             self.held += 1
             return
         if lock._host is None:
-            lock._host = socket.gethostname()
+            lock._host = _getlockprefix()
         lockname = '%s:%s' % (lock._host, self.pid)
         retry = 5
         while not self.held and retry: