Skip to content

Conversation

PatKamin
Copy link
Contributor

To speed up cloning big repositories, add an option for a shallow clone.

name: str,
force_rebuild: bool = False,
no_suffix_src: bool = False,
shallow_clone: bool = False,
Copy link
Contributor

Choose a reason for hiding this comment

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

why can't this be the default? I think we only need the exact commit/tag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't find a clean way for updating a shallow repo with all kinds of refs (tag, branch, sha). For such repos the way to switch to other commit is to make a clean shallow copy of repo. Most of repositories we use are small enough so we could have some (maybe rare, but still) gains from having a full copy, ie. when debugging an older tag/commit.

On the other hand, having by default a clean shallow copy each time a ref can't be found would ensure that we have a clean state without having to call git --reset or git checkout. It's just that we will have to fetch more data more often.

I'll make a shallow copy a default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

log.debug(f"Cloning {self._url} into {self.src_dir} at commit {self._ref}")
git_clone_cmd = "git clone --recursive"
if self._shallow_clone:
git_clone_cmd += f" --depth 1 --branch {self._ref}"
Copy link
Contributor

Choose a reason for hiding this comment

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

this won't work for commits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Checking if ref is either a branch or a tag, if not, fallback to a full clone.

To speed up cloning big repositories, add an option for a shallow clone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants