# HG changeset patch # User Jun Wu # Date 1486762521 28800 # Node ID dc9f086c76915c7450c5746a45d14161481c37c6 # Parent e1fa5fe9f9d40409b5de8d9affee5874ee6ae42e lock: move lock._host calculation to a function This allows customization per platform. See the next patch for why. diff -r e1fa5fe9f9d4 -r dc9f086c7691 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: