Skip to content

Commit

Permalink
perf: faster blobless git clones (#290)
Browse files Browse the repository at this point in the history
Cloning a repo with git can be really slow if the repo is big.

Adding `--filter=blob:none` to the `git clone` command will make it really faster and slimmer because it will lazy-download blobs on checkout, while only getting commit metadata for whatever is not checked out.
  • Loading branch information
yajo authored Apr 4, 2022
1 parent 6b3ed4a commit f405311
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/poetry/core/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,28 @@ def normalize_url(cls, url: str) -> GitUrl:
def config(self) -> GitConfig:
return self._config

@property
def version(self) -> tuple[int, int, int]:
output = self.run("version")
version = re.search(r"(\d+)\.(\d+)\.(\d+)", output)
if not version:
return (0, 0, 0)
return int(version.group(1)), int(version.group(2)), int(version.group(3))

def clone(self, repository: str, dest: Path) -> str:
self._check_parameter(repository)

return self.run("clone", "--recurse-submodules", "--", repository, str(dest))
cmd = [
"clone",
"--filter=blob:none",
"--recurse-submodules",
"--",
repository,
str(dest),
]
# Blobless clones introduced in Git 2.17
if self.version < (2, 17):
cmd.remove("--filter=blob:none")
return self.run(*cmd)

def checkout(self, rev: str, folder: Path | None = None) -> str:
args = []
Expand Down

0 comments on commit f405311

Please sign in to comment.