Skip to content

Commit 3073a90

Browse files
Peter KjellerstedtLUCI
authored andcommitted
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 <[email protected]> Tested-by: Peter Kjellerstedt <[email protected]> Commit-Queue: Peter Kjellerstedt <[email protected]> Reviewed-by: Gavin Mak <[email protected]>
1 parent 75773b8 commit 3073a90

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

docs/manifest-format.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,9 @@ This also applies to all extend-project elements in the included manifests.
579579
Same syntax as the corresponding element of `project`.
580580

581581
Attribute `revision`: Name of a Git branch (e.g. `main` or `refs/heads/main`)
582-
default to which all projects in the included manifest belong.
582+
default to which all projects in the included manifest belong. This recurses,
583+
meaning it will apply to all projects in all manifests included as a result of
584+
this element.
583585

584586
## Local Manifests {#local-manifests}
585587

man/repo-manifest.1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,9 @@ extend\-project elements in the included manifests. Same syntax as the
641641
corresponding element of `project`.
642642
.PP
643643
Attribute `revision`: Name of a Git branch (e.g. `main` or `refs/heads/main`)
644-
default to which all projects in the included manifest belong.
644+
default to which all projects in the included manifest belong. This recurses,
645+
meaning it will apply to all projects in all manifests included as a result of
646+
this element.
645647
.PP
646648
Local Manifests
647649
.PP

manifest_xml.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,14 @@ def _ParseManifestXml(
13051305

13061306
nodes = []
13071307
for node in manifest.childNodes:
1308+
if (
1309+
parent_node
1310+
and node.nodeName in ("include", "project")
1311+
and not node.hasAttribute("revision")
1312+
):
1313+
node.setAttribute(
1314+
"revision", parent_node.getAttribute("revision")
1315+
)
13081316
if node.nodeName == "include":
13091317
name = self._reqatt(node, "name")
13101318
if restrict_includes:
@@ -1349,14 +1357,6 @@ def _ParseManifestXml(
13491357
node.getAttribute("groups")
13501358
)
13511359
node.setAttribute("groups", ",".join(sorted(nodeGroups)))
1352-
if (
1353-
parent_node
1354-
and node.nodeName == "project"
1355-
and not node.hasAttribute("revision")
1356-
):
1357-
node.setAttribute(
1358-
"revision", parent_node.getAttribute("revision")
1359-
)
13601360
nodes.append(node)
13611361
return nodes
13621362

tests/test_manifest_xml.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,27 @@ def test_revision_default(self):
422422
(self.manifest_dir / "stable.xml").write_text(
423423
"""
424424
<manifest>
425+
<include name="man1.xml" />
426+
<include name="man2.xml" revision="stable-branch2" />
425427
<project name="stable-name1" path="stable-path1" />
426428
<project name="stable-name2" path="stable-path2" revision="stable-branch2" />
427429
</manifest>
430+
"""
431+
)
432+
(self.manifest_dir / "man1.xml").write_text(
433+
"""
434+
<manifest>
435+
<project name="man1-name1" />
436+
<project name="man1-name2" revision="stable-branch3" />
437+
</manifest>
438+
"""
439+
)
440+
(self.manifest_dir / "man2.xml").write_text(
441+
"""
442+
<manifest>
443+
<project name="man2-name1" />
444+
<project name="man2-name2" revision="stable-branch3" />
445+
</manifest>
428446
"""
429447
)
430448
include_m = manifest_xml.XmlManifest(str(self.repodir), str(root_m))
@@ -441,6 +459,14 @@ def test_revision_default(self):
441459
if proj.name == "stable-name2":
442460
# Check stable proj revision can override include node.
443461
self.assertEqual("stable-branch2", proj.revisionExpr)
462+
if proj.name == "man1-name1":
463+
self.assertEqual("stable-branch", proj.revisionExpr)
464+
if proj.name == "man1-name2":
465+
self.assertEqual("stable-branch3", proj.revisionExpr)
466+
if proj.name == "man2-name1":
467+
self.assertEqual("stable-branch2", proj.revisionExpr)
468+
if proj.name == "man2-name2":
469+
self.assertEqual("stable-branch3", proj.revisionExpr)
444470

445471
def test_group_levels(self):
446472
root_m = self.manifest_dir / "root.xml"

0 commit comments

Comments
 (0)