On Sat, Apr 7, 2018 at 6:39 AM, Yuya Nishihara <y...@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <y...@tcha.org>
> # Date 1523101838 -32400
> #      Sat Apr 07 20:50:38 2018 +0900
> # Node ID 7a2e591c5eec11d8cf946d8032b6245f4099a161
> # Parent  d83191e9749ba281b569ed67ad345406cedb095d
> procutil: always popen() in binary mode
>

Queued this series.

The cleanup is greatly appreciated! Even better that it teased out some bad
behavior.


>
> 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()
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to