[PATCH 1 of 2] lock: move lock._host calculation to a function

Jun Wu quark at fb.com
Fri Feb 10 22:09:34 UTC 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1486762521 28800
#      Fri Feb 10 13:35:21 2017 -0800
# Node ID f8eb762559b242ec12b199db1ce27c2930881c75
# Parent  b9116befa78417b1cb3763dafd44cc1fc6952109
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r f8eb762559b2
lock: move lock._host calculation to a function

This allows customization per platform. See the next patch for why.

diff --git a/mercurial/lock.py b/mercurial/lock.py
--- a/mercurial/lock.py
+++ b/mercurial/lock.py
@@ -19,4 +19,12 @@ from . import (
 )
 
+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
@@ -100,5 +108,5 @@ class lock(object):
             return
         if lock._host is None:
-            lock._host = socket.gethostname()
+            lock._host = _getlockprefix()
         lockname = '%s:%s' % (lock._host, self.pid)
         retry = 5


More information about the Mercurial-devel mailing list