From 6ea0caea86f4c6b1f934b682a3aa7722e98a46f9 Mon Sep 17 00:00:00 2001 From: Jack Neus Date: Tue, 20 Jul 2021 20:52:33 +0000 Subject: 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 Reviewed-by: Mike Frysinger --- manifest_xml.py | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'manifest_xml.py') 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 from git_config import GitConfig, IsId from git_refs import R_HEADS, HEAD import platform_utils -from project import RemoteSpec, Project, MetaProject +from project import Annotation, RemoteSpec, Project, MetaProject from error import (ManifestParseError, ManifestInvalidPathError, ManifestInvalidRevisionError) from wrapper import Wrapper @@ -149,16 +149,18 @@ class _XmlRemote(object): self.reviewUrl = review self.revision = revision self.resolvedFetchUrl = self._resolveFetchUrl() + self.annotations = [] def __eq__(self, other): if not isinstance(other, _XmlRemote): return False - return self.__dict__ == other.__dict__ + return (sorted(self.annotations) == sorted(other.annotations) and + self.name == other.name and self.fetchUrl == other.fetchUrl and + self.pushUrl == other.pushUrl and self.remoteAlias == other.remoteAlias + and self.reviewUrl == other.reviewUrl and self.revision == other.revision) def __ne__(self, other): - if not isinstance(other, _XmlRemote): - return True - return self.__dict__ != other.__dict__ + return not self.__eq__(other) def _resolveFetchUrl(self): if self.fetchUrl is None: @@ -191,6 +193,9 @@ class _XmlRemote(object): orig_name=self.name, fetchUrl=self.fetchUrl) + def AddAnnotation(self, name, value, keep): + self.annotations.append(Annotation(name, value, keep)) + class XmlManifest(object): """manages the repo configuration file""" @@ -300,6 +305,13 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md if r.revision is not None: e.setAttribute('revision', r.revision) + for a in r.annotations: + if a.keep == 'true': + ae = doc.createElement('annotation') + ae.setAttribute('name', a.name) + ae.setAttribute('value', a.value) + e.appendChild(ae) + def _ParseList(self, field): """Parse fields that contain flattened lists. @@ -995,7 +1007,14 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md if revision == '': revision = None manifestUrl = self.manifestProject.config.GetString('remote.origin.url') - return _XmlRemote(name, alias, fetch, pushUrl, manifestUrl, review, revision) + + remote = _XmlRemote(name, alias, fetch, pushUrl, manifestUrl, review, revision) + + for n in node.childNodes: + if n.nodeName == 'annotation': + self._ParseAnnotation(remote, n) + + return remote def _ParseDefault(self, node): """ @@ -1362,7 +1381,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md self._ValidateFilePaths('linkfile', src, dest) project.AddLinkFile(src, dest, self.topdir) - def _ParseAnnotation(self, project, node): + def _ParseAnnotation(self, element, node): name = self._reqatt(node, 'name') value = self._reqatt(node, 'value') try: @@ -1372,7 +1391,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md if keep != "true" and keep != "false": raise ManifestParseError('optional "keep" attribute must be ' '"true" or "false"') - project.AddAnnotation(name, value, keep) + element.AddAnnotation(name, value, keep) def _get_remote(self, node): name = node.getAttribute('remote') -- cgit v1.2.3-54-g00ecf