repo: move parser init out of module scope

We import the wrapper on the fly, so minimize how much code we run
in module scope.  It's pointless/wasted when importing.

Change-Id: I4a71c2030325d0a639585671cd7ebe8f22687ecd
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/254072
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Reviewed-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
Mike Frysinger 2020-02-06 00:04:21 -05:00
parent 6f1c626a9b
commit f700ac79c3

96
repo
View File

@ -204,87 +204,72 @@ gpg_dir = os.path.join(home_dot_repo, 'gnupg')
extra_args = [] extra_args = []
init_optparse = optparse.OptionParser(usage="repo init -u url [options]") init_optparse = optparse.OptionParser(usage="repo init -u url [options]")
# Logging def _InitParser():
group = init_optparse.add_option_group('Logging options') """Setup the init subcommand parser."""
group.add_option('-q', '--quiet', # Logging.
dest="quiet", action="store_true", default=False, group = init_optparse.add_option_group('Logging options')
help="be quiet") group.add_option('-q', '--quiet',
action='store_true', default=False,
help='be quiet')
# Manifest # Manifest.
group = init_optparse.add_option_group('Manifest options') group = init_optparse.add_option_group('Manifest options')
group.add_option('-u', '--manifest-url', group.add_option('-u', '--manifest-url',
dest='manifest_url',
help='manifest repository location', metavar='URL') help='manifest repository location', metavar='URL')
group.add_option('-b', '--manifest-branch', group.add_option('-b', '--manifest-branch',
dest='manifest_branch',
help='manifest branch or revision', metavar='REVISION') help='manifest branch or revision', metavar='REVISION')
group.add_option('-m', '--manifest-name', group.add_option('-m', '--manifest-name',
dest='manifest_name',
help='initial manifest file', metavar='NAME.xml') help='initial manifest file', metavar='NAME.xml')
group.add_option('--current-branch', group.add_option('--current-branch',
dest='current_branch_only', action='store_true', dest='current_branch_only', action='store_true',
help='fetch only current manifest branch from server') help='fetch only current manifest branch from server')
group.add_option('--mirror', group.add_option('--mirror', action='store_true',
dest='mirror', action='store_true',
help='create a replica of the remote repositories ' help='create a replica of the remote repositories '
'rather than a client working directory') 'rather than a client working directory')
group.add_option('--reference', group.add_option('--reference',
dest='reference',
help='location of mirror directory', metavar='DIR') help='location of mirror directory', metavar='DIR')
group.add_option('--dissociate', group.add_option('--dissociate', action='store_true',
dest='dissociate', action='store_true',
help='dissociate from reference mirrors after clone') help='dissociate from reference mirrors after clone')
group.add_option('--depth', type='int', default=None, group.add_option('--depth', type='int', default=None,
dest='depth', help='create a shallow clone with given depth; '
help='create a shallow clone with given depth; see git clone') 'see git clone')
group.add_option('--partial-clone', action='store_true', group.add_option('--partial-clone', action='store_true',
dest='partial_clone',
help='perform partial clone (https://git-scm.com/' help='perform partial clone (https://git-scm.com/'
'docs/gitrepository-layout#_code_partialclone_code)') 'docs/gitrepository-layout#_code_partialclone_code)')
group.add_option('--clone-filter', action='store', default='blob:none', group.add_option('--clone-filter', action='store', default='blob:none',
dest='clone_filter', help='filter for use with --partial-clone '
help='filter for use with --partial-clone [default: %default]') '[default: %default]')
group.add_option('--archive', group.add_option('--archive', action='store_true',
dest='archive', action='store_true',
help='checkout an archive instead of a git repository for ' help='checkout an archive instead of a git repository for '
'each project. See git archive.') 'each project. See git archive.')
group.add_option('--submodules', group.add_option('--submodules', action='store_true',
dest='submodules', action='store_true',
help='sync any submodules associated with the manifest repo') help='sync any submodules associated with the manifest repo')
group.add_option('-g', '--groups', group.add_option('-g', '--groups', default='default',
dest='groups', default='default',
help='restrict manifest projects to ones with specified ' help='restrict manifest projects to ones with specified '
'group(s) [default|all|G1,G2,G3|G4,-G5,-G6]', 'group(s) [default|all|G1,G2,G3|G4,-G5,-G6]',
metavar='GROUP') metavar='GROUP')
group.add_option('-p', '--platform', group.add_option('-p', '--platform', default='auto',
dest='platform', default="auto",
help='restrict manifest projects to ones with a specified ' help='restrict manifest projects to ones with a specified '
'platform group [auto|all|none|linux|darwin|...]', 'platform group [auto|all|none|linux|darwin|...]',
metavar='PLATFORM') metavar='PLATFORM')
group.add_option('--no-clone-bundle', group.add_option('--no-clone-bundle', action='store_true',
dest='no_clone_bundle', action='store_true',
help='disable use of /clone.bundle on HTTP/HTTPS') help='disable use of /clone.bundle on HTTP/HTTPS')
group.add_option('--no-tags', group.add_option('--no-tags', action='store_true',
dest='no_tags', action='store_true',
help="don't fetch tags in the manifest") help="don't fetch tags in the manifest")
# Tool.
# Tool group = init_optparse.add_option_group('repo Version options')
group = init_optparse.add_option_group('repo Version options') group.add_option('--repo-url', metavar='URL',
group.add_option('--repo-url', help='repo repository location ($REPO_URL)')
dest='repo_url', group.add_option('--repo-branch', metavar='REVISION',
help='repo repository location ($REPO_URL)', metavar='URL') help='repo branch or revision ($REPO_REV)')
group.add_option('--repo-branch', group.add_option('--no-repo-verify', action='store_true',
dest='repo_branch',
help='repo branch or revision ($REPO_REV)', metavar='REVISION')
group.add_option('--no-repo-verify',
dest='no_repo_verify', action='store_true',
help='do not verify repo source code') help='do not verify repo source code')
# Other # Other.
group = init_optparse.add_option_group('Other options') group = init_optparse.add_option_group('Other options')
group.add_option('--config-name', group.add_option('--config-name',
dest='config_name', action="store_true", default=False, action='store_true', default=False,
help='Always prompt for name/e-mail') help='Always prompt for name/e-mail')
@ -931,6 +916,7 @@ def main(orig_args):
'command from the corresponding client under /gitc/', 'command from the corresponding client under /gitc/',
file=sys.stderr) file=sys.stderr)
sys.exit(1) sys.exit(1)
_InitParser()
if not repo_main: if not repo_main:
if opt.help: if opt.help:
_Usage() _Usage()