--- a/mercurial/chgserver.py Sat Mar 24 13:38:04 2018 +0900
+++ b/mercurial/chgserver.py Sat Mar 24 15:09:33 2018 +0900
@@ -61,6 +61,10 @@
util,
)
+from .utils import (
+ procutil,
+)
+
_log = commandserver.log
def _hashlist(items):
@@ -200,7 +204,7 @@
# these situations and will behave differently (write to stdout).
if (out is not self.fout
or not util.safehasattr(self.fout, 'fileno')
- or self.fout.fileno() != util.stdout.fileno()):
+ or self.fout.fileno() != procutil.stdout.fileno()):
return util.system(cmd, environ=environ, cwd=cwd, out=out)
self.flush()
return self._csystem(cmd, util.shellenviron(environ), cwd)
--- a/mercurial/commandserver.py Sat Mar 24 13:38:04 2018 +0900
+++ b/mercurial/commandserver.py Sat Mar 24 15:09:33 2018 +0900
@@ -29,6 +29,9 @@
pycompat,
util,
)
+from .utils import (
+ procutil,
+)
logfile = None
@@ -308,8 +311,8 @@
ui.flush()
newfiles = []
nullfd = os.open(os.devnull, os.O_RDWR)
- for f, sysf, mode in [(ui.fin, util.stdin, r'rb'),
- (ui.fout, util.stdout, r'wb')]:
+ for f, sysf, mode in [(ui.fin, procutil.stdin, r'rb'),
+ (ui.fout, procutil.stdout, r'wb')]:
if f is sysf:
newfd = os.dup(f.fileno())
os.dup2(nullfd, f.fileno())
--- a/mercurial/dispatch.py Sat Mar 24 13:38:04 2018 +0900
+++ b/mercurial/dispatch.py Sat Mar 24 15:09:33 2018 +0900
@@ -42,6 +42,7 @@
)
from .utils import (
+ procutil,
stringutil,
)
@@ -127,8 +128,8 @@
pass
# Otherwise mark it as closed to silence "Exception ignored in"
# message emitted by the interpreter finalizer. Be careful to
- # not close util.stdout, which may be a fdopen-ed file object and
- # its close() actually closes the underlying file descriptor.
+ # not close procutil.stdout, which may be a fdopen-ed file object
+ # and its close() actually closes the underlying file descriptor.
try:
fp.close()
except IOError:
@@ -180,7 +181,7 @@
elif req.ui:
ferr = req.ui.ferr
else:
- ferr = util.stderr
+ ferr = procutil.stderr
try:
if not req.ui:
--- a/mercurial/hgweb/wsgicgi.py Sat Mar 24 13:38:04 2018 +0900
+++ b/mercurial/hgweb/wsgicgi.py Sat Mar 24 15:09:33 2018 +0900
@@ -15,13 +15,17 @@
util,
)
+from ..utils import (
+ procutil,
+)
+
from . import (
common,
)
def launch(application):
- util.setbinary(util.stdin)
- util.setbinary(util.stdout)
+ util.setbinary(procutil.stdin)
+ util.setbinary(procutil.stdout)
environ = dict(encoding.environ.iteritems())
environ.setdefault(r'PATH_INFO', '')
@@ -31,12 +35,12 @@
if environ[r'PATH_INFO'].startswith(scriptname):
environ[r'PATH_INFO'] = environ[r'PATH_INFO'][len(scriptname):]
- stdin = util.stdin
+ stdin = procutil.stdin
if environ.get(r'HTTP_EXPECT', r'').lower() == r'100-continue':
- stdin = common.continuereader(stdin, util.stdout.write)
+ stdin = common.continuereader(stdin, procutil.stdout.write)
environ[r'wsgi.input'] = stdin
- environ[r'wsgi.errors'] = util.stderr
+ environ[r'wsgi.errors'] = procutil.stderr
environ[r'wsgi.version'] = (1, 0)
environ[r'wsgi.multithread'] = False
environ[r'wsgi.multiprocess'] = True
@@ -49,7 +53,7 @@
headers_set = []
headers_sent = []
- out = util.stdout
+ out = procutil.stdout
def write(data):
if not headers_set:
--- a/mercurial/hook.py Sat Mar 24 13:38:04 2018 +0900
+++ b/mercurial/hook.py Sat Mar 24 15:09:33 2018 +0900
@@ -19,6 +19,9 @@
pycompat,
util,
)
+from .utils import (
+ procutil,
+)
def _pythonhook(ui, repo, htype, hname, funcname, args, throw):
'''call python hook. hook is callable object, looked up as
@@ -222,11 +225,11 @@
for hname, cmd in hooks:
if oldstdout == -1 and _redirect:
try:
- stdoutno = util.stdout.fileno()
- stderrno = util.stderr.fileno()
+ stdoutno = procutil.stdout.fileno()
+ stderrno = procutil.stderr.fileno()
# temporarily redirect stdout to stderr, if possible
if stdoutno >= 0 and stderrno >= 0:
- util.stdout.flush()
+ procutil.stdout.flush()
oldstdout = os.dup(stdoutno)
os.dup2(stderrno, stdoutno)
except (OSError, AttributeError):
@@ -269,10 +272,10 @@
# The stderr is fully buffered on Windows when connected to a pipe.
# A forcible flush is required to make small stderr data in the
# remote side available to the client immediately.
- util.stderr.flush()
+ procutil.stderr.flush()
if _redirect and oldstdout >= 0:
- util.stdout.flush() # write hook output to stderr fd
+ procutil.stdout.flush() # write hook output to stderr fd
os.dup2(oldstdout, stdoutno)
os.close(oldstdout)
--- a/mercurial/keepalive.py Sat Mar 24 13:38:04 2018 +0900
+++ b/mercurial/keepalive.py Sat Mar 24 15:09:33 2018 +0900
@@ -97,6 +97,9 @@
urllibcompat,
util,
)
+from .utils import (
+ procutil,
+)
httplib = util.httplib
urlerr = util.urlerr
@@ -635,14 +638,14 @@
def comp(N, url):
print(' making %i connections to:\n %s' % (N, url))
- util.stdout.write(' first using the normal urllib handlers')
+ procutil.stdout.write(' first using the normal urllib handlers')
# first use normal opener
opener = urlreq.buildopener()
urlreq.installopener(opener)
t1 = fetch(N, url)
print(' TIME: %.3f s' % t1)
- util.stdout.write(' now using the keepalive handler ')
+ procutil.stdout.write(' now using the keepalive handler ')
# now install the keepalive handler and try again
opener = urlreq.buildopener(HTTPHandler())
urlreq.installopener(opener)
@@ -687,11 +690,11 @@
i = 20
print(" waiting %i seconds for the server to close the connection" % i)
while i > 0:
- util.stdout.write('\r %2i' % i)
- util.stdout.flush()
+ procutil.stdout.write('\r %2i' % i)
+ procutil.stdout.flush()
time.sleep(1)
i -= 1
- util.stderr.write('\r')
+ procutil.stderr.write('\r')
print(" fetching the file a second time")
fo = urlreq.urlopen(url)
--- a/mercurial/server.py Sat Mar 24 13:38:04 2018 +0900
+++ b/mercurial/server.py Sat Mar 24 15:09:33 2018 +0900
@@ -22,6 +22,10 @@
util,
)
+from .utils import (
+ procutil,
+)
+
def runservice(opts, parentfn=None, initfn=None, runfn=None, logfile=None,
runargs=None, appendpid=False):
'''Run a command as a service.'''
@@ -87,8 +91,8 @@
raise error.Abort(_('invalid value for --daemon-postexec: %s')
% inst)
util.hidewindow()
- util.stdout.flush()
- util.stderr.flush()
+ procutil.stdout.flush()
+ procutil.stderr.flush()
nullfd = os.open(os.devnull, os.O_RDWR)
logfilefd = nullfd
--- a/mercurial/ui.py Sat Mar 24 13:38:04 2018 +0900
+++ b/mercurial/ui.py Sat Mar 24 15:09:33 2018 +0900
@@ -39,6 +39,7 @@
)
from .utils import (
dateutil,
+ procutil,
stringutil,
)
@@ -250,9 +251,9 @@
self.httppasswordmgrdb = src.httppasswordmgrdb
self._blockedtimes = src._blockedtimes
else:
- self.fout = util.stdout
- self.ferr = util.stderr
- self.fin = util.stdin
+ self.fout = procutil.stdout
+ self.ferr = procutil.stderr
+ self.fin = procutil.stdin
self.pageractive = False
self._disablepager = False
self._tweaked = False
@@ -1099,7 +1100,7 @@
pager = subprocess.Popen(
command, shell=shell, bufsize=-1,
close_fds=util.closefds, stdin=subprocess.PIPE,
- stdout=util.stdout, stderr=util.stderr,
+ stdout=procutil.stdout, stderr=procutil.stderr,
env=util.shellenviron(env))
except OSError as e:
if e.errno == errno.ENOENT and not shell:
@@ -1109,20 +1110,20 @@
raise
# back up original file descriptors
- stdoutfd = os.dup(util.stdout.fileno())
- stderrfd = os.dup(util.stderr.fileno())
+ stdoutfd = os.dup(procutil.stdout.fileno())
+ stderrfd = os.dup(procutil.stderr.fileno())
- os.dup2(pager.stdin.fileno(), util.stdout.fileno())
- if self._isatty(util.stderr):
- os.dup2(pager.stdin.fileno(), util.stderr.fileno())
+ os.dup2(pager.stdin.fileno(), procutil.stdout.fileno())
+ if self._isatty(procutil.stderr):
+ os.dup2(pager.stdin.fileno(), procutil.stderr.fileno())
@self.atexit
def killpager():
if util.safehasattr(signal, "SIGINT"):
signal.signal(signal.SIGINT, signal.SIG_IGN)
# restore original fds, closing pager.stdin copies in the process
- os.dup2(stdoutfd, util.stdout.fileno())
- os.dup2(stderrfd, util.stderr.fileno())
+ os.dup2(stdoutfd, procutil.stdout.fileno())
+ os.dup2(stderrfd, procutil.stderr.fileno())
pager.stdin.close()
pager.wait()
--- a/mercurial/wireproto.py Sat Mar 24 13:38:04 2018 +0900
+++ b/mercurial/wireproto.py Sat Mar 24 15:09:33 2018 +0900
@@ -35,6 +35,7 @@
)
from .utils import (
+ procutil,
stringutil,
)
@@ -519,8 +520,8 @@
opts[k] = others[k]
del others[k]
if others:
- util.stderr.write("warning: %s ignored unexpected arguments %s\n"
- % (cmd, ",".join(others)))
+ procutil.stderr.write("warning: %s ignored unexpected arguments %s\n"
+ % (cmd, ",".join(others)))
return opts
def bundle1allowed(repo, action):
@@ -1081,14 +1082,14 @@
try:
raise
except error.Abort:
- # The old code we moved used util.stderr directly.
+ # The old code we moved used procutil.stderr directly.
# We did not change it to minimise code change.
# This need to be moved to something proper.
# Feel free to do it.
- util.stderr.write("abort: %s\n" % exc)
+ procutil.stderr.write("abort: %s\n" % exc)
if exc.hint is not None:
- util.stderr.write("(%s)\n" % exc.hint)
- util.stderr.flush()
+ procutil.stderr.write("(%s)\n" % exc.hint)
+ procutil.stderr.flush()
return pushres(0, output.getvalue() if output else '')
except error.PushRaced:
return pusherr(pycompat.bytestr(exc),
--- a/tests/test-commit-interactive.t Sat Mar 24 13:38:04 2018 +0900
+++ b/tests/test-commit-interactive.t Sat Mar 24 15:09:33 2018 +0900
@@ -900,7 +900,9 @@
> from __future__ import absolute_import
> from mercurial import (
> pycompat,
- > util,
+ > )
+ > from mercurial.utils import (
+ > procutil,
> )
> def escape(c):
> o = ord(c)
@@ -908,8 +910,9 @@
> return c
> else:
> return br'\x%02x' % o # escape char setting MSB
- > for l in util.stdin:
- > util.stdout.write(b''.join(escape(c) for c in pycompat.iterbytestr(l)))
+ > for l in procutil.stdin:
+ > procutil.stdout.write(
+ > b''.join(escape(c) for c in pycompat.iterbytestr(l)))
> EOF
$ hg commit -i --encoding cp932 2>&1 <<EOF | $PYTHON $TESTTMP/escape.py | grep '^y - '
--- a/tests/test-config-env.py Sat Mar 24 13:38:04 2018 +0900
+++ b/tests/test-config-env.py Sat Mar 24 15:09:33 2018 +0900
@@ -11,6 +11,10 @@
util,
)
+from mercurial.utils import (
+ procutil,
+)
+
testtmp = encoding.environ[b'TESTTMP']
# prepare hgrc files
@@ -41,9 +45,9 @@
ui = uimod.ui.load()
for section, name, value in ui.walkconfig():
source = ui.configsource(section, name)
- util.stdout.write(b'%s.%s=%s # %s\n'
- % (section, name, value, util.pconvert(source)))
- util.stdout.write(b'\n')
+ procutil.stdout.write(b'%s.%s=%s # %s\n'
+ % (section, name, value, util.pconvert(source)))
+ procutil.stdout.write(b'\n')
# environment variable overrides
printconfigs({})