Commit cd862e37 authored by Raul Tambre's avatar Raul Tambre Committed by Commit Bot

gclient_scm: Decode Git output centrally for better Python 3 support

This avoids the need to do the decoding everywhere separately.
Also a small fix for filter() no longer returning a list on Py3.

The scripts still work with Python 2.
There are no intended behaviour changes.

Bug: 942522
Change-Id: Id0f5153011b2ef1b64394359087864cd9434e45e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1595685
Commit-Queue: Dirk Pranke <dpranke@chromium.org>
Auto-Submit: Raul Tambre <raul@tambre.ee>
Reviewed-by: 's avatarDirk Pranke <dpranke@chromium.org>
parent 059f26bc
......@@ -256,9 +256,10 @@ class GitWrapper(SCMWrapper):
def _GetDiffFilenames(self, base):
"""Returns the names of files modified since base."""
return self._Capture(
# Filter to remove base if it is None.
filter(bool, ['-c', 'core.quotePath=false', 'diff', '--name-only', base])
).split()
# Filter to remove base if it is None.
list(filter(bool, ['-c', 'core.quotePath=false', 'diff', '--name-only',
base])
)).split()
def diff(self, options, _args, _file_list):
_, revision = gclient_utils.SplitUrlRevision(self.url)
......@@ -630,7 +631,7 @@ class GitWrapper(SCMWrapper):
# Skip url auto-correction if remote.origin.gclient-auto-fix-url is set.
# This allows devs to use experimental repos which have a different url
# but whose branch(s) are the same as official repos.
if (current_url.rstrip(b'/') != url.rstrip('/') and url != 'git://foo' and
if (current_url.rstrip('/') != url.rstrip('/') and url != 'git://foo' and
subprocess2.capture(
['git', 'config', 'remote.%s.gclient-auto-fix-url' % self.remote],
cwd=self.checkout_path).strip() != 'False'):
......@@ -1306,7 +1307,8 @@ class GitWrapper(SCMWrapper):
kwargs.setdefault('stderr', subprocess2.PIPE)
strip = kwargs.pop('strip', True)
env = scm.GIT.ApplyEnvVars(kwargs)
ret = subprocess2.check_output(['git'] + args, env=env, **kwargs)
ret = subprocess2.check_output(
['git'] + args, env=env, **kwargs).decode('utf-8')
if strip:
ret = ret.strip()
return ret
......
......@@ -117,8 +117,8 @@ class GIT(object):
def Capture(args, cwd, strip_out=True, **kwargs):
env = GIT.ApplyEnvVars(kwargs)
output = subprocess2.check_output(
['git'] + args,
cwd=cwd, stderr=subprocess2.PIPE, env=env, **kwargs)
['git'] + args, cwd=cwd, stderr=subprocess2.PIPE, env=env,
**kwargs).decode('utf-8')
return output.strip() if strip_out else output
@staticmethod
......@@ -388,7 +388,7 @@ class GIT(object):
"""Asserts git's version is at least min_version."""
if cls.current_version is None:
current_version = cls.Capture(['--version'], '.')
matched = re.search(r'version ([0-9\.]+)', current_version.decode())
matched = re.search(r'version ([0-9\.]+)', current_version)
cls.current_version = matched.group(1)
current_version_list = list(map(only_int, cls.current_version.split('.')))
for min_ver in map(int, min_version.split('.')):
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
......@@ -140,7 +141,7 @@ class FakeReposBase(object):
# Hostname
NB_GIT_REPOS = 1
USERS = [
('user1@example.com', 'foo'),
('user1@example.com', 'foo Fuß'),
('user2@example.com', 'bar'),
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment