changeset 37458:00e4bd97b095

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.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 07 Apr 2018 20:50:38 +0900
parents d83191e9749b
children 90c5ca718781
files hgext/bugzilla.py hgext/convert/cvsps.py mercurial/mail.py mercurial/patch.py
diffstat 4 files changed, 10 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/bugzilla.py	Sat Apr 07 13:46:32 2018 +0900
+++ b/hgext/bugzilla.py	Sat Apr 07 20:50:38 2018 +0900
@@ -528,8 +528,8 @@
             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)
--- a/hgext/convert/cvsps.py	Sat Apr 07 13:46:32 2018 +0900
+++ b/hgext/convert/cvsps.py	Sat Apr 07 20:50:38 2018 +0900
@@ -228,13 +228,13 @@
     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))
--- a/mercurial/mail.py	Sat Apr 07 13:46:32 2018 +0900
+++ b/mercurial/mail.py	Sat Apr 07 20:50:38 2018 +0900
@@ -144,8 +144,8 @@
     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' % (
--- a/mercurial/patch.py	Sat Apr 07 13:46:32 2018 +0900
+++ b/mercurial/patch.py	Sat Apr 07 20:50:38 2018 +0900
@@ -2103,8 +2103,9 @@
     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()