Provide useful submodule info for all Change classes

GitChange uses 'scm.GIT.ListSubmodules' to filter out files under repo
root that belong to a submodule. ProvidedDiffChange does not use this
so doesn't filter out submoduled files.

'scm.GIT.ListSubmodules' just reads '.gitmodules' at repo root and
can be run outside a git workspace. Use this to provide useful
submodule info for Change/ProvidedDiffChange.

Bug: b/333744051
Change-Id: Idaead11c69681e86276a29b0dc58090e7c4ec2c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5466527
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Gavin Mak <gavinmak@google.com>
changes/27/5466527/3
Gavin Mak 2 years ago committed by LUCI CQ
parent 55774b24e6
commit 1a61eb625d

@ -1199,6 +1199,9 @@ class Change(object):
self._description_without_tags = '' self._description_without_tags = ''
self.SetDescriptionText(description) self.SetDescriptionText(description)
# List of submodule paths in the repo.
self._submodules = None
assert all((isinstance(f, (list, tuple)) and len(f) == 2) assert all((isinstance(f, (list, tuple)) and len(f) == 2)
for f in files), files for f in files), files
@ -1359,11 +1362,11 @@ class Change(object):
return list(filter(lambda x: x.Action() != 'D', affected)) return list(filter(lambda x: x.Action() != 'D', affected))
def AffectedSubmodules(self): def AffectedSubmodules(self):
"""Returns a list of AffectedFile instances for submodules in the change. """Returns a list of AffectedFile instances for submodules in the change."""
return [
There is no SCM and no submodules, so return an empty list. af for af in self._affected_files
""" if af.LocalPath() in self._repo_submodules()
return [] ]
def AffectedTestableFiles(self, include_deletes=None, **kwargs): def AffectedTestableFiles(self, include_deletes=None, **kwargs):
"""Return a list of the existing text files in a change.""" """Return a list of the existing text files in a change."""
@ -1423,11 +1426,10 @@ class Change(object):
return {f.LocalPath(): f.OldContents() for f in files} return {f.LocalPath(): f.OldContents() for f in files}
def _repo_submodules(self): def _repo_submodules(self):
"""Returns submodule paths for current change's repo. """Returns submodule paths for current change's repo."""
if not self._submodules:
There is no SCM, so return an empty list. self._submodules = scm.GIT.ListSubmodules(self.RepositoryRoot())
""" return self._submodules
return []
class GitChange(Change): class GitChange(Change):
@ -1438,18 +1440,9 @@ class GitChange(Change):
self._upstream = upstream self._upstream = upstream
super(GitChange, self).__init__(*args) super(GitChange, self).__init__(*args)
# List of submodule paths in the repo.
self._submodules = None
def _diff_cache(self): def _diff_cache(self):
return self._AFFECTED_FILES.DIFF_CACHE(self._upstream) 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): def UpstreamBranch(self):
"""Returns the upstream branch for the change.""" """Returns the upstream branch for the change."""
return self._upstream return self._upstream
@ -1481,13 +1474,6 @@ class GitChange(Change):
return affected return affected
return list(filter(lambda x: x.Action() != 'D', 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()
]
class ProvidedDiffChange(Change): class ProvidedDiffChange(Change):
_AFFECTED_FILES = ProvidedDiffAffectedFile _AFFECTED_FILES = ProvidedDiffAffectedFile

Loading…
Cancel
Save