diff --git a/command.py b/command.py index 724e4c5d..2ee0a43a 100644 --- a/command.py +++ b/command.py @@ -58,7 +58,7 @@ class Command(object): """Perform the action, after option parsing is complete. """ raise NotImplementedError - + def GetProjects(self, args, missing_ok=False): """A list of projects that match the arguments. """ @@ -68,8 +68,9 @@ class Command(object): mp = self.manifest.manifestProject groups = mp.config.GetString('manifest.groups') - if groups: - groups = re.split('[,\s]+', groups) + if groups is None: + groups = 'default' + groups = [x for x in re.split('[,\s]+', groups) if x] if not args: for project in all.values(): diff --git a/docs/manifest-format.txt b/docs/manifest-format.txt index e5f5ee18..764e41eb 100644 --- a/docs/manifest-format.txt +++ b/docs/manifest-format.txt @@ -165,8 +165,8 @@ been extensively tested. If not supplied the revision given by the default element is used. Attribute `groups`: List of groups to which this project belongs, -whitespace or comma separated. All projects are part of the group -"default" unless "-default" is specified in the list of groups. +whitespace or comma separated. All projects belong to the group +"default". Element annotation ------------------ diff --git a/manifest_xml.py b/manifest_xml.py index 9b804da9..5ffc49e9 100644 --- a/manifest_xml.py +++ b/manifest_xml.py @@ -122,8 +122,9 @@ class XmlManifest(object): mp = self.manifestProject groups = mp.config.GetString('manifest.groups') - if groups: - groups = re.split('[,\s]+', groups) + if groups is None: + groups = 'default' + groups = [x for x in re.split(r'[,\s]+', groups) if x] doc = xml.dom.minidom.Document() root = doc.createElement('manifest') @@ -200,8 +201,9 @@ class XmlManifest(object): ce.setAttribute('dest', c.dest) e.appendChild(ce) - if p.groups: - e.setAttribute('groups', ','.join(p.groups)) + egroups = [g for g in p.groups if g != 'default'] + if egroups: + e.setAttribute('groups', ','.join(egroups)) for a in p.annotations: if a.keep == "true": @@ -524,11 +526,12 @@ class XmlManifest(object): else: rebase = rebase.lower() in ("yes", "true", "1") - groups = node.getAttribute('groups') - if groups: - groups = re.split('[,\s]+', groups) - else: - groups = None + groups = '' + if node.hasAttribute('groups'): + groups = node.getAttribute('groups') + groups = [x for x in re.split('[,\s]+', groups) if x] + if 'default' not in groups: + groups.append('default') if self.IsMirror: relpath = None diff --git a/project.py b/project.py index e297926d..2b740007 100644 --- a/project.py +++ b/project.py @@ -657,41 +657,21 @@ class Project(object): """Returns true if the manifest groups specified at init should cause this project to be synced. Prefixing a manifest group with "-" inverts the meaning of a group. - All projects are implicitly labelled with "default" unless they are - explicitly labelled "-default". - If any non-inverted manifest groups are specified, the default label - is ignored. - Specifying only inverted groups implies "default". + All projects are implicitly labelled with "default". + + labels are resolved in order. In the example case of + project_groups: "default,group1,group2" + manifest_groups: "-group1,group2" + the project will be matched. """ - project_groups = self.groups - if not manifest_groups: - return not project_groups or not "-default" in project_groups + matched = False + for group in manifest_groups: + if group.startswith('-') and group[1:] in self.groups: + matched = False + elif group in self.groups: + matched = True - if not project_groups: - project_groups = ["default"] - elif not ("default" in project_groups or "-default" in project_groups): - project_groups.append("default") - - plus_groups = [x for x in manifest_groups if not x.startswith("-")] - minus_groups = [x[1:] for x in manifest_groups if x.startswith("-")] - - if not plus_groups: - plus_groups.append("default") - - for group in minus_groups: - if group in project_groups: - # project was excluded by -group - return False - - for group in plus_groups: - if group in project_groups: - # project was included by group - return True - - # groups were specified that did not include this project - if plus_groups: - return False - return True + return matched ## Status Display ## diff --git a/repo b/repo index 75fe9ec2..0aabc0d8 100755 --- a/repo +++ b/repo @@ -28,7 +28,7 @@ if __name__ == '__main__': del magic # increment this whenever we make important changes to this script -VERSION = (1, 15) +VERSION = (1, 16) # increment this if the MAINTAINER_KEYS block is modified KEYRING_VERSION = (1,0) @@ -126,7 +126,7 @@ group.add_option('--depth', type='int', default=None, dest='depth', help='create a shallow clone with given depth; see git clone') group.add_option('-g', '--groups', - dest='groups', default="", + dest='groups', default='default', help='restrict manifest projects to ones with a specified group', metavar='GROUP') diff --git a/subcmds/init.py b/subcmds/init.py index 6cf39d14..d1c497c1 100644 --- a/subcmds/init.py +++ b/subcmds/init.py @@ -14,6 +14,7 @@ # limitations under the License. import os +import re import shutil import sys @@ -87,7 +88,7 @@ to update the working directory files. dest='depth', help='create a shallow clone with given depth; see git clone') g.add_option('-g', '--groups', - dest='groups', default="", + dest='groups', default='default', help='restrict manifest projects to ones with a specified group', metavar='GROUP') @@ -139,7 +140,12 @@ to update the working directory files. r.ResetFetch() r.Save() - m.config.SetString('manifest.groups', opt.groups) + groups = re.split('[,\s]+', opt.groups) + groups = [x for x in groups if x] + groupstr = ','.join(groups) + if groupstr == 'default': + groupstr = None + m.config.SetString('manifest.groups', groupstr) if opt.reference: m.config.SetString('repo.reference', opt.reference)