git-cache: Decode subprocess.check_output

Always decode subprocess.check_output.

Bug: 1064547
Change-Id: I459a236235a2355f9dd9813dafc12dff44866529
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2120966
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
changes/66/2120966/5
Edward Lesmes 6 years ago committed by LUCI CQ
parent e2ac022f0b
commit 4c3eb70358

@ -301,7 +301,7 @@ class Mirror(object):
cachepath = subprocess.check_output( cachepath = subprocess.check_output(
[cls.git_exe, 'config'] + [cls.git_exe, 'config'] +
cls._GIT_CONFIG_LOCATION + cls._GIT_CONFIG_LOCATION +
['cache.cachepath']).strip() ['cache.cachepath']).decode('utf-8', 'ignore').strip()
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
cachepath = os.environ.get('GIT_CACHE_PATH', cls.UNSET_CACHEPATH) cachepath = os.environ.get('GIT_CACHE_PATH', cls.UNSET_CACHEPATH)
setattr(cls, 'cachepath', cachepath) setattr(cls, 'cachepath', cachepath)
@ -472,7 +472,7 @@ class Mirror(object):
try: try:
config_fetchspecs = subprocess.check_output( config_fetchspecs = subprocess.check_output(
[self.git_exe, 'config', '--get-all', 'remote.origin.fetch'], [self.git_exe, 'config', '--get-all', 'remote.origin.fetch'],
cwd=self.mirror_path) cwd=self.mirror_path).decode('utf-8', 'ignore')
for fetchspec in config_fetchspecs.splitlines(): for fetchspec in config_fetchspecs.splitlines():
self.fetch_specs.add(self.parse_fetch_spec(fetchspec)) self.fetch_specs.add(self.parse_fetch_spec(fetchspec))
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
@ -541,9 +541,8 @@ class Mirror(object):
fetch_cmd = ['fetch'] + v + d + t + ['origin'] fetch_cmd = ['fetch'] + v + d + t + ['origin']
fetch_specs = subprocess.check_output( fetch_specs = subprocess.check_output(
[self.git_exe, 'config', '--get-all', 'remote.origin.fetch'], [self.git_exe, 'config', '--get-all', 'remote.origin.fetch'],
cwd=rundir).strip().splitlines() cwd=rundir).decode('utf-8', 'ignore').strip().splitlines()
for spec in fetch_specs: for spec in fetch_specs:
spec = spec.decode()
try: try:
self.print('Fetching %s' % spec) self.print('Fetching %s' % spec)
with self.print_duration_of('fetch %s' % spec): with self.print_duration_of('fetch %s' % spec):
@ -589,7 +588,8 @@ class Mirror(object):
def update_bootstrap(self, prune=False, gc_aggressive=False): def update_bootstrap(self, prune=False, gc_aggressive=False):
# The folder is <git number> # The folder is <git number>
gen_number = subprocess.check_output( gen_number = subprocess.check_output(
[self.git_exe, 'number', 'master'], cwd=self.mirror_path).strip() [self.git_exe, 'number', 'master'],
cwd=self.mirror_path).decode('utf-8', 'ignore').strip()
gsutil = Gsutil(path=self.gsutil_exe, boto_path=None) gsutil = Gsutil(path=self.gsutil_exe, boto_path=None)
src_name = self.mirror_path src_name = self.mirror_path
@ -809,16 +809,18 @@ def CMDfetch(parser, args):
remotes = [] remotes = []
if options.all: if options.all:
assert not args, 'fatal: fetch --all does not take a repository argument' assert not args, 'fatal: fetch --all does not take a repository argument'
remotes = subprocess.check_output([Mirror.git_exe, 'remote']).splitlines() remotes = subprocess.check_output([Mirror.git_exe, 'remote'])
remotes = remotes.decode('utf-8', 'ignore').splitlines()
elif args: elif args:
remotes = args remotes = args
else: else:
current_branch = subprocess.check_output( current_branch = subprocess.check_output(
[Mirror.git_exe, 'rev-parse', '--abbrev-ref', 'HEAD']).strip() [Mirror.git_exe, 'rev-parse', '--abbrev-ref', 'HEAD'])
current_branch = current_branch.decode('utf-8', 'ignore').strip()
if current_branch != 'HEAD': if current_branch != 'HEAD':
upstream = subprocess.check_output( upstream = subprocess.check_output(
[Mirror.git_exe, 'config', 'branch.%s.remote' % current_branch] [Mirror.git_exe, 'config', 'branch.%s.remote' % current_branch])
).strip() upstream = upstream.decode('utf-8', 'ignore').strip()
if upstream and upstream != '.': if upstream and upstream != '.':
remotes = [upstream] remotes = [upstream]
if not remotes: if not remotes:
@ -826,7 +828,7 @@ def CMDfetch(parser, args):
cachepath = Mirror.GetCachePath() cachepath = Mirror.GetCachePath()
git_dir = os.path.abspath(subprocess.check_output( git_dir = os.path.abspath(subprocess.check_output(
[Mirror.git_exe, 'rev-parse', '--git-dir'])) [Mirror.git_exe, 'rev-parse', '--git-dir']).decode('utf-8', 'ignore'))
git_dir = os.path.abspath(git_dir) git_dir = os.path.abspath(git_dir)
if git_dir.startswith(cachepath): if git_dir.startswith(cachepath):
mirror = Mirror.FromPath(git_dir) mirror = Mirror.FromPath(git_dir)
@ -837,7 +839,8 @@ def CMDfetch(parser, args):
return 0 return 0
for remote in remotes: for remote in remotes:
remote_url = subprocess.check_output( remote_url = subprocess.check_output(
[Mirror.git_exe, 'config', 'remote.%s.url' % remote]).strip() [Mirror.git_exe, 'config', 'remote.%s.url' % remote])
remote_url = remote_url.decode('utf-8', 'ignore').strip()
if remote_url.startswith(cachepath): if remote_url.startswith(cachepath):
mirror = Mirror.FromPath(remote_url) mirror = Mirror.FromPath(remote_url)
mirror.print = lambda *args: None mirror.print = lambda *args: None

@ -152,7 +152,7 @@ class GitCacheDirTest(unittest.TestCase):
git_cache.Mirror._GIT_CONFIG_LOCATION = ['-f', tmpFile] git_cache.Mirror._GIT_CONFIG_LOCATION = ['-f', tmpFile]
self.assertEqual(git_cache.Mirror.GetCachePath(), b'hello world') self.assertEqual(git_cache.Mirror.GetCachePath(), 'hello world')
finally: finally:
git_cache.Mirror._GIT_CONFIG_LOCATION = old git_cache.Mirror._GIT_CONFIG_LOCATION = old
os.remove(tmpFile) os.remove(tmpFile)

Loading…
Cancel
Save