From 412367bfafd9de014cfeb37475e0f97b1f6a2509 Mon Sep 17 00:00:00 2001 From: Peter Kjellerstedt Date: Sat, 8 Nov 2025 00:06:16 +0100 Subject: 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 Reviewed-by: Gavin Mak Tested-by: Peter Kjellerstedt Commit-Queue: Peter Kjellerstedt --- tests/test_manifest_xml.py | 90 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py index d4bf76a91..f59915158 100644 --- a/tests/test_manifest_xml.py +++ b/tests/test_manifest_xml.py @@ -1254,8 +1254,8 @@ class ExtendProjectElementTests(ManifestParseTestCase): """ ) - self.assertEqual(manifest.projects[0].copyfiles[0].src, "foo") - self.assertEqual(manifest.projects[0].copyfiles[0].dest, "bar") + self.assertEqual(list(manifest.projects[0].copyfiles)[0].src, "foo") + self.assertEqual(list(manifest.projects[0].copyfiles)[0].dest, "bar") self.assertEqual( sort_attributes(manifest.ToXml().toxml()), '' @@ -1267,6 +1267,47 @@ class ExtendProjectElementTests(ManifestParseTestCase): "", ) + def test_extend_project_duplicate_copyfiles(self): + root_m = self.manifest_dir / "root.xml" + root_m.write_text( + """ + + + + + + + +""" + ) + (self.manifest_dir / "man1.xml").write_text( + """ + + + +""" + ) + (self.manifest_dir / "man2.xml").write_text( + """ + + + +""" + ) + (self.manifest_dir / "common.xml").write_text( + """ + + + + + +""" + ) + manifest = manifest_xml.XmlManifest(str(self.repodir), str(root_m)) + self.assertEqual(len(manifest.projects[0].copyfiles), 1) + self.assertEqual(list(manifest.projects[0].copyfiles)[0].src, "foo") + self.assertEqual(list(manifest.projects[0].copyfiles)[0].dest, "bar") + def test_extend_project_linkfiles(self): manifest = self.getXmlManifest( """ @@ -1280,8 +1321,8 @@ class ExtendProjectElementTests(ManifestParseTestCase): """ ) - self.assertEqual(manifest.projects[0].linkfiles[0].src, "foo") - self.assertEqual(manifest.projects[0].linkfiles[0].dest, "bar") + self.assertEqual(list(manifest.projects[0].linkfiles)[0].src, "foo") + self.assertEqual(list(manifest.projects[0].linkfiles)[0].dest, "bar") self.assertEqual( sort_attributes(manifest.ToXml().toxml()), '' @@ -1293,6 +1334,47 @@ class ExtendProjectElementTests(ManifestParseTestCase): "", ) + def test_extend_project_duplicate_linkfiles(self): + root_m = self.manifest_dir / "root.xml" + root_m.write_text( + """ + + + + + + + +""" + ) + (self.manifest_dir / "man1.xml").write_text( + """ + + + +""" + ) + (self.manifest_dir / "man2.xml").write_text( + """ + + + +""" + ) + (self.manifest_dir / "common.xml").write_text( + """ + + + + + +""" + ) + manifest = manifest_xml.XmlManifest(str(self.repodir), str(root_m)) + self.assertEqual(len(manifest.projects[0].linkfiles), 1) + self.assertEqual(list(manifest.projects[0].linkfiles)[0].src, "foo") + self.assertEqual(list(manifest.projects[0].linkfiles)[0].dest, "bar") + def test_extend_project_annotations(self): manifest = self.getXmlManifest( """ -- cgit v1.2.3-54-g00ecf