Patchwork [5,of,5] py3: convert popen() command arguments in hgclient to str on Windows

login
register
mail settings
Submitter Matt Harbison
Date Dec. 18, 2018, 6:56 a.m.
Message ID <932ed8a051de1d7ef7ae.1545116171@Envy>
Download mbox | patch
Permalink /patch/37231/
State Accepted
Headers show

Comments

Matt Harbison - Dec. 18, 2018, 6:56 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1545112472 18000
#      Tue Dec 18 00:54:32 2018 -0500
# Node ID 932ed8a051de1d7ef7aee5af66395b48080f17b3
# Parent  6de48fd4e5d322f05986427e1dcce150bbf32e47
py3: convert popen() command arguments in hgclient to str on Windows

This fixes test-commandserver.t and test-keyword.t, which was previously
complaining

        TypeError("a bytes-like object is required, not 'str'")

Patch

diff --git a/contrib/hgclient.py b/contrib/hgclient.py
--- a/contrib/hgclient.py
+++ b/contrib/hgclient.py
@@ -33,7 +33,12 @@  def connectpipe(path=None, extraargs=())
         cmdline += [b'-R', path]
     cmdline.extend(extraargs)
 
-    server = subprocess.Popen(cmdline, stdin=subprocess.PIPE,
+    def tonative(cmdline):
+        if os.name != r'nt':
+            return cmdline
+        return [arg.decode("utf-8") for arg in cmdline]
+
+    server = subprocess.Popen(tonative(cmdline), stdin=subprocess.PIPE,
                               stdout=subprocess.PIPE)
 
     return server