Skip to content

Commit 0214730

Browse files
vapierLUCI
authored and
LUCI
committed
launcher: switch command quoting to shlex.quote
Minor fix, but just in case, provides properly quoted commands for people to copy & paste. Change-Id: Ia9fce5c0df9f51cbed9d49861adcf6821251e46f Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/466821 Tested-by: Mike Frysinger <[email protected]> Commit-Queue: Mike Frysinger <[email protected]> Reviewed-by: Gavin Mak <[email protected]>
1 parent daebd6c commit 0214730

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

release/util.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import os
1818
import re
19+
import shlex
1920
import subprocess
2021
import sys
2122

@@ -35,12 +36,7 @@
3536

3637
def cmdstr(cmd):
3738
"""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)
4440

4541

4642
def run(opts, cmd, check=True, **kwargs):

repo

+8-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,14 @@ class Trace:
5757
trace = Trace()
5858

5959

60+
def cmdstr(cmd):
61+
"""Get a nicely quoted shell command."""
62+
return " ".join(shlex.quote(x) for x in cmd)
63+
64+
6065
def exec_command(cmd):
6166
"""Execute |cmd| or return None on failure."""
62-
trace.print(":", " ".join(cmd))
67+
trace.print(":", cmdstr(cmd))
6368
try:
6469
if platform.system() == "Windows":
6570
ret = subprocess.call(cmd)
@@ -506,7 +511,7 @@ def run_command(cmd, **kwargs):
506511
# Run & package the results.
507512
proc = subprocess.Popen(cmd, **kwargs)
508513
(stdout, stderr) = proc.communicate(input=cmd_input)
509-
dbg = ": " + " ".join(cmd)
514+
dbg = ": " + cmdstr(cmd)
510515
if cmd_input is not None:
511516
dbg += " 0<|"
512517
if stdout == subprocess.PIPE:
@@ -843,7 +848,7 @@ def _GetRepoConfig(name):
843848
return None
844849
else:
845850
print(
846-
f"repo: error: git {' '.join(cmd)} failed:\n{ret.stderr}",
851+
f"repo: error: git {cmdstr(cmd)} failed:\n{ret.stderr}",
847852
file=sys.stderr,
848853
)
849854
# This will raise subprocess.CalledProcessError for us.

0 commit comments

Comments
 (0)