From 14a2bda32e6508c977b8caf661aea4db42aaa410 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Tue, 2 Nov 2021 08:27:33 +0000 Subject: [PATCH] perf(clone): clone faster without blobs When git 2.27 or newer is installed, we can add `--filter=blob:none` to avoid getting useless information from the git server. This makes clone much faster if your template has a big history. Close https://github.com/copier-org/copier/issues/450 (it does not exactly fix it, but maybe makes it irrelevant). --- README.md | 2 +- copier/vcs.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 54c5002e6..2fc3c125a 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ A library and CLI app for rendering project templates. ## Installation 1. Install Python 3.6.1 or newer (3.8 or newer if you're on Windows). -1. Install Git 2.24 or newer. +1. Install Git 2.27 or newer. 1. To use as a CLI app: `pipx install copier` 1. To use as a library: `pip install copier` diff --git a/copier/vcs.py b/copier/vcs.py index e828ca0a8..4f9bb976b 100644 --- a/copier/vcs.py +++ b/copier/vcs.py @@ -5,6 +5,7 @@ from pathlib import Path from packaging import version +from packaging.version import Version from plumbum import TF, ProcessExecutionError, colors, local from plumbum.cmd import git @@ -13,6 +14,7 @@ GIT_PREFIX = ("git@", "git://", "git+") GIT_POSTFIX = (".git",) +GIT_VERSION = Version(git("version").split()[-1]) REPLACEMENTS = ( (re.compile(r"^gh:/?(.*\.git)$"), r"https://github.com/\1"), (re.compile(r"^gh:/?(.*)$"), r"https://github.com/\1.git"), @@ -117,7 +119,11 @@ def clone(url: str, ref: OptStr = None) -> str: Reference to checkout. For Git repos, defaults to `HEAD`. """ location = tempfile.mkdtemp(prefix=f"{__name__}.clone.") - git("clone", "--no-checkout", url, location) + _clone = git["clone", "--no-checkout", url, location] + # Faster clones if possible + if GIT_VERSION >= Version("2.27"): + _clone = _clone["--filter=blob:none"] + _clone() with local.cwd(location): git("checkout", ref or "HEAD") git("submodule", "update", "--checkout", "--init", "--recursive", "--force")