File tree 2 files changed +10
-9
lines changed
2 files changed +10
-9
lines changed Original file line number Diff line number Diff line change 16
16
17
17
import os
18
18
import re
19
+ import shlex
19
20
import subprocess
20
21
import sys
21
22
35
36
36
37
def cmdstr (cmd ):
37
38
"""Get a nicely quoted shell command."""
38
- ret = []
39
- for arg in cmd :
40
- if not re .match (r"^[a-zA-Z0-9/_.=-]+$" , arg ):
41
- arg = f'"{ arg } "'
42
- ret .append (arg )
43
- return " " .join (ret )
39
+ return " " .join (shlex .quote (x ) for x in cmd )
44
40
45
41
46
42
def run (opts , cmd , check = True , ** kwargs ):
Original file line number Diff line number Diff line change @@ -57,9 +57,14 @@ class Trace:
57
57
trace = Trace ()
58
58
59
59
60
+ def cmdstr (cmd ):
61
+ """Get a nicely quoted shell command."""
62
+ return " " .join (shlex .quote (x ) for x in cmd )
63
+
64
+
60
65
def exec_command (cmd ):
61
66
"""Execute |cmd| or return None on failure."""
62
- trace .print (":" , " " . join (cmd ))
67
+ trace .print (":" , cmdstr (cmd ))
63
68
try :
64
69
if platform .system () == "Windows" :
65
70
ret = subprocess .call (cmd )
@@ -506,7 +511,7 @@ def run_command(cmd, **kwargs):
506
511
# Run & package the results.
507
512
proc = subprocess .Popen (cmd , ** kwargs )
508
513
(stdout , stderr ) = proc .communicate (input = cmd_input )
509
- dbg = ": " + " " . join (cmd )
514
+ dbg = ": " + cmdstr (cmd )
510
515
if cmd_input is not None :
511
516
dbg += " 0<|"
512
517
if stdout == subprocess .PIPE :
@@ -843,7 +848,7 @@ def _GetRepoConfig(name):
843
848
return None
844
849
else :
845
850
print (
846
- f"repo: error: git { ' ' . join (cmd )} failed:\n { ret .stderr } " ,
851
+ f"repo: error: git { cmdstr (cmd )} failed:\n { ret .stderr } " ,
847
852
file = sys .stderr ,
848
853
)
849
854
# This will raise subprocess.CalledProcessError for us.
You can’t perform that action at this time.
0 commit comments