Skip to content

Implement #624: Use shorter hashes with CPM_SOURCE_CACHE #631

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

Merged
merged 10 commits into from
May 18, 2025

Conversation

codeinred
Copy link
Contributor

Some systems have pathname limits (eg, windows). If a project has multiple levels of nested directories, it can be easy to hit those limits, and having a 40-character hash in the pathname contributes to this problem.

Shorter hashes do increase the chance of a collision. This PR implements shorter hashes as follows:

  1. Take an input hash
  2. Take gradually longer substrings until we've identified the shortest substring that uniquely identifies the hash (eg, trying a substring of length 4, then 8, then 12, and so on)

See #624 for more information.

Checks if the contents of a file matches the given input
Uses shorter hashes with CPM_SOURCE_CACHE. Falls back to a longer hash
if necessary (ie, if there's a collision with an existing hash).

See: cpm-cmake#624
Copy link
Member

@TheLartians TheLartians left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! I've modified the code slightly so that it will still recognise legacy cache hashs, avoiding duplicating our user's cache size after the update.

@TheLartians TheLartians merged commit d9364ce into cpm-cmake:master May 18, 2025
11 checks passed
@TheLartians
Copy link
Member

Feature published in v0.42.0 🎉

@codeinred
Copy link
Contributor Author

Awesome!!! Thank you!

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