cpm-cmake / CPM.cmake

📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature request] Use git worktrees instead of individual clones in cache

touraill-adobe opened this issue · comments

When using CPM_SOURCE_CACHE, each dependency is cloned in its own folder even if they are just different commits of the same repo. It seems to me that using git worktree would greatly optimize the download time and storage usage, by cloning a remote repo only once.

The behavior I would expect would be to have one folder in the cache per repo url, that contains a bare repo, then the usual hashed folders with worktrees created from this repo.

What do you think?

That's a pretty cool git feature I wasn't aware of! I agree it would make a lot of sense for CPM to use this feature.

Today I learned about git clone --reference-if-able, which may be a simpler alternative to worktrees in the context of CPM. It allows retrieving git objects from an existing local clone, to avoid downloading them from the remote server. clone times are dramatically reduced (like a factor of 10 or more, depending on your network). If you want to be safe you can add --dissociate to not borrow the objects from the local reference but copy them, which is a little longer but still saves a lot of time by avoiding some download.

I'm not sure what flexibility you have in CPM w.r.t. git commands but if you can inject custom arguments, and if you can easily find a previous clone of a repo in the CPM cache, then I think this optimization would be worth investigating.