Refine groups functionality

Every project is in group "default".  "-default" does not remove
it from this project.  All group names specified in the manifest
are positive names as opposed to a mix of negative and positive.

Specified groups are resolved in order.  If init is supplied with
--groups="group1,-group2", the following describes the project
selection when syncing:

  * all projects in "group1" will be added, and
  * all projects in "group2" will be removed.

Change-Id: I1df3dcdb64bbd4cd80d675f9b2d3becbf721f661
This commit is contained in:
Conley Owens 2012-04-16 10:36:08 -07:00 committed by Shawn O. Pearce
parent 24c1308840
commit 971de8ea7b
6 changed files with 41 additions and 51 deletions

View File

@ -68,8 +68,9 @@ class Command(object):
mp = self.manifest.manifestProject mp = self.manifest.manifestProject
groups = mp.config.GetString('manifest.groups') groups = mp.config.GetString('manifest.groups')
if groups: if groups is None:
groups = re.split('[,\s]+', groups) groups = 'default'
groups = [x for x in re.split('[,\s]+', groups) if x]
if not args: if not args:
for project in all.values(): for project in all.values():

View File

@ -165,8 +165,8 @@ been extensively tested. If not supplied the revision given by
the default element is used. the default element is used.
Attribute `groups`: List of groups to which this project belongs, Attribute `groups`: List of groups to which this project belongs,
whitespace or comma separated. All projects are part of the group whitespace or comma separated. All projects belong to the group
"default" unless "-default" is specified in the list of groups. "default".
Element annotation Element annotation
------------------ ------------------

View File

@ -122,8 +122,9 @@ class XmlManifest(object):
mp = self.manifestProject mp = self.manifestProject
groups = mp.config.GetString('manifest.groups') groups = mp.config.GetString('manifest.groups')
if groups: if groups is None:
groups = re.split('[,\s]+', groups) groups = 'default'
groups = [x for x in re.split(r'[,\s]+', groups) if x]
doc = xml.dom.minidom.Document() doc = xml.dom.minidom.Document()
root = doc.createElement('manifest') root = doc.createElement('manifest')
@ -200,8 +201,9 @@ class XmlManifest(object):
ce.setAttribute('dest', c.dest) ce.setAttribute('dest', c.dest)
e.appendChild(ce) e.appendChild(ce)
if p.groups: egroups = [g for g in p.groups if g != 'default']
e.setAttribute('groups', ','.join(p.groups)) if egroups:
e.setAttribute('groups', ','.join(egroups))
for a in p.annotations: for a in p.annotations:
if a.keep == "true": if a.keep == "true":
@ -524,11 +526,12 @@ class XmlManifest(object):
else: else:
rebase = rebase.lower() in ("yes", "true", "1") rebase = rebase.lower() in ("yes", "true", "1")
groups = node.getAttribute('groups') groups = ''
if groups: if node.hasAttribute('groups'):
groups = re.split('[,\s]+', groups) groups = node.getAttribute('groups')
else: groups = [x for x in re.split('[,\s]+', groups) if x]
groups = None if 'default' not in groups:
groups.append('default')
if self.IsMirror: if self.IsMirror:
relpath = None relpath = None

View File

@ -657,41 +657,21 @@ class Project(object):
"""Returns true if the manifest groups specified at init should cause """Returns true if the manifest groups specified at init should cause
this project to be synced. this project to be synced.
Prefixing a manifest group with "-" inverts the meaning of a group. Prefixing a manifest group with "-" inverts the meaning of a group.
All projects are implicitly labelled with "default" unless they are All projects are implicitly labelled with "default".
explicitly labelled "-default".
If any non-inverted manifest groups are specified, the default label labels are resolved in order. In the example case of
is ignored. project_groups: "default,group1,group2"
Specifying only inverted groups implies "default". manifest_groups: "-group1,group2"
the project will be matched.
""" """
project_groups = self.groups matched = False
if not manifest_groups: for group in manifest_groups:
return not project_groups or not "-default" in project_groups if group.startswith('-') and group[1:] in self.groups:
matched = False
elif group in self.groups:
matched = True
if not project_groups: return matched
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
## Status Display ## ## Status Display ##

4
repo
View File

@ -28,7 +28,7 @@ if __name__ == '__main__':
del magic del magic
# increment this whenever we make important changes to this script # 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 # increment this if the MAINTAINER_KEYS block is modified
KEYRING_VERSION = (1,0) KEYRING_VERSION = (1,0)
@ -126,7 +126,7 @@ group.add_option('--depth', type='int', default=None,
dest='depth', dest='depth',
help='create a shallow clone with given depth; see git clone') help='create a shallow clone with given depth; see git clone')
group.add_option('-g', '--groups', group.add_option('-g', '--groups',
dest='groups', default="", dest='groups', default='default',
help='restrict manifest projects to ones with a specified group', help='restrict manifest projects to ones with a specified group',
metavar='GROUP') metavar='GROUP')

View File

@ -14,6 +14,7 @@
# limitations under the License. # limitations under the License.
import os import os
import re
import shutil import shutil
import sys import sys
@ -87,7 +88,7 @@ to update the working directory files.
dest='depth', dest='depth',
help='create a shallow clone with given depth; see git clone') help='create a shallow clone with given depth; see git clone')
g.add_option('-g', '--groups', g.add_option('-g', '--groups',
dest='groups', default="", dest='groups', default='default',
help='restrict manifest projects to ones with a specified group', help='restrict manifest projects to ones with a specified group',
metavar='GROUP') metavar='GROUP')
@ -139,7 +140,12 @@ to update the working directory files.
r.ResetFetch() r.ResetFetch()
r.Save() 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: if opt.reference:
m.config.SetString('repo.reference', opt.reference) m.config.SetString('repo.reference', opt.reference)