summaryrefslogtreecommitdiffstats
path: root/tests/test_git_superproject.py
diff options
context:
space:
mode:
authorRaman Tenneti <rtenneti@google.com>2021-02-09 00:26:31 -0800
committerRaman Tenneti <rtenneti@google.com>2021-02-11 18:59:29 +0000
commit21dce3d8b351538d0fe8c05e6106c8b281580dda (patch)
tree771c7d005adc27acfbfdd7e6e85339766efdb810 /tests/test_git_superproject.py
parente3315bb49a782bcf62ba9df4fc1c2690b046763f (diff)
downloadgit-repo-21dce3d8b351538d0fe8c05e6106c8b281580dda.tar.gz
init: added --use-superproject option to clone superproject.v2.12.2
Added --no-use-superproject to repo and init.py to disable use of manifest superprojects. Replaced the term "sha" with "commit id". Added _GetBranch method to Superproject object. Moved shared code between init and sync into SyncSuperproject function. This function either does git clone or git fetch. If git fetch fails it does git clone. Changed Superproject constructor to accept manifest, repodir and branch to avoid passing them to multiple functions as argument. Changed functions that were raising exceptions to return either True or False. Saved the --use-superproject option in config as repo.superproject. Updated internal-fs-layout.md document. Updated the tests to work with the new API changes in Superproject. Performance for the first time sync has improved from 20 minutes to around 15 minutes. Tested the code with the following commands. $ ./run_tests -v Tested the sync code by using repo_dev alias and pointing to this CL. $ repo init took around 20 seconds longer because of cloning of superproject. $ time repo_dev init -u sso://android.git.corp.google.com/platform/manifest -b master --partial-clone --clone-filter=blob:limit=10M --repo-rev=main --use-superproject ... real 0m35.919s user 0m21.947s sys 0m8.977s First run $ time repo sync --use-superproject ... real 16m41.982s user 100m6.916s sys 19m18.753s No difference in repo sync time after the first run. Bug: [google internal] b/179090734 Bug: https://crbug.com/gerrit/13709 Bug: https://crbug.com/gerrit/13707 Change-Id: I12df92112f46e001dfbc6f12cd633c3a15cf924b Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/296382 Reviewed-by: Mike Frysinger <vapier@google.com> Tested-by: Raman Tenneti <rtenneti@google.com>
Diffstat (limited to 'tests/test_git_superproject.py')
-rw-r--r--tests/test_git_superproject.py115
1 files changed, 64 insertions, 51 deletions
diff --git a/tests/test_git_superproject.py b/tests/test_git_superproject.py
index fc9101dd..d2ee9f4f 100644
--- a/tests/test_git_superproject.py
+++ b/tests/test_git_superproject.py
@@ -19,7 +19,6 @@ import tempfile
19import unittest 19import unittest
20from unittest import mock 20from unittest import mock
21 21
22from error import GitError
23import git_superproject 22import git_superproject
24import manifest_xml 23import manifest_xml
25import platform_utils 24import platform_utils
@@ -32,7 +31,6 @@ class SuperprojectTestCase(unittest.TestCase):
32 """Set up superproject every time.""" 31 """Set up superproject every time."""
33 self.tempdir = tempfile.mkdtemp(prefix='repo_tests') 32 self.tempdir = tempfile.mkdtemp(prefix='repo_tests')
34 self.repodir = os.path.join(self.tempdir, '.repo') 33 self.repodir = os.path.join(self.tempdir, '.repo')
35 self._superproject = git_superproject.Superproject(self.repodir)
36 self.manifest_file = os.path.join( 34 self.manifest_file = os.path.join(
37 self.repodir, manifest_xml.MANIFEST_FILE_NAME) 35 self.repodir, manifest_xml.MANIFEST_FILE_NAME)
38 os.mkdir(self.repodir) 36 os.mkdir(self.repodir)
@@ -45,6 +43,16 @@ class SuperprojectTestCase(unittest.TestCase):
45 url = https://localhost:0/manifest 43 url = https://localhost:0/manifest
46""") 44""")
47 45
46 manifest = self.getXmlManifest("""
47<manifest>
48 <remote name="default-remote" fetch="http://localhost" />
49 <default remote="default-remote" revision="refs/heads/main" />
50 <superproject name="superproject"/>
51 <project path="art" name="platform/art" />
52</manifest>
53""")
54 self._superproject = git_superproject.Superproject(manifest, self.repodir)
55
48 def tearDown(self): 56 def tearDown(self):
49 """Tear down superproject every time.""" 57 """Tear down superproject every time."""
50 platform_utils.rmtree(self.tempdir) 58 platform_utils.rmtree(self.tempdir)
@@ -55,37 +63,53 @@ class SuperprojectTestCase(unittest.TestCase):
55 fp.write(data) 63 fp.write(data)
56 return manifest_xml.XmlManifest(self.repodir, self.manifest_file) 64 return manifest_xml.XmlManifest(self.repodir, self.manifest_file)
57 65
58 def test_superproject_get_project_shas_no_url(self): 66 def test_superproject_get_superproject_no_superproject(self):
59 """Test with no url.""" 67 """Test with no url."""
60 with self.assertRaises(ValueError): 68 manifest = self.getXmlManifest("""
61 self._superproject._GetAllProjectsSHAs(url=None) 69<manifest>
70</manifest>
71""")
72 superproject = git_superproject.Superproject(manifest, self.repodir)
73 self.assertFalse(superproject.Sync())
62 74
63 def test_superproject_get_project_shas_invalid_url(self): 75 def test_superproject_get_superproject_invalid_url(self):
64 """Test with an invalid url.""" 76 """Test with an invalid url."""
65 with self.assertRaises(GitError): 77 manifest = self.getXmlManifest("""
66 self._superproject._GetAllProjectsSHAs(url='localhost') 78<manifest>
79 <remote name="test-remote" fetch="localhost" />
80 <default remote="test-remote" revision="refs/heads/main" />
81 <superproject name="superproject"/>
82</manifest>
83""")
84 superproject = git_superproject.Superproject(manifest, self.repodir)
85 self.assertFalse(superproject.Sync())
67 86
68 def test_superproject_get_project_shas_invalid_branch(self): 87 def test_superproject_get_superproject_invalid_branch(self):
69 """Test with an invalid branch.""" 88 """Test with an invalid branch."""
70 with self.assertRaises(GitError): 89 manifest = self.getXmlManifest("""
71 self._superproject._GetAllProjectsSHAs( 90<manifest>
72 url='sso://android/platform/superproject', 91 <remote name="test-remote" fetch="localhost" />
73 branch='junk') 92 <default remote="test-remote" revision="refs/heads/main" />
93 <superproject name="superproject"/>
94</manifest>
95""")
96 superproject = git_superproject.Superproject(manifest, self.repodir)
97 with mock.patch.object(self._superproject, '_GetBranch', return_value='junk'):
98 self.assertFalse(superproject.Sync())
74 99
75 def test_superproject_get_project_shas_mock_clone(self): 100 def test_superproject_get_superproject_mock_clone(self):
76 """Test with _Clone failing.""" 101 """Test with _Clone failing."""
77 with self.assertRaises(GitError): 102 with mock.patch.object(self._superproject, '_Clone', return_value=False):
78 with mock.patch.object(self._superproject, '_Clone', return_value=False): 103 self.assertFalse(self._superproject.Sync())
79 self._superproject._GetAllProjectsSHAs(url='localhost') 104
80 105 def test_superproject_get_superproject_mock_fetch(self):
81 def test_superproject_get_project_shas_mock_fetch(self): 106 """Test with _Fetch failing and _clone being called."""
82 """Test with _Fetch failing.""" 107 with mock.patch.object(self._superproject, '_Clone', return_value=True):
83 with self.assertRaises(GitError): 108 os.mkdir(self._superproject._superproject_path)
84 with mock.patch.object(self._superproject, '_Clone', return_value=True): 109 with mock.patch.object(self._superproject, '_Fetch', return_value=False):
85 with mock.patch.object(self._superproject, '_Fetch', return_value=False): 110 self.assertTrue(self._superproject.Sync())
86 self._superproject._GetAllProjectsSHAs(url='localhost') 111
87 112 def test_superproject_get_all_project_commit_ids_mock_ls_tree(self):
88 def test_superproject_get_project_shas_mock_ls_tree(self):
89 """Test with LsTree being a mock.""" 113 """Test with LsTree being a mock."""
90 data = ('120000 blob 158258bdf146f159218e2b90f8b699c4d85b5804\tAndroid.bp\x00' 114 data = ('120000 blob 158258bdf146f159218e2b90f8b699c4d85b5804\tAndroid.bp\x00'
91 '160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00' 115 '160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00'
@@ -94,8 +118,8 @@ class SuperprojectTestCase(unittest.TestCase):
94 '160000 commit ade9b7a0d874e25fff4bf2552488825c6f111928\tbuild/bazel\x00') 118 '160000 commit ade9b7a0d874e25fff4bf2552488825c6f111928\tbuild/bazel\x00')
95 with mock.patch.object(self._superproject, '_Clone', return_value=True): 119 with mock.patch.object(self._superproject, '_Clone', return_value=True):
96 with mock.patch.object(self._superproject, '_LsTree', return_value=data): 120 with mock.patch.object(self._superproject, '_LsTree', return_value=data):
97 shas = self._superproject._GetAllProjectsSHAs(url='localhost', branch='junk') 121 commit_ids = self._superproject._GetAllProjectsCommitIds()
98 self.assertEqual(shas, { 122 self.assertEqual(commit_ids, {
99 'art': '2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea', 123 'art': '2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea',
100 'bootable/recovery': 'e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06', 124 'bootable/recovery': 'e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06',
101 'build/bazel': 'ade9b7a0d874e25fff4bf2552488825c6f111928' 125 'build/bazel': 'ade9b7a0d874e25fff4bf2552488825c6f111928'
@@ -103,19 +127,12 @@ class SuperprojectTestCase(unittest.TestCase):
103 127
104 def test_superproject_write_manifest_file(self): 128 def test_superproject_write_manifest_file(self):
105 """Test with writing manifest to a file after setting revisionId.""" 129 """Test with writing manifest to a file after setting revisionId."""
106 manifest = self.getXmlManifest(""" 130 self.assertEqual(len(self._superproject._manifest.projects), 1)
107<manifest> 131 project = self._superproject._manifest.projects[0]
108 <remote name="default-remote" fetch="http://localhost" />
109 <default remote="default-remote" revision="refs/heads/main" />
110 <project name="test-name"/>
111</manifest>
112""")
113 self.assertEqual(len(manifest.projects), 1)
114 project = manifest.projects[0]
115 project.SetRevisionId('ABCDEF') 132 project.SetRevisionId('ABCDEF')
116 # Create temporary directory so that it can write the file. 133 # Create temporary directory so that it can write the file.
117 os.mkdir(self._superproject._superproject_path) 134 os.mkdir(self._superproject._superproject_path)
118 manifest_path = self._superproject._WriteManfiestFile(manifest) 135 manifest_path = self._superproject._WriteManfiestFile()
119 self.assertIsNotNone(manifest_path) 136 self.assertIsNotNone(manifest_path)
120 with open(manifest_path, 'r') as fp: 137 with open(manifest_path, 'r') as fp:
121 manifest_xml = fp.read() 138 manifest_xml = fp.read()
@@ -124,29 +141,24 @@ class SuperprojectTestCase(unittest.TestCase):
124 '<?xml version="1.0" ?><manifest>' + 141 '<?xml version="1.0" ?><manifest>' +
125 '<remote name="default-remote" fetch="http://localhost"/>' + 142 '<remote name="default-remote" fetch="http://localhost"/>' +
126 '<default remote="default-remote" revision="refs/heads/main"/>' + 143 '<default remote="default-remote" revision="refs/heads/main"/>' +
127 '<project name="test-name" revision="ABCDEF"/>' + 144 '<project name="platform/art" path="art" revision="ABCDEF"/>' +
145 '<superproject name="superproject"/>' +
128 '</manifest>') 146 '</manifest>')
129 147
130 def test_superproject_update_project_revision_id(self): 148 def test_superproject_update_project_revision_id(self):
131 """Test with LsTree being a mock.""" 149 """Test with LsTree being a mock."""
132 manifest = self.getXmlManifest(""" 150 self.assertEqual(len(self._superproject._manifest.projects), 1)
133<manifest> 151 projects = self._superproject._manifest.projects
134 <remote name="default-remote" fetch="http://localhost" />
135 <default remote="default-remote" revision="refs/heads/main" />
136 <project path="art" name="platform/art" />
137</manifest>
138""")
139 self.assertEqual(len(manifest.projects), 1)
140 projects = manifest.projects
141 data = ('160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00' 152 data = ('160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00'
142 '160000 commit e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06\tbootable/recovery\x00') 153 '160000 commit e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06\tbootable/recovery\x00')
143 with mock.patch.object(self._superproject, '_Clone', return_value=True): 154 with mock.patch.object(self._superproject, '_Clone', return_value=True):
144 with mock.patch.object(self._superproject, '_Fetch', return_value=True): 155 with mock.patch.object(self._superproject, '_Fetch', return_value=True):
145 with mock.patch.object(self._superproject, '_LsTree', return_value=data): 156 with mock.patch.object(self._superproject,
157 '_LsTree',
158 return_value=data):
146 # Create temporary directory so that it can write the file. 159 # Create temporary directory so that it can write the file.
147 os.mkdir(self._superproject._superproject_path) 160 os.mkdir(self._superproject._superproject_path)
148 manifest_path = self._superproject.UpdateProjectsRevisionId( 161 manifest_path = self._superproject.UpdateProjectsRevisionId(projects)
149 manifest, projects, url='localhost')
150 self.assertIsNotNone(manifest_path) 162 self.assertIsNotNone(manifest_path)
151 with open(manifest_path, 'r') as fp: 163 with open(manifest_path, 'r') as fp:
152 manifest_xml = fp.read() 164 manifest_xml = fp.read()
@@ -157,6 +169,7 @@ class SuperprojectTestCase(unittest.TestCase):
157 '<default remote="default-remote" revision="refs/heads/main"/>' + 169 '<default remote="default-remote" revision="refs/heads/main"/>' +
158 '<project name="platform/art" path="art" ' + 170 '<project name="platform/art" path="art" ' +
159 'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea"/>' + 171 'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea"/>' +
172 '<superproject name="superproject"/>' +
160 '</manifest>') 173 '</manifest>')
161 174
162 175