mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 02:31:29 +00:00
Fix CheckForCommitObjects to check missing gitlink changes
https://crrev.com/c/7234371 made some optimizations to the check but caused it to start missing changes that modified DEPS but not the corresponding gitlink. Fix the check by doing a full tree scan when DEPS is updated. Bug: 469784282 Change-Id: Ibdcdcb1af5a330e4d9e96daecd28e06bc1436022 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7362007 Reviewed-by: Yiwei Zhang <yiwzhang@google.com> Reviewed-by: Josiah Kiehl <kiehl@google.com> Commit-Queue: Gavin Mak <gavinmak@google.com>
This commit is contained in:
@@ -2081,8 +2081,13 @@ def CheckForCommitObjects(input_api, output_api):
|
|||||||
# If the number of affected files is small, we can avoid scanning the entire
|
# If the number of affected files is small, we can avoid scanning the entire
|
||||||
# tree.
|
# tree.
|
||||||
affected_files = list(input_api.AffectedFiles())
|
affected_files = list(input_api.AffectedFiles())
|
||||||
|
|
||||||
|
# We must scan the full tree if DEPS is modified to ensure that any change
|
||||||
|
# in DEPS is reflected in the gitlinks.
|
||||||
|
deps_modified = any(f.LocalPath() == 'DEPS' for f in affected_files)
|
||||||
|
|
||||||
cmd = ['git', 'ls-tree', '-z', '--full-tree', 'HEAD']
|
cmd = ['git', 'ls-tree', '-z', '--full-tree', 'HEAD']
|
||||||
if len(affected_files) < 1000:
|
if len(affected_files) < 1000 and not deps_modified:
|
||||||
# We need to pass the paths relative to the repository root.
|
# We need to pass the paths relative to the repository root.
|
||||||
repo_root = input_api.change.RepositoryRoot()
|
repo_root = input_api.change.RepositoryRoot()
|
||||||
files_to_check = [
|
files_to_check = [
|
||||||
|
|||||||
@@ -14,6 +14,18 @@ import presubmit_canned_checks
|
|||||||
from testing_support.presubmit_canned_checks_test_mocks import MockInputApi, MockOutputApi, MockFile
|
from testing_support.presubmit_canned_checks_test_mocks import MockInputApi, MockOutputApi, MockFile
|
||||||
|
|
||||||
|
|
||||||
|
class MockRelativeFile(MockFile):
|
||||||
|
|
||||||
|
def __init__(self, rel_path, new_contents):
|
||||||
|
# We pass absolute path to super so AbsoluteLocalPath returns absolute path
|
||||||
|
abs_path = os.path.join('/tmp/repo', rel_path)
|
||||||
|
super(MockRelativeFile, self).__init__(abs_path, new_contents)
|
||||||
|
self._rel_path = rel_path
|
||||||
|
|
||||||
|
def LocalPath(self):
|
||||||
|
return self._rel_path
|
||||||
|
|
||||||
|
|
||||||
class CheckForCommitObjectsTest(unittest.TestCase):
|
class CheckForCommitObjectsTest(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@@ -70,6 +82,24 @@ class CheckForCommitObjectsTest(unittest.TestCase):
|
|||||||
self.assertIn('--full-tree', args)
|
self.assertIn('--full-tree', args)
|
||||||
self.assertNotIn('f0.txt', args)
|
self.assertNotIn('f0.txt', args)
|
||||||
|
|
||||||
|
def testFullTreeExecutionWhenDepsModified(self):
|
||||||
|
# Small CL but DEPS is modified, should run full tree scan
|
||||||
|
self.input_api.files = [
|
||||||
|
MockRelativeFile('DEPS', []),
|
||||||
|
MockRelativeFile('other.txt', [])
|
||||||
|
]
|
||||||
|
|
||||||
|
self.input_api.subprocess.check_output = mock.Mock(return_value=b'')
|
||||||
|
|
||||||
|
presubmit_canned_checks.CheckForCommitObjects(self.input_api,
|
||||||
|
self.output_api)
|
||||||
|
|
||||||
|
args = self.input_api.subprocess.check_output.call_args[0][0]
|
||||||
|
self.assertIn('ls-tree', args)
|
||||||
|
self.assertIn('--full-tree', args)
|
||||||
|
# Should not list specific files when running full tree
|
||||||
|
self.assertNotIn('other.txt', args)
|
||||||
|
|
||||||
def testBatchedFoundCommit(self):
|
def testBatchedFoundCommit(self):
|
||||||
# 1 file, found a commit object (gitlink)
|
# 1 file, found a commit object (gitlink)
|
||||||
self.input_api.files = [
|
self.input_api.files = [
|
||||||
|
|||||||
Reference in New Issue
Block a user