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

144
repo
View File

@ -204,88 +204,73 @@ 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', help='manifest branch or revision', metavar='REVISION')
dest='manifest_branch', group.add_option('-m', '--manifest-name',
help='manifest branch or revision', metavar='REVISION') help='initial manifest file', metavar='NAME.xml')
group.add_option('-m', '--manifest-name', group.add_option('--current-branch',
dest='manifest_name', dest='current_branch_only', action='store_true',
help='initial manifest file', metavar='NAME.xml') help='fetch only current manifest branch from server')
group.add_option('--current-branch', group.add_option('--mirror', action='store_true',
dest='current_branch_only', action='store_true', help='create a replica of the remote repositories '
help='fetch only current manifest branch from server') 'rather than a client working directory')
group.add_option('--mirror', group.add_option('--reference',
dest='mirror', action='store_true', help='location of mirror directory', metavar='DIR')
help='create a replica of the remote repositories ' group.add_option('--dissociate', action='store_true',
'rather than a client working directory') help='dissociate from reference mirrors after clone')
group.add_option('--reference', group.add_option('--depth', type='int', default=None,
dest='reference', help='create a shallow clone with given depth; '
help='location of mirror directory', metavar='DIR') 'see git clone')
group.add_option('--dissociate', group.add_option('--partial-clone', action='store_true',
dest='dissociate', action='store_true', help='perform partial clone (https://git-scm.com/'
help='dissociate from reference mirrors after clone') 'docs/gitrepository-layout#_code_partialclone_code)')
group.add_option('--depth', type='int', default=None, group.add_option('--clone-filter', action='store', default='blob:none',
dest='depth', help='filter for use with --partial-clone '
help='create a shallow clone with given depth; see git clone') '[default: %default]')
group.add_option('--partial-clone', action='store_true', group.add_option('--archive', action='store_true',
dest='partial_clone', help='checkout an archive instead of a git repository for '
help='perform partial clone (https://git-scm.com/' 'each project. See git archive.')
'docs/gitrepository-layout#_code_partialclone_code)') group.add_option('--submodules', action='store_true',
group.add_option('--clone-filter', action='store', default='blob:none', help='sync any submodules associated with the manifest repo')
dest='clone_filter', group.add_option('-g', '--groups', default='default',
help='filter for use with --partial-clone [default: %default]') help='restrict manifest projects to ones with specified '
group.add_option('--archive', 'group(s) [default|all|G1,G2,G3|G4,-G5,-G6]',
dest='archive', action='store_true', metavar='GROUP')
help='checkout an archive instead of a git repository for ' group.add_option('-p', '--platform', default='auto',
'each project. See git archive.') help='restrict manifest projects to ones with a specified '
group.add_option('--submodules', 'platform group [auto|all|none|linux|darwin|...]',
dest='submodules', action='store_true', metavar='PLATFORM')
help='sync any submodules associated with the manifest repo') group.add_option('--no-clone-bundle', action='store_true',
group.add_option('-g', '--groups', help='disable use of /clone.bundle on HTTP/HTTPS')
dest='groups', default='default', group.add_option('--no-tags', action='store_true',
help='restrict manifest projects to ones with specified ' help="don't fetch tags in the manifest")
'group(s) [default|all|G1,G2,G3|G4,-G5,-G6]',
metavar='GROUP')
group.add_option('-p', '--platform',
dest='platform', default="auto",
help='restrict manifest projects to ones with a specified '
'platform group [auto|all|none|linux|darwin|...]',
metavar='PLATFORM')
group.add_option('--no-clone-bundle',
dest='no_clone_bundle', action='store_true',
help='disable use of /clone.bundle on HTTP/HTTPS')
group.add_option('--no-tags',
dest='no_tags', action='store_true',
help="don't fetch tags in the manifest")
# Tool.
group = init_optparse.add_option_group('repo Version options')
group.add_option('--repo-url', metavar='URL',
help='repo repository location ($REPO_URL)')
group.add_option('--repo-branch', metavar='REVISION',
help='repo branch or revision ($REPO_REV)')
group.add_option('--no-repo-verify', action='store_true',
help='do not verify repo source code')
# Tool # Other.
group = init_optparse.add_option_group('repo Version options') group = init_optparse.add_option_group('Other options')
group.add_option('--repo-url', group.add_option('--config-name',
dest='repo_url', action='store_true', default=False,
help='repo repository location ($REPO_URL)', metavar='URL') help='Always prompt for name/e-mail')
group.add_option('--repo-branch',
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')
# Other
group = init_optparse.add_option_group('Other options')
group.add_option('--config-name',
dest='config_name', action="store_true", default=False,
help='Always prompt for name/e-mail')
def _GitcInitOptions(init_optparse_arg): def _GitcInitOptions(init_optparse_arg):
@ -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()