From cd862e37ea2953271923618ba5321c794b74867b Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Fri, 10 May 2019 21:19:00 +0000 Subject: [PATCH] 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 Auto-Submit: Raul Tambre Reviewed-by: Dirk Pranke --- gclient_scm.py | 12 +++++++----- scm.py | 6 +++--- testing_support/fake_repos.py | 3 ++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/gclient_scm.py b/gclient_scm.py index efb69504f..e940a69d2 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -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 diff --git a/scm.py b/scm.py index 102f77d19..46c25a720 100644 --- a/scm.py +++ b/scm.py @@ -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('.')): diff --git a/testing_support/fake_repos.py b/testing_support/fake_repos.py index 16afc30e3..01b534677 100755 --- a/testing_support/fake_repos.py +++ b/testing_support/fake_repos.py @@ -1,4 +1,5 @@ #!/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'), ]