diff options
author | Shuchuan Zeng <zengshuchuan@allwinnertech.com> | 2023-04-18 10:36:50 +0800 |
---|---|---|
committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-05-05 03:40:28 +0000 |
commit | 3e3340d94f8a680156ceaa81faca1c3b8863c6ac (patch) | |
tree | 93bcf5c0d43e2a9fc2c4c88703abe3e185cbeec8 /manifest_xml.py | |
parent | edcaa94ca86d29c1ea106eddac837f4a699379ba (diff) | |
download | git-repo-3e3340d94f8a680156ceaa81faca1c3b8863c6ac.tar.gz |
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,
```
<include name="include.xml" revision="r1" />
```
and the include.xml has some projects,
```
<project path="project1_path" name="project1_name" revision="r2" />
<project path="project2_path" name="project2_name" />
```
With this change, the final manifest will have revision="r1" for project2.
```
<project name="project1_name" path="project1_path" revision="r2" />
<project name="project2_name" path="project2_path" revision="r1" />
```
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 <vapier@google.com>
Commit-Queue: Shuchuan Zeng <zengshuchuan@allwinnertech.com>
Tested-by: Shuchuan Zeng <zengshuchuan@allwinnertech.com>
Diffstat (limited to 'manifest_xml.py')
-rw-r--r-- | manifest_xml.py | 21 |
1 files changed, 19 insertions, 2 deletions
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 | |||
1233 | ) | 1233 | ) |
1234 | 1234 | ||
1235 | def _ParseManifestXml( | 1235 | def _ParseManifestXml( |
1236 | self, path, include_root, parent_groups="", restrict_includes=True | 1236 | self, |
1237 | path, | ||
1238 | include_root, | ||
1239 | parent_groups="", | ||
1240 | restrict_includes=True, | ||
1241 | parent_node=None, | ||
1237 | ): | 1242 | ): |
1238 | """Parse a manifest XML and return the computed nodes. | 1243 | """Parse a manifest XML and return the computed nodes. |
1239 | 1244 | ||
@@ -1243,6 +1248,8 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
1243 | parent_groups: The groups to apply to this projects. | 1248 | parent_groups: The groups to apply to this projects. |
1244 | restrict_includes: Whether to constrain the "name" attribute of | 1249 | restrict_includes: Whether to constrain the "name" attribute of |
1245 | includes. | 1250 | includes. |
1251 | parent_node: The parent include node, to apply attribute to this | ||
1252 | projects. | ||
1246 | 1253 | ||
1247 | Returns: | 1254 | Returns: |
1248 | List of XML nodes. | 1255 | List of XML nodes. |
@@ -1288,7 +1295,9 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
1288 | ) | 1295 | ) |
1289 | try: | 1296 | try: |
1290 | nodes.extend( | 1297 | nodes.extend( |
1291 | self._ParseManifestXml(fp, include_root, include_groups) | 1298 | self._ParseManifestXml( |
1299 | fp, include_root, include_groups, parent_node=node | ||
1300 | ) | ||
1292 | ) | 1301 | ) |
1293 | # should isolate this to the exact exception, but that's | 1302 | # should isolate this to the exact exception, but that's |
1294 | # tricky. actual parsing implementation may vary. | 1303 | # tricky. actual parsing implementation may vary. |
@@ -1311,6 +1320,14 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
1311 | node.getAttribute("groups") + "," + nodeGroups | 1320 | node.getAttribute("groups") + "," + nodeGroups |
1312 | ) | 1321 | ) |
1313 | node.setAttribute("groups", nodeGroups) | 1322 | node.setAttribute("groups", nodeGroups) |
1323 | if ( | ||
1324 | parent_node | ||
1325 | and node.nodeName == "project" | ||
1326 | and not node.hasAttribute("revision") | ||
1327 | ): | ||
1328 | node.setAttribute( | ||
1329 | "revision", parent_node.getAttribute("revision") | ||
1330 | ) | ||
1314 | nodes.append(node) | 1331 | nodes.append(node) |
1315 | return nodes | 1332 | return nodes |
1316 | 1333 | ||