History

checkkconfigsymbols: use arglist instead of cmd string

Splitting a command string could lead to unintended arguments. Use an argument list in the execute() function instead.

Valentin Rothberg committed 10 years ago

Commit 2f9cc121 parent ef3f5541 file · +16 −11Browse files

Unified · Split

scripts/checkkconfigsymbols.py+16−11
@@ -149,11 +149,11 @@ def main(): · 148 unmodified lines
149149 undefined_b = {}
150150
151151 # get undefined items before the commit
152− execute("git reset --hard %s" % commit_a)
152+ reset(commit_a)
153153 undefined_a, _ = check_symbols(args.ignore)
154154
155155 # get undefined items for the commit
156− execute("git reset --hard %s" % commit_b)
156+ reset(commit_b)
157157 undefined_b, defined = check_symbols(args.ignore)
158158
159159 # report cases that are present for the commit but not before
@@ -170,7 +170,7 @@ def main(): · 10 unmodified lines
170170 undefined[symbol] = files
171171
172172 # reset to head
173− execute("git reset --hard %s" % head)
173+ reset(head)
174174
175175 # default to check the entire tree
176176 else:
@@ -202,6 +202,11 @@ def main(): · 25 unmodified lines
202202 print() # new line
203203
204204
205+def reset(commit):
206+ """Reset current git tree to %commit."""
207+ execute(["git", "reset", "--hard", commit])
208+
209+
205210 def yel(string):
206211 """
207212 Color %string yellow.
@@ -219,25 +224,25 @@ def red(string): · 11 unmodified lines
219224 def execute(cmd):
220225 """Execute %cmd and return stdout. Exit in case of error."""
221226 try:
222− cmdlist = cmd.split(" ")
223− stdout = subprocess.check_output(cmdlist, stderr=subprocess.STDOUT, shell=False)
227+ stdout = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=False)
224228 stdout = stdout.decode(errors='replace')
225229 except subprocess.CalledProcessError as fail:
226− exit("Failed to execute %s\n%s" % (cmd, fail))
230+ exit(fail)
227231 return stdout
228232
229233
230234 def find_commits(symbol, diff):
231235 """Find commits changing %symbol in the given range of %diff."""
232− commits = execute("git log --pretty=oneline --abbrev-commit -G %s %s"
233− % (symbol, diff))
236+ commits = execute(["git", "log", "--pretty=oneline",
237+ "--abbrev-commit", "-G",
238+ symbol, diff])
234239 return [x for x in commits.split("\n") if x]
235240
236241
237242 def tree_is_dirty():
238243 """Return true if the current working tree is dirty (i.e., if any file has
239244 been added, deleted, modified, renamed or copied but not committed)."""
240− stdout = execute("git status --porcelain")
245+ stdout = execute(["git", "status", "--porcelain"])
241246 for line in stdout:
242247 if re.findall(r"[URMADC]{1}", line[:2]):
243248 return True
@@ -246,7 +251,7 @@ def tree_is_dirty(): · 2 unmodified lines
246251
247252 def get_head():
248253 """Return commit hash of current HEAD."""
249− stdout = execute("git rev-parse HEAD")
254+ stdout = execute(["git", "rev-parse", "HEAD"])
250255 return stdout.strip('\n')
251256
252257
@@ -285,7 +290,7 @@ def find_sims(symbol, ignore, defined=[]): · 32 unmodified lines
285290 def get_files():
286291 """Return a list of all files in the current git directory."""
287292 # use 'git ls-files' to get the worklist
288− stdout = execute("git ls-files")
293+ stdout = execute(["git", "ls-files"])
289294 if len(stdout) > 0 and stdout[-1] == "\n":
290295 stdout = stdout[:-1]
291296