From 3e3340d94f8a680156ceaa81faca1c3b8863c6ac Mon Sep 17 00:00:00 2001 From: Shuchuan Zeng Date: Tue, 18 Apr 2023 10:36:50 +0800 Subject: manifest: add support for revision in include Attribute groups can now be added to manifest include, thus all projects in an included manifest file can easily modify default branch without modifying all projects in that manifest file. For example, the main manifest.xml has an include node contain revision attribute, ``` ``` and the include.xml has some projects, ``` ``` With this change, the final manifest will have revision="r1" for project2. ``` ``` Test: added unit tests to cover the inheritance Change-Id: I4b8547a7198610ec3a3c6aeb2136e0c0f3557df0 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/369714 Reviewed-by: Mike Frysinger Commit-Queue: Shuchuan Zeng Tested-by: Shuchuan Zeng --- manifest_xml.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'manifest_xml.py') diff --git a/manifest_xml.py b/manifest_xml.py index 9603906f..14b03a30 100644 --- a/manifest_xml.py +++ b/manifest_xml.py @@ -1233,7 +1233,12 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md ) def _ParseManifestXml( - self, path, include_root, parent_groups="", restrict_includes=True + self, + path, + include_root, + parent_groups="", + restrict_includes=True, + parent_node=None, ): """Parse a manifest XML and return the computed nodes. @@ -1243,6 +1248,8 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md parent_groups: The groups to apply to this projects. restrict_includes: Whether to constrain the "name" attribute of includes. + parent_node: The parent include node, to apply attribute to this + projects. Returns: List of XML nodes. @@ -1288,7 +1295,9 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md ) try: nodes.extend( - self._ParseManifestXml(fp, include_root, include_groups) + self._ParseManifestXml( + fp, include_root, include_groups, parent_node=node + ) ) # should isolate this to the exact exception, but that's # tricky. actual parsing implementation may vary. @@ -1311,6 +1320,14 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md node.getAttribute("groups") + "," + nodeGroups ) node.setAttribute("groups", nodeGroups) + if ( + parent_node + and node.nodeName == "project" + and not node.hasAttribute("revision") + ): + node.setAttribute( + "revision", parent_node.getAttribute("revision") + ) nodes.append(node) return nodes -- cgit v1.2.3-54-g00ecf