Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project.git(list/str): reduce reliance on shlex.split() #683

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/west/app/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ def has_checked_out_branch(project):
if self.ignore_branches:
return False

return bool(project.git('branch --show-current',
return bool(project.git(['branch', '--show-current'],
capture_stdout=True,
capture_stderr=True).stdout.strip())

Expand Down Expand Up @@ -1228,7 +1228,7 @@ def update(self, project):
# out the new detached HEAD, then print some helpful context.
if take_stats:
start = perf_counter()
project.git('checkout --detach ' + sha)
project.git(['checkout', '--detach', sha])
if take_stats:
stats['checkout new manifest-rev'] = perf_counter() - start
self.post_checkout_help(project, current_branch,
Expand Down Expand Up @@ -1320,7 +1320,7 @@ def init_project(self, project):
# This remote is added as a convenience for the user.
# However, west always fetches project data by URL, not name.
# The user is therefore free to change the URL of this remote.
project.git(f'remote add -- {project.remote_name} {project.url}')
project.git(['remote', 'add', '--', project.remote_name, project.url])
else:
self.small_banner(f'{project.name}: cloning from {cache_dir}')
# Clone the project from a local cache repository. Set the
Expand Down Expand Up @@ -1891,14 +1891,14 @@ def _clean_west_refspace(project):
# Clean the refs/west space to ensure they do not show up in 'git log'.

# Get all the ref names that start with refs/west/.
list_refs_cmd = ('for-each-ref --format="%(refname)" -- ' +
QUAL_REFS + '**')
list_refs_cmd = ['for-each-ref', '--format=%(refname)', '--',
QUAL_REFS + '**']
cp = project.git(list_refs_cmd, capture_stdout=True)
west_references = cp.stdout.decode('utf-8').strip()

# Safely delete each one.
for ref in west_references.splitlines():
delete_ref_cmd = 'update-ref -d ' + ref
delete_ref_cmd = ['update-ref', '-d', ref]
project.git(delete_ref_cmd)

def _update_manifest_rev(project, new_manifest_rev):
Expand Down
4 changes: 2 additions & 2 deletions src/west/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ def sha(self, rev: str, cwd: Optional[PathType] = None) -> str:
# Though we capture stderr, it will be available as the stderr
# attribute in the CalledProcessError raised by git() in
# Python 3.5 and above if this call fails.
cp = self.git(f'rev-parse {rev}^{{commit}}', capture_stdout=True,
cp = self.git(['rev-parse', f'{rev}^{{commit}}'], capture_stdout=True,
cwd=cwd, capture_stderr=True)
# Assumption: SHAs are hex values and thus safe to decode in ASCII.
# It'll be fun when we find out that was wrong and how...
Expand Down Expand Up @@ -1023,7 +1023,7 @@ def is_cloned(self, cwd: Optional[PathType] = None) -> bool:
# instead, which prints an empty string (i.e., just a newline,
# which we strip) for the top-level directory.
_logger.debug(f'{self.name}: checking if cloned')
res = self.git('rev-parse --show-cdup', check=False, cwd=cwd,
res = self.git(['rev-parse', '--show-cdup'], check=False, cwd=cwd,
capture_stderr=True, capture_stdout=True)

return not (res.returncode or res.stdout.strip())
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ envlist=py3
ignore = E126,E261,E302,E305,W504
# Don't lint setup.py, the .tox virtualenv directory, or the build directory
exclude = setup.py,.tox,build
max-line-length = 100

[mypy]
mypy_path=src
Expand Down
Loading