From f307916f22c633d9d918158bd13f4bced581af17 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 16 Feb 2021 02:38:21 -0500 Subject: [PATCH] git_command: use subprocess.run for version info The code is a bit simpler & easier to reason about. Change-Id: If125ea7d776cdfa38a0440a2b03583de079c4839 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/297023 Reviewed-by: Michael Mortensen Tested-by: Mike Frysinger --- git_command.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/git_command.py b/git_command.py index 2b3975ec..51e856a8 100644 --- a/git_command.py +++ b/git_command.py @@ -162,11 +162,10 @@ def RepoSourceVersion(): proj = os.path.dirname(os.path.abspath(__file__)) env[GIT_DIR] = os.path.join(proj, '.git') - - p = subprocess.Popen([GIT, 'describe', HEAD], stdout=subprocess.PIPE, - env=env) - if p.wait() == 0: - ver = p.stdout.read().strip().decode('utf-8') + result = subprocess.run([GIT, 'describe', HEAD], stdout=subprocess.PIPE, + encoding='utf-8', env=env, check=False) + if result.returncode == 0: + ver = result.stdout.strip() if ver.startswith('v'): ver = ver[1:] else: