mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
Revert "Reland "Refactor git functionality out of Change and _DiffCache""
This reverts commit4d2864f3a1. Reason for revert: This still doesn't scale well with large commit: https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket/8756578662173359185/+/u/presubmit/stdout?format=raw This is now a different instruction called repeatedly needlessly: ``` git -c core.quotePath=false diff -p --no-color --no-prefix --no-ext-diff f0b151b0e519ceb3efae2ad8951d8a9ce86e4fbd...HEAD --no-renames; cwd=D:\b\s\w\ir\cache\builder\win_presubmit\src ``` called for each affected files. We probably want to cache the output for this too? Original change's description: > Reland "Refactor git functionality out of Change and _DiffCache" > > This is a reland of commitdd1a596c3e> > It is not a pure reland and adds support for caching submodules. > > Original change's description: > > Refactor git functionality out of Change and _DiffCache > > > > A followup change will add support for change diff provided as user > > input through stdin/file. > > > > Bug: b/323243527 > > Change-Id: I8d3420370e134859c61e35e23d76803227e4a506 > > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5254364 > > Reviewed-by: Joanna Wang <jojwang@chromium.org> > > Commit-Queue: Gavin Mak <gavinmak@google.com> > > Reviewed-by: Josip Sokcevic <sokcevic@chromium.org> > > Bug: b/323243527 > Change-Id: I74bbb179d4cbda7431101a2d707131fab2093029 > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5280620 > Reviewed-by: Josip Sokcevic <sokcevic@chromium.org> > Commit-Queue: Gavin Mak <gavinmak@google.com> Bug: b/323243527, b/324293047 Change-Id: Iffde46facefa9d2e3a0d3a9ab5f8e753c53ea6d4 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5272317 Auto-Submit: Arthur Sonzogni <arthursonzogni@google.com> Reviewed-by: Gavin Mak <gavinmak@google.com> Commit-Queue: Gavin Mak <gavinmak@google.com> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
This commit is contained in:
@@ -880,7 +880,7 @@ class InputApi(object):
|
||||
|
||||
def ListSubmodules(self):
|
||||
"""Returns submodule paths for current change's repo."""
|
||||
return self.change._repo_submodules()
|
||||
return scm.GIT.ListSubmodules(self.change.RepositoryRoot())
|
||||
|
||||
@property
|
||||
def tbr(self):
|
||||
@@ -912,6 +912,9 @@ class InputApi(object):
|
||||
|
||||
class _DiffCache(object):
|
||||
"""Caches diffs retrieved from a particular SCM."""
|
||||
def __init__(self, upstream=None):
|
||||
"""Stores the upstream revision against which all diffs will be computed."""
|
||||
self._upstream = upstream
|
||||
|
||||
def GetDiff(self, path, local_root):
|
||||
"""Get the diff for a particular path."""
|
||||
@@ -924,11 +927,8 @@ class _DiffCache(object):
|
||||
|
||||
class _GitDiffCache(_DiffCache):
|
||||
"""DiffCache implementation for git; gets all file diffs at once."""
|
||||
|
||||
def __init__(self, upstream):
|
||||
"""Stores the upstream revision against which all diffs are computed."""
|
||||
super(_GitDiffCache, self).__init__()
|
||||
self._upstream = upstream
|
||||
super(_GitDiffCache, self).__init__(upstream=upstream)
|
||||
self._diffs_by_file = None
|
||||
|
||||
def GetDiff(self, path, local_root):
|
||||
@@ -1138,13 +1138,21 @@ class Change(object):
|
||||
'^[ \t]*(?P<key>[A-Z][A-Z_0-9]*)[ \t]*=[ \t]*(?P<value>.*?)[ \t]*$')
|
||||
scm = ''
|
||||
|
||||
def __init__(self, name, description, local_root, files, issue, patchset,
|
||||
author):
|
||||
def __init__(self,
|
||||
name,
|
||||
description,
|
||||
local_root,
|
||||
files,
|
||||
issue,
|
||||
patchset,
|
||||
author,
|
||||
upstream=None):
|
||||
if files is None:
|
||||
files = []
|
||||
self._name = name
|
||||
# Convert root into an absolute path.
|
||||
self._local_root = os.path.abspath(local_root)
|
||||
self._upstream = upstream
|
||||
self.issue = issue
|
||||
self.patchset = patchset
|
||||
self.author_email = author
|
||||
@@ -1157,13 +1165,15 @@ class Change(object):
|
||||
assert all((isinstance(f, (list, tuple)) and len(f) == 2)
|
||||
for f in files), files
|
||||
|
||||
diff_cache = self._AFFECTED_FILES.DIFF_CACHE(self._upstream)
|
||||
self._affected_files = [
|
||||
self._AFFECTED_FILES(path, action.strip(), self._local_root,
|
||||
self._diff_cache()) for action, path in files
|
||||
diff_cache) for action, path in files
|
||||
]
|
||||
|
||||
def _diff_cache(self):
|
||||
return self._AFFECTED_FILES.DIFF_CACHE()
|
||||
def UpstreamBranch(self):
|
||||
"""Returns the upstream branch for the change."""
|
||||
return self._upstream
|
||||
|
||||
def Name(self):
|
||||
"""Returns the change name."""
|
||||
@@ -1300,22 +1310,29 @@ class Change(object):
|
||||
Returns:
|
||||
[AffectedFile(path, action), AffectedFile(path, action)]
|
||||
"""
|
||||
affected = list(filter(file_filter, self._affected_files))
|
||||
submodule_list = scm.GIT.ListSubmodules(self.RepositoryRoot())
|
||||
files = [
|
||||
af for af in self._affected_files
|
||||
if af.LocalPath() not in submodule_list
|
||||
]
|
||||
affected = list(filter(file_filter, files))
|
||||
|
||||
if include_deletes:
|
||||
return affected
|
||||
return list(filter(lambda x: x.Action() != 'D', affected))
|
||||
|
||||
def AffectedSubmodules(self):
|
||||
"""Returns a list of AffectedFile instances for submodules in the change.
|
||||
|
||||
There is no SCM and no submodules, so return an empty list.
|
||||
"""
|
||||
return []
|
||||
"""Returns a list of AffectedFile instances for submodules in the change."""
|
||||
submodule_list = scm.GIT.ListSubmodules(self.RepositoryRoot())
|
||||
return [
|
||||
af for af in self._affected_files
|
||||
if af.LocalPath() in submodule_list
|
||||
]
|
||||
|
||||
def AffectedTestableFiles(self, include_deletes=None, **kwargs):
|
||||
"""Return a list of the existing text files in a change."""
|
||||
if include_deletes is not None:
|
||||
warn('AffectedTestableFiles(include_deletes=%s)'
|
||||
warn('AffectedTeestableFiles(include_deletes=%s)'
|
||||
' is deprecated and ignored' % str(include_deletes),
|
||||
category=DeprecationWarning,
|
||||
stacklevel=2)
|
||||
@@ -1369,38 +1386,11 @@ class Change(object):
|
||||
files = self.AffectedFiles(file_filter=owners_file_filter)
|
||||
return {f.LocalPath(): f.OldContents() for f in files}
|
||||
|
||||
def _repo_submodules(self):
|
||||
"""Returns submodule paths for current change's repo.
|
||||
|
||||
There is no SCM, so return an empty list.
|
||||
"""
|
||||
return []
|
||||
|
||||
|
||||
class GitChange(Change):
|
||||
_AFFECTED_FILES = GitAffectedFile
|
||||
scm = 'git'
|
||||
|
||||
def __init__(self, *args, upstream, **kwargs):
|
||||
self._upstream = upstream
|
||||
super(GitChange, self).__init__(*args)
|
||||
|
||||
# List of submodule paths in the repo.
|
||||
self._submodules = None
|
||||
|
||||
def _diff_cache(self):
|
||||
return self._AFFECTED_FILES.DIFF_CACHE(self._upstream)
|
||||
|
||||
def _repo_submodules(self):
|
||||
"""Returns submodule paths for current change's repo."""
|
||||
if not self._submodules:
|
||||
self._submodules = scm.GIT.ListSubmodules(self.RepositoryRoot())
|
||||
return self._submodules
|
||||
|
||||
def UpstreamBranch(self):
|
||||
"""Returns the upstream branch for the change."""
|
||||
return self._upstream
|
||||
|
||||
def AllFiles(self, root=None):
|
||||
"""List all files under source control in the repo."""
|
||||
root = root or self.RepositoryRoot()
|
||||
@@ -1408,33 +1398,6 @@ class GitChange(Change):
|
||||
['git', '-c', 'core.quotePath=false', 'ls-files', '--', '.'],
|
||||
cwd=root).decode('utf-8', 'ignore').splitlines()
|
||||
|
||||
def AffectedFiles(self, include_deletes=True, file_filter=None):
|
||||
"""Returns a list of AffectedFile instances for all files in the change.
|
||||
|
||||
Args:
|
||||
include_deletes: If false, deleted files will be filtered out.
|
||||
file_filter: An additional filter to apply.
|
||||
|
||||
Returns:
|
||||
[AffectedFile(path, action), AffectedFile(path, action)]
|
||||
"""
|
||||
files = [
|
||||
af for af in self._affected_files
|
||||
if af.LocalPath() not in self._repo_submodules()
|
||||
]
|
||||
affected = list(filter(file_filter, files))
|
||||
|
||||
if include_deletes:
|
||||
return affected
|
||||
return list(filter(lambda x: x.Action() != 'D', affected))
|
||||
|
||||
def AffectedSubmodules(self):
|
||||
"""Returns a list of AffectedFile instances for submodules in the change."""
|
||||
return [
|
||||
af for af in self._affected_files
|
||||
if af.LocalPath() in self._repo_submodules()
|
||||
]
|
||||
|
||||
|
||||
def ListRelevantPresubmitFiles(files, root):
|
||||
"""Finds all presubmit files that apply to a given set of source files.
|
||||
@@ -2017,13 +1980,15 @@ def _parse_change(parser, options):
|
||||
ignore_submodules=False)
|
||||
logging.info('Found %d file(s).', len(change_files))
|
||||
|
||||
change_args = [
|
||||
options.name, options.description, options.root, change_files,
|
||||
options.issue, options.patchset, options.author
|
||||
]
|
||||
if change_scm == 'git':
|
||||
return GitChange(*change_args, upstream=options.upstream)
|
||||
return Change(*change_args)
|
||||
change_class = GitChange if change_scm == 'git' else Change
|
||||
return change_class(options.name,
|
||||
options.description,
|
||||
options.root,
|
||||
change_files,
|
||||
options.issue,
|
||||
options.patchset,
|
||||
options.author,
|
||||
upstream=options.upstream)
|
||||
|
||||
|
||||
def _parse_gerrit_options(parser, options):
|
||||
|
||||
Reference in New Issue
Block a user