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

login
register
mail settings
Submitter Jun Wu
Date Feb. 10, 2017, 10:09 p.m.
Message ID <f8eb762559b242ec12b1.1486764574@localhost.localdomain>
Download mbox | patch
Permalink /patch/18417/
State Accepted
Headers show

Comments

Jun Wu - Feb. 10, 2017, 10:09 p.m.
# HG changeset patch
# User Jun Wu <quark@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.

Patch

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