# HG changeset patch # User timeless # Date 1454490682 0 # Node ID 14033c5dd261dca75af401932462639f0010cd3b # Parent a6db1163befab45bbe70a7dc13c12d7f6ab1a114 util: enable getpid to be replaced This will enable tests to write stable process ids. diff -r a6db1163befa -r 14033c5dd261 hgext/blackbox.py --- a/hgext/blackbox.py Mon Feb 08 00:47:36 2016 +0000 +++ b/hgext/blackbox.py Wed Feb 03 09:11:22 2016 +0000 @@ -31,7 +31,7 @@ from mercurial import util, cmdutil from mercurial.i18n import _ -import errno, os, re +import errno, re cmdtable = {} command = cmdutil.command(cmdtable) @@ -107,7 +107,7 @@ if blackbox: date = util.datestr(None, '%Y/%m/%d %H:%M:%S') user = util.getuser() - pid = str(os.getpid()) + pid = str(util.getpid()) formattedmsg = msg[0] % msg[1:] try: blackbox.write('%s %s (%s)> %s' % diff -r a6db1163befa -r 14033c5dd261 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Mon Feb 08 00:47:36 2016 +0000 +++ b/mercurial/cmdutil.py Wed Feb 03 09:11:22 2016 +0000 @@ -796,7 +796,7 @@ initfn() if not opts['daemon']: - writepid(os.getpid()) + writepid(util.getpid()) if opts['daemon_pipefds']: lockpath = opts['daemon_pipefds'] diff -r a6db1163befa -r 14033c5dd261 mercurial/commandserver.py --- a/mercurial/commandserver.py Mon Feb 08 00:47:36 2016 +0000 +++ b/mercurial/commandserver.py Wed Feb 03 09:11:22 2016 +0000 @@ -262,7 +262,7 @@ hellomsg += '\n' hellomsg += 'encoding: ' + encoding.encoding hellomsg += '\n' - hellomsg += 'pid: %d' % os.getpid() + hellomsg += 'pid: %d' % util.getpid() # write the hello msg in -one- chunk self.cout.write(hellomsg) diff -r a6db1163befa -r 14033c5dd261 mercurial/lock.py --- a/mercurial/lock.py Mon Feb 08 00:47:36 2016 +0000 +++ b/mercurial/lock.py Wed Feb 03 09:11:22 2016 +0000 @@ -9,7 +9,6 @@ import contextlib import errno -import os import socket import time import warnings @@ -77,8 +76,8 @@ self.release() def _getpid(self): - # wrapper around os.getpid() to make testing easier - return os.getpid() + # wrapper around util.getpid() to make testing easier + return util.getpid() def lock(self): timeout = self.timeout diff -r a6db1163befa -r 14033c5dd261 mercurial/util.py --- a/mercurial/util.py Mon Feb 08 00:47:36 2016 +0000 +++ b/mercurial/util.py Wed Feb 03 09:11:22 2016 +0000 @@ -65,6 +65,7 @@ findexe = platform.findexe gethgcmd = platform.gethgcmd getuser = platform.getuser +getpid = os.getpid groupmembers = platform.groupmembers groupname = platform.groupname hidewindow = platform.hidewindow diff -r a6db1163befa -r 14033c5dd261 tests/test-lock.py --- a/tests/test-lock.py Mon Feb 08 00:47:36 2016 +0000 +++ b/tests/test-lock.py Wed Feb 03 09:11:22 2016 +0000 @@ -28,7 +28,7 @@ self._pidoffset = pidoffset super(lockwrapper, self).__init__(*args, **kwargs) def _getpid(self): - return os.getpid() + self._pidoffset + return super(lockwrapper, self)._getpid() + self._pidoffset class teststate(object): def __init__(self, testcase, dir, pidoffset=0):