diff options
author | Jack Neus <jackneus@google.com> | 2021-07-20 20:52:33 +0000 |
---|---|---|
committer | Jack Neus <jackneus@google.com> | 2021-07-23 18:03:11 +0000 |
commit | 6ea0caea86f4c6b1f934b682a3aa7722e98a46f9 (patch) | |
tree | f54707aa6778f60078aef727210669f22f87de4e /manifest_xml.py | |
parent | 8e983bbc0f5f48aa38d0e1c5a37766ce121d28eb (diff) | |
download | git-repo-6ea0caea86f4c6b1f934b682a3aa7722e98a46f9.tar.gz |
repo: properly handle remote annotations in manifest_xml
BUG=b:192664812
TEST=tests/
Change-Id: I1aa50260f4a00d3cebbd531141e1626825e70127
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/312643
Tested-by: Jack Neus <jackneus@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'manifest_xml.py')
-rw-r--r-- | manifest_xml.py | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/manifest_xml.py b/manifest_xml.py index 22758cfd..55ad6c08 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
@@ -25,7 +25,7 @@ import gitc_utils | |||
25 | from git_config import GitConfig, IsId | 25 | from git_config import GitConfig, IsId |
26 | from git_refs import R_HEADS, HEAD | 26 | from git_refs import R_HEADS, HEAD |
27 | import platform_utils | 27 | import platform_utils |
28 | from project import RemoteSpec, Project, MetaProject | 28 | from project import Annotation, RemoteSpec, Project, MetaProject |
29 | from error import (ManifestParseError, ManifestInvalidPathError, | 29 | from error import (ManifestParseError, ManifestInvalidPathError, |
30 | ManifestInvalidRevisionError) | 30 | ManifestInvalidRevisionError) |
31 | from wrapper import Wrapper | 31 | from wrapper import Wrapper |
@@ -149,16 +149,18 @@ class _XmlRemote(object): | |||
149 | self.reviewUrl = review | 149 | self.reviewUrl = review |
150 | self.revision = revision | 150 | self.revision = revision |
151 | self.resolvedFetchUrl = self._resolveFetchUrl() | 151 | self.resolvedFetchUrl = self._resolveFetchUrl() |
152 | self.annotations = [] | ||
152 | 153 | ||
153 | def __eq__(self, other): | 154 | def __eq__(self, other): |
154 | if not isinstance(other, _XmlRemote): | 155 | if not isinstance(other, _XmlRemote): |
155 | return False | 156 | return False |
156 | return self.__dict__ == other.__dict__ | 157 | return (sorted(self.annotations) == sorted(other.annotations) and |
158 | self.name == other.name and self.fetchUrl == other.fetchUrl and | ||
159 | self.pushUrl == other.pushUrl and self.remoteAlias == other.remoteAlias | ||
160 | and self.reviewUrl == other.reviewUrl and self.revision == other.revision) | ||
157 | 161 | ||
158 | def __ne__(self, other): | 162 | def __ne__(self, other): |
159 | if not isinstance(other, _XmlRemote): | 163 | return not self.__eq__(other) |
160 | return True | ||
161 | return self.__dict__ != other.__dict__ | ||
162 | 164 | ||
163 | def _resolveFetchUrl(self): | 165 | def _resolveFetchUrl(self): |
164 | if self.fetchUrl is None: | 166 | if self.fetchUrl is None: |
@@ -191,6 +193,9 @@ class _XmlRemote(object): | |||
191 | orig_name=self.name, | 193 | orig_name=self.name, |
192 | fetchUrl=self.fetchUrl) | 194 | fetchUrl=self.fetchUrl) |
193 | 195 | ||
196 | def AddAnnotation(self, name, value, keep): | ||
197 | self.annotations.append(Annotation(name, value, keep)) | ||
198 | |||
194 | 199 | ||
195 | class XmlManifest(object): | 200 | class XmlManifest(object): |
196 | """manages the repo configuration file""" | 201 | """manages the repo configuration file""" |
@@ -300,6 +305,13 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
300 | if r.revision is not None: | 305 | if r.revision is not None: |
301 | e.setAttribute('revision', r.revision) | 306 | e.setAttribute('revision', r.revision) |
302 | 307 | ||
308 | for a in r.annotations: | ||
309 | if a.keep == 'true': | ||
310 | ae = doc.createElement('annotation') | ||
311 | ae.setAttribute('name', a.name) | ||
312 | ae.setAttribute('value', a.value) | ||
313 | e.appendChild(ae) | ||
314 | |||
303 | def _ParseList(self, field): | 315 | def _ParseList(self, field): |
304 | """Parse fields that contain flattened lists. | 316 | """Parse fields that contain flattened lists. |
305 | 317 | ||
@@ -995,7 +1007,14 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
995 | if revision == '': | 1007 | if revision == '': |
996 | revision = None | 1008 | revision = None |
997 | manifestUrl = self.manifestProject.config.GetString('remote.origin.url') | 1009 | manifestUrl = self.manifestProject.config.GetString('remote.origin.url') |
998 | return _XmlRemote(name, alias, fetch, pushUrl, manifestUrl, review, revision) | 1010 | |
1011 | remote = _XmlRemote(name, alias, fetch, pushUrl, manifestUrl, review, revision) | ||
1012 | |||
1013 | for n in node.childNodes: | ||
1014 | if n.nodeName == 'annotation': | ||
1015 | self._ParseAnnotation(remote, n) | ||
1016 | |||
1017 | return remote | ||
999 | 1018 | ||
1000 | def _ParseDefault(self, node): | 1019 | def _ParseDefault(self, node): |
1001 | """ | 1020 | """ |
@@ -1362,7 +1381,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
1362 | self._ValidateFilePaths('linkfile', src, dest) | 1381 | self._ValidateFilePaths('linkfile', src, dest) |
1363 | project.AddLinkFile(src, dest, self.topdir) | 1382 | project.AddLinkFile(src, dest, self.topdir) |
1364 | 1383 | ||
1365 | def _ParseAnnotation(self, project, node): | 1384 | def _ParseAnnotation(self, element, node): |
1366 | name = self._reqatt(node, 'name') | 1385 | name = self._reqatt(node, 'name') |
1367 | value = self._reqatt(node, 'value') | 1386 | value = self._reqatt(node, 'value') |
1368 | try: | 1387 | try: |
@@ -1372,7 +1391,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
1372 | if keep != "true" and keep != "false": | 1391 | if keep != "true" and keep != "false": |
1373 | raise ManifestParseError('optional "keep" attribute must be ' | 1392 | raise ManifestParseError('optional "keep" attribute must be ' |
1374 | '"true" or "false"') | 1393 | '"true" or "false"') |
1375 | project.AddAnnotation(name, value, keep) | 1394 | element.AddAnnotation(name, value, keep) |
1376 | 1395 | ||
1377 | def _get_remote(self, node): | 1396 | def _get_remote(self, node): |
1378 | name = node.getAttribute('remote') | 1397 | name = node.getAttribute('remote') |