Commit d682fa4e authored by Josip Sokcevic's avatar Josip Sokcevic Committed by LUCI CQ

Add support for git_hyper_blame for Windows

Change-Id: I8cfbc013b4f17d727b65313e9e4823bab5d9ac18
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2113553Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
parent 8f41598a
......@@ -258,6 +258,7 @@ def approx_lineno_across_revs(filename, newfilename, revision, newrevision,
def hyper_blame(outbuf, ignored, filename, revision):
# Map from commit to parsed blame from that commit.
blame_from = {}
filename = os.path.normpath(filename)
def cache_blame_from(filename, commithash):
try:
......@@ -315,7 +316,8 @@ def hyper_blame(outbuf, ignored, filename, revision):
# If any line has a different filename to the file's current name, turn on
# filename display for the entire blame output.
if line.commit.filename != filename:
# Use normpath to make variable consistent across platforms.
if os.path.normpath(line.commit.filename) != filename:
show_filenames = True
new_parsed.append(line)
......
......@@ -9,11 +9,14 @@ import datetime
import hashlib
import os
import shutil
# Do not use subprocess2 as we won't be able to test encoding failures
import subprocess
import sys
import tempfile
import unittest
import gclient_utils
if sys.version_info.major == 3:
# pylint: disable=redefined-builtin
......@@ -260,7 +263,7 @@ class GitRepo(object):
For file content, if 'data' is None, then this commit will `git rm` that file.
"""
BASE_TEMP_DIR = tempfile.mkdtemp(suffix='base', prefix='git_repo')
atexit.register(shutil.rmtree, BASE_TEMP_DIR)
atexit.register(gclient_utils.rmtree, BASE_TEMP_DIR)
# Singleton objects to specify specific data in a commit dictionary.
AUTHOR_NAME = object()
......@@ -382,8 +385,13 @@ class GitRepo(object):
assert self.repo_path is not None
try:
with open(os.devnull, 'wb') as devnull:
shell = sys.platform == 'win32'
output = subprocess.check_output(
('git',) + args, cwd=self.repo_path, stderr=devnull, **kwargs)
('git', ) + args,
shell=shell,
cwd=self.repo_path,
stderr=devnull,
**kwargs)
output = output.decode('utf-8')
return self.COMMAND_OUTPUT(0, output)
except subprocess.CalledProcessError as e:
......@@ -402,7 +410,7 @@ class GitRepo(object):
Causes this GitRepo to be unusable.
"""
shutil.rmtree(self.repo_path)
gclient_utils.rmtree(self.repo_path)
self.repo_path = None
def run(self, fn, *args, **kwargs):
......
......@@ -132,8 +132,8 @@ class GitHyperBlameMainTest(GitHyperBlameTestBase):
retval = self.git_hyper_blame.main(
['-i', 'tag_B', 'tag_C', 'some/files/file'], outbuf)
finally:
shutil.rmtree(tempdir)
os.chdir(curdir)
shutil.rmtree(tempdir)
self.assertNotEqual(0, retval)
self.assertEqual(b'', outbuf.getvalue())
......@@ -590,16 +590,29 @@ class GitHyperBlameUnicodeTest(GitHyperBlameTestBase):
# Add a line.
COMMIT_B = {
GitRepo.AUTHOR_NAME: '\u4e2d\u56fd\u4f5c\u8005'.encode('utf-8'),
'file': {'data': b'red\ngreen\nblue\n'},
# AUTHOR_NAME has .encode('utf-8') for py2 as Windows raises exception
# otherwise. Type remains str
GitRepo.AUTHOR_NAME:
('\u4e2d\u56fd\u4f5c\u8005'.encode('utf-8')
if sys.version_info.major == 2 else '\u4e2d\u56fd\u4f5c\u8005'),
'file': {
'data': b'red\ngreen\nblue\n'
},
}
# Modify a line with non-UTF-8 author and file text.
COMMIT_C = {
GitRepo.AUTHOR_NAME: 'Lat\u00edn-1 Author'.encode('latin-1'),
'file': {'data': 'red\ngre\u00e9n\nblue\n'.encode('latin-1')},
GitRepo.AUTHOR_NAME:
('Lat\u00edn-1 Author'.encode('latin-1')
if sys.version_info.major == 2 else 'Lat\xedn-1 Author'),
'file': {
'data': 'red\ngre\u00e9n\nblue\n'.encode('latin-1')
},
}
@unittest.skipIf(
sys.platform.startswith("win") and sys.version_info.major == 2,
"Known issue for Windows and py2")
def testNonASCIIAuthorName(self):
"""Ensures correct tabulation.
......@@ -607,7 +620,11 @@ class GitHyperBlameUnicodeTest(GitHyperBlameTestBase):
name.
Regression test for https://crbug.com/808905.
This test is disabled only for Windows and Python2 as `author` gets escaped
differently.
"""
# Known issue with Windows and py2, skip test for such env
expected_output = [
self.blame_line('A', '1) red', author='ASCII Author'),
# Expect 8 spaces, to line up with the other name.
......
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