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

Conversation

SomberNight
Copy link
Contributor

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 = '9b43a43ee96198674060c6b9591e515e2d27c28f'  # version 5.15.2

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'
```
Copy link
Member

@AndreMiras AndreMiras left a comment

Choose a reason for hiding this comment

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

LGTM, made a suggestion if you want to take a look

Comment on lines +219 to +224
# 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)
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 👍

@AndreMiras AndreMiras merged commit 5b9b382 into kivy:develop Oct 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants