From 51e39d536d9210dbae285f330a8ecb697d52aac6 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 4 Dec 2020 05:32:06 -0500 Subject: manifest_xml: harmonize list fields We allow project.groups to be whitespace or comma delimited, but repo-hooks.enabled-list is only whitespace delimited. This hasn't been a big deal as it's only ever had one valid value, but if we want to add more, we should harmonize these a bit. Refactor the groups method to be more generic, and run the enabled- list attribute through it. Then add missing docs for it. Change-Id: Iaa96a0faa9c4a68b313b49336751831b73bf855d Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/290743 Reviewed-by: Michael Mortensen Tested-by: Mike Frysinger --- manifest_xml.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'manifest_xml.py') diff --git a/manifest_xml.py b/manifest_xml.py index ad0017cc..00659316 100644 --- a/manifest_xml.py +++ b/manifest_xml.py @@ -292,8 +292,12 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md if r.revision is not None: e.setAttribute('revision', r.revision) - def _ParseGroups(self, groups): - return [x for x in re.split(r'[,\s]+', groups) if x] + def _ParseList(self, field): + """Parse fields that contain flattened lists. + + These are whitespace & comma separated. Empty elements will be discarded. + """ + return [x for x in re.split(r'[,\s]+', field) if x] def ToXml(self, peg_rev=False, peg_rev_upstream=True, peg_rev_dest_branch=True, groups=None): """Return the current manifest XML.""" @@ -302,7 +306,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md if groups is None: groups = mp.config.GetString('manifest.groups') if groups: - groups = self._ParseGroups(groups) + groups = self._ParseList(groups) doc = xml.dom.minidom.Document() root = doc.createElement('manifest') @@ -754,7 +758,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md path = node.getAttribute('path') groups = node.getAttribute('groups') if groups: - groups = self._ParseGroups(groups) + groups = self._ParseList(groups) revision = node.getAttribute('revision') remote = node.getAttribute('remote') if remote: @@ -776,7 +780,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md if node.nodeName == 'repo-hooks': # Get the name of the project and the (space-separated) list of enabled. repo_hooks_project = self._reqatt(node, 'in-project') - enabled_repo_hooks = self._reqatt(node, 'enabled-list').split() + enabled_repo_hooks = self._ParseList(self._reqatt(node, 'enabled-list')) # Only one project can be the hooks project if self._repo_hooks_project is not None: @@ -989,7 +993,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md groups = '' if node.hasAttribute('groups'): groups = node.getAttribute('groups') - groups = self._ParseGroups(groups) + groups = self._ParseList(groups) if parent is None: relpath, worktree, gitdir, objdir, use_git_worktrees = \ -- cgit v1.2.3-54-g00ecf