summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPeter Kjellerstedt <pkj@axis.com>2025-11-08 00:06:16 +0100
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2025-11-26 02:07:35 -0800
commit412367bfafd9de014cfeb37475e0f97b1f6a2509 (patch)
tree100e674dea649546145dbb81532a8f432cc09f52 /tests
parent47c24b5c4092ce397c94c05d8686c8bcac64fbb2 (diff)
downloadgit-repo-412367bfafd9de014cfeb37475e0f97b1f6a2509.tar.gz
project: Use dicts to keep track of copyfiles and linkfiles
This avoids copying/linking the same file/link multiple times if a copyfile/linkfile element with the same values has been specifed multiple times. This can happen when including a common manifest that uses an extend-project element that has a copyfile/linkfile element. This uses dicts rather than sets to store the copyfiles and linkfiles to make sure the order they are specified in the manifest is maintained. For Python 3.7+, maintaining the order that keys are added to dicts is guaranteed, and for Python 3.6 it happened to be true. The _CopyFile class and the _LinkFile class are changed to inherit from NamedTuple to be able to store them in dicts. Change-Id: I9f5a80298b875251a81c5fe7d353e262d104fae4 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/525322 Reviewed-by: Mike Frysinger <vapier@google.com> Reviewed-by: Gavin Mak <gavinmak@google.com> Tested-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> Commit-Queue: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_manifest_xml.py90
1 files changed, 86 insertions, 4 deletions
diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py
index d4bf76a9..f5991515 100644
--- a/tests/test_manifest_xml.py
+++ b/tests/test_manifest_xml.py
@@ -1254,8 +1254,8 @@ class ExtendProjectElementTests(ManifestParseTestCase):
1254</manifest> 1254</manifest>
1255""" 1255"""
1256 ) 1256 )
1257 self.assertEqual(manifest.projects[0].copyfiles[0].src, "foo") 1257 self.assertEqual(list(manifest.projects[0].copyfiles)[0].src, "foo")
1258 self.assertEqual(manifest.projects[0].copyfiles[0].dest, "bar") 1258 self.assertEqual(list(manifest.projects[0].copyfiles)[0].dest, "bar")
1259 self.assertEqual( 1259 self.assertEqual(
1260 sort_attributes(manifest.ToXml().toxml()), 1260 sort_attributes(manifest.ToXml().toxml()),
1261 '<?xml version="1.0" ?><manifest>' 1261 '<?xml version="1.0" ?><manifest>'
@@ -1267,6 +1267,47 @@ class ExtendProjectElementTests(ManifestParseTestCase):
1267 "</manifest>", 1267 "</manifest>",
1268 ) 1268 )
1269 1269
1270 def test_extend_project_duplicate_copyfiles(self):
1271 root_m = self.manifest_dir / "root.xml"
1272 root_m.write_text(
1273 """
1274<manifest>
1275 <remote name="test-remote" fetch="http://localhost" />
1276 <default remote="test-remote" revision="refs/heads/main" />
1277 <project name="myproject" />
1278 <include name="man1.xml" />
1279 <include name="man2.xml" />
1280</manifest>
1281"""
1282 )
1283 (self.manifest_dir / "man1.xml").write_text(
1284 """
1285<manifest>
1286 <include name="common.xml" />
1287</manifest>
1288"""
1289 )
1290 (self.manifest_dir / "man2.xml").write_text(
1291 """
1292<manifest>
1293 <include name="common.xml" />
1294</manifest>
1295"""
1296 )
1297 (self.manifest_dir / "common.xml").write_text(
1298 """
1299<manifest>
1300 <extend-project name="myproject">
1301 <copyfile dest="bar" src="foo"/>
1302 </extend-project>
1303</manifest>
1304"""
1305 )
1306 manifest = manifest_xml.XmlManifest(str(self.repodir), str(root_m))
1307 self.assertEqual(len(manifest.projects[0].copyfiles), 1)
1308 self.assertEqual(list(manifest.projects[0].copyfiles)[0].src, "foo")
1309 self.assertEqual(list(manifest.projects[0].copyfiles)[0].dest, "bar")
1310
1270 def test_extend_project_linkfiles(self): 1311 def test_extend_project_linkfiles(self):
1271 manifest = self.getXmlManifest( 1312 manifest = self.getXmlManifest(
1272 """ 1313 """
@@ -1280,8 +1321,8 @@ class ExtendProjectElementTests(ManifestParseTestCase):
1280</manifest> 1321</manifest>
1281""" 1322"""
1282 ) 1323 )
1283 self.assertEqual(manifest.projects[0].linkfiles[0].src, "foo") 1324 self.assertEqual(list(manifest.projects[0].linkfiles)[0].src, "foo")
1284 self.assertEqual(manifest.projects[0].linkfiles[0].dest, "bar") 1325 self.assertEqual(list(manifest.projects[0].linkfiles)[0].dest, "bar")
1285 self.assertEqual( 1326 self.assertEqual(
1286 sort_attributes(manifest.ToXml().toxml()), 1327 sort_attributes(manifest.ToXml().toxml()),
1287 '<?xml version="1.0" ?><manifest>' 1328 '<?xml version="1.0" ?><manifest>'
@@ -1293,6 +1334,47 @@ class ExtendProjectElementTests(ManifestParseTestCase):
1293 "</manifest>", 1334 "</manifest>",
1294 ) 1335 )
1295 1336
1337 def test_extend_project_duplicate_linkfiles(self):
1338 root_m = self.manifest_dir / "root.xml"
1339 root_m.write_text(
1340 """
1341<manifest>
1342 <remote name="test-remote" fetch="http://localhost" />
1343 <default remote="test-remote" revision="refs/heads/main" />
1344 <project name="myproject" />
1345 <include name="man1.xml" />
1346 <include name="man2.xml" />
1347</manifest>
1348"""
1349 )
1350 (self.manifest_dir / "man1.xml").write_text(
1351 """
1352<manifest>
1353 <include name="common.xml" />
1354</manifest>
1355"""
1356 )
1357 (self.manifest_dir / "man2.xml").write_text(
1358 """
1359<manifest>
1360 <include name="common.xml" />
1361</manifest>
1362"""
1363 )
1364 (self.manifest_dir / "common.xml").write_text(
1365 """
1366<manifest>
1367 <extend-project name="myproject">
1368 <linkfile dest="bar" src="foo"/>
1369 </extend-project>
1370</manifest>
1371"""
1372 )
1373 manifest = manifest_xml.XmlManifest(str(self.repodir), str(root_m))
1374 self.assertEqual(len(manifest.projects[0].linkfiles), 1)
1375 self.assertEqual(list(manifest.projects[0].linkfiles)[0].src, "foo")
1376 self.assertEqual(list(manifest.projects[0].linkfiles)[0].dest, "bar")
1377
1296 def test_extend_project_annotations(self): 1378 def test_extend_project_annotations(self):
1297 manifest = self.getXmlManifest( 1379 manifest = self.getXmlManifest(
1298 """ 1380 """