From 745be2ede1e67421275afc00c04d996d9d6908ee Mon Sep 17 00:00:00 2001 From: Xin Li Date: Mon, 3 Jun 2019 11:24:30 -0700 Subject: Add support for partial clone. A new option, --partial-clone is added to 'repo init' which tells repo to utilize git's partial clone functionality, which reduces disk and bandwidth usage when downloading by omitting blob downloads initially. Different from restricting clone-depth, the user will have full access to change history, etc., as the objects are downloaded on demand. Change-Id: I60326744875eac16521a007bd7d5481112a98749 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/229532 Reviewed-by: Mike Frysinger Tested-by: Xin Li --- subcmds/init.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'subcmds/init.py') diff --git a/subcmds/init.py b/subcmds/init.py index 1c809ab4..eaa6da50 100644 --- a/subcmds/init.py +++ b/subcmds/init.py @@ -115,6 +115,13 @@ to update the working directory files. g.add_option('--depth', type='int', default=None, dest='depth', help='create a shallow clone with given depth; see git clone') + g.add_option('--partial-clone', action='store_true', + dest='partial_clone', + help='perform partial clone (https://git-scm.com/' + 'docs/gitrepository-layout#_code_partialclone_code)') + g.add_option('--clone-filter', action='store', default='blob:none', + dest='clone_filter', + help='filter for use with --partial-clone [default: %default]') g.add_option('--archive', dest='archive', action='store_true', help='checkout an archive instead of a git repository for ' @@ -253,13 +260,25 @@ to update the working directory files. 'in another location.', file=sys.stderr) sys.exit(1) + if opt.partial_clone: + if opt.mirror: + print('fatal: --mirror and --partial-clone are mutually exclusive', + file=sys.stderr) + sys.exit(1) + m.config.SetString('repo.partialclone', 'true') + if opt.clone_filter: + m.config.SetString('repo.clonefilter', opt.clone_filter) + else: + opt.clone_filter = None + if opt.submodules: m.config.SetString('repo.submodules', 'true') if not m.Sync_NetworkHalf(is_new=is_new, quiet=opt.quiet, clone_bundle=not opt.no_clone_bundle, current_branch_only=opt.current_branch_only, - no_tags=opt.no_tags, submodules=opt.submodules): + no_tags=opt.no_tags, submodules=opt.submodules, + clone_filter=opt.clone_filter): r = m.GetRemote(m.remote.name) print('fatal: cannot obtain manifest %s' % r.url, file=sys.stderr) -- cgit v1.2.3-54-g00ecf