# HG changeset patch # User Yuya Nishihara # Date 2018-04-07 11:50:38 # Node ID 00e4bd97b095b81e4dae4a1783c0cb89bbaea7ae # Parent d83191e9749ba281b569ed67ad345406cedb095d procutil: always popen() in binary mode On Python 3, non-binary stream is useless. Let's convert line ending by ourselves. Note that we don't need fromnativeeol() in patch._externalpatch() since any whitespace characters are rstrip()-ed. diff --git a/hgext/bugzilla.py b/hgext/bugzilla.py --- a/hgext/bugzilla.py +++ b/hgext/bugzilla.py @@ -528,8 +528,8 @@ class bzmysql(bzaccess): except TypeError: cmd = cmdfmt % {'bzdir': bzdir, 'id': id, 'user': user} self.ui.note(_('running notify command %s\n') % cmd) - fp = procutil.popen('(%s) 2>&1' % cmd) - out = fp.read() + fp = procutil.popen('(%s) 2>&1' % cmd, 'rb') + out = util.fromnativeeol(fp.read()) ret = fp.close() if ret: self.ui.warn(out) diff --git a/hgext/convert/cvsps.py b/hgext/convert/cvsps.py --- a/hgext/convert/cvsps.py +++ b/hgext/convert/cvsps.py @@ -228,13 +228,13 @@ def createlog(ui, directory=None, root=" ui.note(_("running %s\n") % (' '.join(cmd))) ui.debug("prefix=%r directory=%r root=%r\n" % (prefix, directory, root)) - pfp = procutil.popen(' '.join(cmd)) - peek = pfp.readline() + pfp = procutil.popen(' '.join(cmd), 'rb') + peek = util.fromnativeeol(pfp.readline()) while True: line = peek if line == '': break - peek = pfp.readline() + peek = util.fromnativeeol(pfp.readline()) if line.endswith('\n'): line = line[:-1] #ui.debug('state=%d line=%r\n' % (state, line)) diff --git a/mercurial/mail.py b/mercurial/mail.py --- a/mercurial/mail.py +++ b/mercurial/mail.py @@ -144,8 +144,8 @@ def _sendmail(ui, sender, recipients, ms cmdline = '%s -f %s %s' % (program, stringutil.email(sender), ' '.join(map(stringutil.email, recipients))) ui.note(_('sending mail: %s\n') % cmdline) - fp = procutil.popen(cmdline, 'w') - fp.write(msg) + fp = procutil.popen(cmdline, 'wb') + fp.write(util.tonativeeol(msg)) ret = fp.close() if ret: raise error.Abort('%s %s' % ( diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -2103,8 +2103,9 @@ def _externalpatch(ui, repo, patcher, pa cwd = repo.root if cwd: args.append('-d %s' % procutil.shellquote(cwd)) - fp = procutil.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip, - procutil.shellquote(patchname))) + cmd = ('%s %s -p%d < %s' + % (patcher, ' '.join(args), strip, procutil.shellquote(patchname))) + fp = procutil.popen(cmd, 'rb') try: for line in util.iterfile(fp): line = line.rstrip()