Skip to content

Commit 83e9fa9

Browse files
SomberNightaccumulator
authored andcommitted
recipe.download_file: implement shallow git cloning
1 parent 098098f commit 83e9fa9

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

pythonforandroid/recipe.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -228,24 +228,26 @@ def report_hook(index, blksize, size):
228228
break
229229
return target
230230
elif parsed_url.scheme in ('git', 'git+file', 'git+ssh', 'git+http', 'git+https'):
231-
if isdir(target):
232-
with current_directory(target):
233-
shprint(sh.git, 'fetch', '--tags', '--recurse-submodules')
234-
if self.version:
235-
shprint(sh.git, 'checkout', self.version)
236-
branch = sh.git('branch', '--show-current')
237-
if branch:
238-
shprint(sh.git, 'pull')
239-
shprint(sh.git, 'pull', '--recurse-submodules')
240-
shprint(sh.git, 'submodule', 'update', '--recursive')
241-
else:
231+
if not isdir(target):
242232
if url.startswith('git+'):
243233
url = url[4:]
244-
shprint(sh.git, 'clone', '--recursive', url, target)
234+
# if 'version' is specified, do a shallow clone
245235
if self.version:
236+
shprint(sh.mkdir, '-p', target)
246237
with current_directory(target):
247-
shprint(sh.git, 'checkout', self.version)
248-
shprint(sh.git, 'submodule', 'update', '--recursive')
238+
shprint(sh.git, 'init')
239+
shprint(sh.git, 'remote', 'add', 'origin', url)
240+
else:
241+
shprint(sh.git, 'clone', '--recursive', url, target)
242+
with current_directory(target):
243+
if self.version:
244+
shprint(sh.git, 'fetch', '--depth', '1', 'origin', self.version)
245+
shprint(sh.git, 'checkout', self.version)
246+
branch = sh.git('branch', '--show-current')
247+
if branch:
248+
shprint(sh.git, 'pull')
249+
shprint(sh.git, 'pull', '--recurse-submodules')
250+
shprint(sh.git, 'submodule', 'update', '--recursive', '--init', '--depth', '1')
249251
return target
250252

251253
def apply_patch(self, filename, arch, build_dir=None):

0 commit comments

Comments
 (0)