manifest: add submanifest.default_groups attribute
When the user does not specify any manifest groups, this allows the
parent manifest to indicate which manifest groups should be used for
syncing the submanifest.
Change-Id: I88806ed35013d13dd2ab3cd245fcd4f9061112c4
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/335474
Tested-by: LaMont Jones <lamontjones@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
diff --git a/docs/manifest-format.md b/docs/manifest-format.md
index 6e67108..0d26296 100644
--- a/docs/manifest-format.md
+++ b/docs/manifest-format.md
@@ -66,6 +66,7 @@
<!ATTLIST submanifest revision CDATA #IMPLIED>
<!ATTLIST submanifest path CDATA #IMPLIED>
<!ATTLIST submanifest groups CDATA #IMPLIED>
+ <!ATTLIST submanifest default-groups CDATA #IMPLIED>
<!ELEMENT project (annotation*,
project*,
@@ -302,6 +303,9 @@
all projects in submanifests carry all parent submanifest groups.
Same syntax as the corresponding element of `project`.
+Attribute `default-groups`: The list of manifest groups to sync if no
+`--groups=` parameter was specified at init. When that list is empty, use this
+list instead of "default" as the list of groups to sync.
### Element project
diff --git a/manifest_xml.py b/manifest_xml.py
index dbab974..3c43295 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -214,6 +214,7 @@
revision: a string, the commitish.
manifestName: a string, the submanifest file name.
groups: a list of strings, the groups to add to all projects in the submanifest.
+ default_groups: a list of strings, the default groups to sync.
path: a string, the relative path for the submanifest checkout.
parent: an XmlManifest, the parent manifest.
annotations: (derived) a list of annotations.
@@ -226,6 +227,7 @@
revision=None,
manifestName=None,
groups=None,
+ default_groups=None,
path=None,
parent=None):
self.name = name
@@ -234,6 +236,7 @@
self.revision = revision
self.manifestName = manifestName
self.groups = groups
+ self.default_groups = default_groups
self.path = path
self.parent = parent
self.annotations = []
@@ -250,7 +253,8 @@
os.path.join(parent.path_prefix, self.relpath), MANIFEST_FILE_NAME)
rc = self.repo_client = RepoClient(
parent.repodir, linkFile, parent_groups=','.join(groups) or '',
- submanifest_path=self.relpath, outer_client=outer_client)
+ submanifest_path=self.relpath, outer_client=outer_client,
+ default_groups=default_groups)
self.present = os.path.exists(manifestFile)
@@ -264,6 +268,7 @@
self.revision == other.revision and
self.manifestName == other.manifestName and
self.groups == other.groups and
+ self.default_groups == other.default_groups and
self.path == other.path and
sorted(self.annotations) == sorted(other.annotations))
@@ -284,6 +289,7 @@
revision = self.revision or self.name
path = self.path or revision.split('/')[-1]
groups = self.groups or []
+ default_groups = self.default_groups or []
return SubmanifestSpec(self.name, manifestUrl, manifestName, revision, path,
groups)
@@ -300,6 +306,10 @@
return ','.join(self.groups)
return ''
+ def GetDefaultGroupsStr(self):
+ """Returns the `default-groups` given for this submanifest."""
+ return ','.join(self.default_groups or [])
+
def AddAnnotation(self, name, value, keep):
"""Add annotations to the submanifest."""
self.annotations.append(Annotation(name, value, keep))
@@ -327,7 +337,8 @@
"""manages the repo configuration file"""
def __init__(self, repodir, manifest_file, local_manifests=None,
- outer_client=None, parent_groups='', submanifest_path=''):
+ outer_client=None, parent_groups='', submanifest_path='',
+ default_groups=None):
"""Initialize.
Args:
@@ -340,6 +351,7 @@
outer_client: RepoClient of the outertree.
parent_groups: a string, the groups to apply to this projects.
submanifest_path: The submanifest root relative to the repo root.
+ default_groups: a string, the default manifest groups to use.
"""
# TODO(vapier): Move this out of this class.
self.globalConfig = GitConfig.ForUser()
@@ -358,6 +370,7 @@
self.local_manifests = local_manifests
self._load_local_manifests = True
self.parent_groups = parent_groups
+ self.default_groups = default_groups
if outer_client and self.isGitcClient:
raise ManifestParseError('Multi-manifest is incompatible with `gitc-init`')
@@ -472,6 +485,8 @@
e.setAttribute('path', r.path)
if r.groups:
e.setAttribute('groups', r.GetGroupsStr())
+ if r.default_groups:
+ e.setAttribute('default-groups', r.GetDefaultGroupsStr())
for a in r.annotations:
if a.keep == 'true':
@@ -967,16 +982,21 @@
worktree=os.path.join(subdir, 'manifests'))
return mp
- def GetDefaultGroupsStr(self):
- """Returns the default group string for the platform."""
- return 'default,platform-' + platform.system().lower()
+ def GetDefaultGroupsStr(self, with_platform=True):
+ """Returns the default group string to use.
+
+ Args:
+ with_platform: a boolean, whether to include the group for the
+ underlying platform.
+ """
+ groups = ','.join(self.default_groups or ['default'])
+ if with_platform:
+ groups += f',platform-{platform.system().lower()}'
+ return groups
def GetGroupsStr(self):
"""Returns the manifest group string that should be synced."""
- groups = self.manifestProject.manifest_groups
- if not groups:
- groups = self.GetDefaultGroupsStr()
- return groups
+ return self.manifestProject.manifest_groups or self.GetDefaultGroupsStr()
def Unload(self):
"""Unload the manifest.
@@ -1491,6 +1511,7 @@
if node.hasAttribute('groups'):
groups = node.getAttribute('groups')
groups = self._ParseList(groups)
+ default_groups = self._ParseList(node.getAttribute('default-groups'))
path = node.getAttribute('path')
if path == '':
path = None
@@ -1511,7 +1532,7 @@
'<submanifest> invalid "path": %s: %s' % (path, msg))
submanifest = _XmlSubmanifest(name, remote, project, revision, manifestName,
- groups, path, self)
+ groups, default_groups, path, self)
for n in node.childNodes:
if n.nodeName == 'annotation':
diff --git a/project.py b/project.py
index 7afd6a7..2641c44 100644
--- a/project.py
+++ b/project.py
@@ -715,7 +715,8 @@
The special manifest group "default" will match any project that
does not have the special project group "notdefault"
"""
- expanded_manifest_groups = manifest_groups or ['default']
+ default_groups = self.manifest.default_groups or ['default']
+ expanded_manifest_groups = manifest_groups or default_groups
expanded_project_groups = ['all'] + (self.groups or [])
if 'notdefault' not in expanded_project_groups:
expanded_project_groups += ['default']
@@ -3496,7 +3497,7 @@
"""
assert _kwargs_only == (), 'Sync only accepts keyword arguments.'
- groups = groups or 'default'
+ groups = groups or self.manifest.GetDefaultGroupsStr(with_platform=False)
platform = platform or 'auto'
git_event_log = git_event_log or EventLog()
if outer_manifest and self.manifest.is_submanifest:
diff --git a/subcmds/info.py b/subcmds/info.py
index 4bedf9d..baa4c5b 100644
--- a/subcmds/info.py
+++ b/subcmds/info.py
@@ -65,8 +65,7 @@
self.manifest = self.manifest.outer_client
manifestConfig = self.manifest.manifestProject.config
mergeBranch = manifestConfig.GetBranch("default").merge
- manifestGroups = (manifestConfig.GetString('manifest.groups')
- or 'all,-notdefault')
+ manifestGroups = self.manifest.GetGroupsStr()
self.heading("Manifest branch: ")
if self.manifest.default.revisionExpr: