Skip to content

Commit f18dd83

Browse files
committed
recipe.download_file: implement shallow git cloning
When a recipe uses a `git+...` url, and has a `version` specified, only do a shallow git clone. This saves disk space and bandwidth. Tested with a custom qt5 recipe. Without this patch, the git clone on disk was 8.5 GB, now it is 5.0 GB. ``` class Qt5Recipe(BootstrapNDKRecipe): url = 'git+https://code.qt.io/qt/qt5.git' #version = '5.15.2' version = '9b43a43ee96198674060c6b9591e515e2d27c28f' ```
1 parent 25f3a53 commit f18dd83

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
@@ -213,24 +213,26 @@ def report_hook(index, blksize, size):
213213
break
214214
return target
215215
elif parsed_url.scheme in ('git', 'git+file', 'git+ssh', 'git+http', 'git+https'):
216-
if isdir(target):
217-
with current_directory(target):
218-
shprint(sh.git, 'fetch', '--tags', '--recurse-submodules')
219-
if self.version:
220-
shprint(sh.git, 'checkout', self.version)
221-
branch = sh.git('branch', '--show-current')
222-
if branch:
223-
shprint(sh.git, 'pull')
224-
shprint(sh.git, 'pull', '--recurse-submodules')
225-
shprint(sh.git, 'submodule', 'update', '--recursive')
226-
else:
216+
if not isdir(target):
227217
if url.startswith('git+'):
228218
url = url[4:]
229-
shprint(sh.git, 'clone', '--recursive', url, target)
219+
# if 'version' is specified, do a shallow clone
230220
if self.version:
221+
shprint(sh.mkdir, '-p', target)
231222
with current_directory(target):
232-
shprint(sh.git, 'checkout', self.version)
233-
shprint(sh.git, 'submodule', 'update', '--recursive')
223+
shprint(sh.git, 'init')
224+
shprint(sh.git, 'remote', 'add', 'origin', url)
225+
else:
226+
shprint(sh.git, 'clone', '--recursive', url, target)
227+
with current_directory(target):
228+
if self.version:
229+
shprint(sh.git, 'fetch', '--depth', '1', 'origin', self.version)
230+
shprint(sh.git, 'checkout', self.version)
231+
branch = sh.git('branch', '--show-current')
232+
if branch:
233+
shprint(sh.git, 'pull')
234+
shprint(sh.git, 'pull', '--recurse-submodules')
235+
shprint(sh.git, 'submodule', 'update', '--recursive', '--init', '--depth', '1')
234236
return target
235237

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

0 commit comments

Comments
 (0)