manifest: Propagate revision attribute through multiple levels of include

Make sure a revision attribute for an include element is propagated
through multiple levels of manifest includes.

Change-Id: If37d65b0cd47da673719976598175d0eb6b7cbbe
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/525341
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Commit-Queue: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
This commit is contained in:
Peter Kjellerstedt
2025-11-08 06:42:53 +01:00
committed by LUCI
parent 75773b8b9d
commit 3073a90046
4 changed files with 40 additions and 10 deletions

View File

@@ -579,7 +579,9 @@ This also applies to all extend-project elements in the included manifests.
Same syntax as the corresponding element of `project`.
Attribute `revision`: Name of a Git branch (e.g. `main` or `refs/heads/main`)
default to which all projects in the included manifest belong.
default to which all projects in the included manifest belong. This recurses,
meaning it will apply to all projects in all manifests included as a result of
this element.
## Local Manifests {#local-manifests}

View File

@@ -641,7 +641,9 @@ extend\-project elements in the included manifests. Same syntax as the
corresponding element of `project`.
.PP
Attribute `revision`: Name of a Git branch (e.g. `main` or `refs/heads/main`)
default to which all projects in the included manifest belong.
default to which all projects in the included manifest belong. This recurses,
meaning it will apply to all projects in all manifests included as a result of
this element.
.PP
Local Manifests
.PP

View File

@@ -1305,6 +1305,14 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
nodes = []
for node in manifest.childNodes:
if (
parent_node
and node.nodeName in ("include", "project")
and not node.hasAttribute("revision")
):
node.setAttribute(
"revision", parent_node.getAttribute("revision")
)
if node.nodeName == "include":
name = self._reqatt(node, "name")
if restrict_includes:
@@ -1349,14 +1357,6 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
node.getAttribute("groups")
)
node.setAttribute("groups", ",".join(sorted(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

View File

@@ -422,9 +422,27 @@ class IncludeElementTests(ManifestParseTestCase):
(self.manifest_dir / "stable.xml").write_text(
"""
<manifest>
<include name="man1.xml" />
<include name="man2.xml" revision="stable-branch2" />
<project name="stable-name1" path="stable-path1" />
<project name="stable-name2" path="stable-path2" revision="stable-branch2" />
</manifest>
"""
)
(self.manifest_dir / "man1.xml").write_text(
"""
<manifest>
<project name="man1-name1" />
<project name="man1-name2" revision="stable-branch3" />
</manifest>
"""
)
(self.manifest_dir / "man2.xml").write_text(
"""
<manifest>
<project name="man2-name1" />
<project name="man2-name2" revision="stable-branch3" />
</manifest>
"""
)
include_m = manifest_xml.XmlManifest(str(self.repodir), str(root_m))
@@ -441,6 +459,14 @@ class IncludeElementTests(ManifestParseTestCase):
if proj.name == "stable-name2":
# Check stable proj revision can override include node.
self.assertEqual("stable-branch2", proj.revisionExpr)
if proj.name == "man1-name1":
self.assertEqual("stable-branch", proj.revisionExpr)
if proj.name == "man1-name2":
self.assertEqual("stable-branch3", proj.revisionExpr)
if proj.name == "man2-name1":
self.assertEqual("stable-branch2", proj.revisionExpr)
if proj.name == "man2-name2":
self.assertEqual("stable-branch3", proj.revisionExpr)
def test_group_levels(self):
root_m = self.manifest_dir / "root.xml"