mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-02-03 16:14:27 +00:00
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:
parent
24c1308840
commit
971de8ea7b
@ -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():
|
||||
|
@ -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
|
||||
------------------
|
||||
|
@ -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 = ''
|
||||
if node.hasAttribute('groups'):
|
||||
groups = node.getAttribute('groups')
|
||||
if groups:
|
||||
groups = re.split('[,\s]+', groups)
|
||||
else:
|
||||
groups = None
|
||||
groups = [x for x in re.split('[,\s]+', groups) if x]
|
||||
if 'default' not in groups:
|
||||
groups.append('default')
|
||||
|
||||
if self.IsMirror:
|
||||
relpath = None
|
||||
|
46
project.py
46
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 ##
|
||||
|
||||
|
4
repo
4
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')
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user