Stop passing optparse.Values to git_superproject

Make git_superproject independent of the command line by passing
the specific value instead of requiring the caller to have an
optparse.Values object to pass in.

Flag --use-superproject and --archive as incompatible in subcmds/init.py

Change-Id: Ied7c874b312e151038df903c8af4328f070f387c
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/335135
Tested-by: LaMont Jones <lamontjones@google.com>
Reviewed-by: Raman Tenneti <rtenneti@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
LaMont Jones 2022-04-14 14:41:13 +00:00
parent 4ada043dc0
commit 5fa912b0d1
3 changed files with 25 additions and 10 deletions

View File

@ -415,16 +415,26 @@ def _UseSuperprojectFromConfiguration():
return False return False
def PrintMessages(opt, manifest): def PrintMessages(use_superproject, manifest):
"""Returns a boolean if error/warning messages are to be printed.""" """Returns a boolean if error/warning messages are to be printed.
return opt.use_superproject is not None or bool(manifest.superproject)
Args:
use_superproject: option value from optparse.
manifest: manifest to use.
"""
return use_superproject is not None or bool(manifest.superproject)
def UseSuperproject(opt, manifest): def UseSuperproject(use_superproject, manifest):
"""Returns a boolean if use-superproject option is enabled.""" """Returns a boolean if use-superproject option is enabled.
if opt.use_superproject is not None: Args:
return opt.use_superproject use_superproject: option value from optparse.
manifest: manifest to use.
"""
if use_superproject is not None:
return use_superproject
else: else:
client_value = manifest.manifestProject.use_superproject client_value = manifest.manifestProject.use_superproject
if client_value is not None: if client_value is not None:

View File

@ -260,6 +260,9 @@ to update the working directory files.
if opt.use_superproject is not None: if opt.use_superproject is not None:
self.OptionParser.error('--mirror and --use-superproject cannot be ' self.OptionParser.error('--mirror and --use-superproject cannot be '
'used together.') 'used together.')
if opt.archive and opt.use_superproject is not None:
self.OptionParser.error('--archive and --use-superproject cannot be used '
'together.')
if opt.standalone_manifest and (opt.manifest_branch or if opt.standalone_manifest and (opt.manifest_branch or
opt.manifest_name != 'default.xml'): opt.manifest_name != 'default.xml'):

View File

@ -286,7 +286,7 @@ later is required to fix a server side protocol bug.
True if a superproject is requested, otherwise the value of the True if a superproject is requested, otherwise the value of the
current_branch option (True, False or None). current_branch option (True, False or None).
""" """
return git_superproject.UseSuperproject(opt, self.manifest) or opt.current_branch_only return git_superproject.UseSuperproject(opt.use_superproject, self.manifest) or opt.current_branch_only
def _UpdateProjectsRevisionId(self, opt, args, load_local_manifests, superproject_logging_data): def _UpdateProjectsRevisionId(self, opt, args, load_local_manifests, superproject_logging_data):
"""Update revisionId of every project with the SHA from superproject. """Update revisionId of every project with the SHA from superproject.
@ -306,7 +306,8 @@ later is required to fix a server side protocol bug.
""" """
superproject = self.manifest.superproject superproject = self.manifest.superproject
superproject.SetQuiet(opt.quiet) superproject.SetQuiet(opt.quiet)
print_messages = git_superproject.PrintMessages(opt, self.manifest) print_messages = git_superproject.PrintMessages(opt.use_superproject,
self.manifest)
superproject.SetPrintMessages(print_messages) superproject.SetPrintMessages(print_messages)
if opt.local_only: if opt.local_only:
manifest_path = superproject.manifest_path manifest_path = superproject.manifest_path
@ -993,7 +994,8 @@ later is required to fix a server side protocol bug.
self._UpdateManifestProject(opt, mp, manifest_name) self._UpdateManifestProject(opt, mp, manifest_name)
load_local_manifests = not self.manifest.HasLocalManifests load_local_manifests = not self.manifest.HasLocalManifests
use_superproject = git_superproject.UseSuperproject(opt, self.manifest) use_superproject = git_superproject.UseSuperproject(opt.use_superproject,
self.manifest)
if use_superproject and (self.manifest.IsMirror or self.manifest.IsArchive): if use_superproject and (self.manifest.IsMirror or self.manifest.IsArchive):
# Don't use superproject, because we have no working tree. # Don't use superproject, because we have no working tree.
use_superproject = False use_superproject = False