changeset 30920:dc9f086c7691

lock: move lock._host calculation to a function This allows customization per platform. See the next patch for why.
author Jun Wu <quark@fb.com>
date Fri, 10 Feb 2017 13:35:21 -0800
parents e1fa5fe9f9d4
children 1f151a33af8e
files mercurial/lock.py
diffstat 1 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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: