Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recipe.download_file: implement shallow git cloning #2682

Merged
merged 1 commit into from
Oct 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions pythonforandroid/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,24 +213,26 @@ def report_hook(index, blksize, size):
break
return target
elif parsed_url.scheme in ('git', 'git+file', 'git+ssh', 'git+http', 'git+https'):
if isdir(target):
with current_directory(target):
shprint(sh.git, 'fetch', '--tags', '--recurse-submodules')
if self.version:
shprint(sh.git, 'checkout', self.version)
branch = sh.git('branch', '--show-current')
if branch:
shprint(sh.git, 'pull')
shprint(sh.git, 'pull', '--recurse-submodules')
shprint(sh.git, 'submodule', 'update', '--recursive')
else:
if not isdir(target):
if url.startswith('git+'):
url = url[4:]
shprint(sh.git, 'clone', '--recursive', url, target)
# if 'version' is specified, do a shallow clone
if self.version:
shprint(sh.mkdir, '-p', target)
with current_directory(target):
shprint(sh.git, 'checkout', self.version)
shprint(sh.git, 'submodule', 'update', '--recursive')
shprint(sh.git, 'init')
shprint(sh.git, 'remote', 'add', 'origin', url)
Comment on lines +219 to +224
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have we thought about directly cloning that branch from here and skipping the other code path?
Something like:

shprint(sh.git, 'clone', '--branch', self.version, '--single-branch', url)

I haven't tested so I don't know if the rest of the code apply something we would need still

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which code path do you mean?
Do you mean you would do this instead of

shprint(sh.git, 'fetch', '--depth', '1', 'origin', self.version)
shprint(sh.git, 'checkout', self.version)

but note that version is not necessarily a branch -- I for example always set it to a commit hash, for reproducibility. In that case your command errors.

Also, btw, I could simplify this logic if we raised on version not being set. I am not sure in what scenario it makes sense to set a git repo but not even specify a branch.

The combinatorial matrix of possibilities is surprisingly large here btw,
{isdir(target)}x{version in (not_set, branch, commit)} gives 6 options, and that's not even counting whether there are submodules.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks 👍

else:
shprint(sh.git, 'clone', '--recursive', url, target)
with current_directory(target):
if self.version:
shprint(sh.git, 'fetch', '--depth', '1', 'origin', self.version)
shprint(sh.git, 'checkout', self.version)
branch = sh.git('branch', '--show-current')
if branch:
shprint(sh.git, 'pull')
shprint(sh.git, 'pull', '--recurse-submodules')
shprint(sh.git, 'submodule', 'update', '--recursive', '--init', '--depth', '1')
return target

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