bisect-kit: make git_util.get_file_from_revision faster
On a machine with slow disk io, this change could reduce
bisect_cr_localbuild_internal.py init time from 59 to 55 minutes.
BUG=b:157446351
TEST=./bisect_cr_localbuild_internal.py init --old 84.0.4142.0 --new 84.0.4147.0
Change-Id: Idd994cf948255939d3c3ec767bf52b13dd5f452f
diff --git a/bisect_kit/git_util.py b/bisect_kit/git_util.py
index 1d565d7..ed10db4 100644
--- a/bisect_kit/git_util.py
+++ b/bisect_kit/git_util.py
@@ -352,6 +352,7 @@
ValueError if not found
"""
# format: 120000 blob 8735a8c1dd96ede39a21d983d5c96792fd15c1a5 default.xml
+ # TODO(kcwu): handle escaped path with special characters
splitted = util.check_output(
'git', 'ls-tree', rev, '--full-name', path, cwd=git_repo).split()
if len(splitted) >= 4 and splitted[3] == path:
@@ -374,8 +375,14 @@
"""
result = util.check_output(
'git', 'show', '%s:%s' % (rev, path), cwd=git_repo, log_stdout=False)
- if is_symbolic_link(git_repo, rev, path):
+
+ # It might be a symbolic link.
+ # In extreme case, it's possible that filenames contain special characters,
+ # like newlines. In practice, it should be safe to assume no such cases and
+ # reduce disk i/o.
+ if '\n' not in result and is_symbolic_link(git_repo, rev, path):
return get_file_from_revision(git_repo, rev, result)
+
return result