Origin of hash in folder name for cargo git dependencies

Git dependencies are by default cloned bare under $HOME/.cargo/git/db/ and the appropriate commit(s) are checked out under $HOME/.cargo/git/checkouts/, in subfolders named after the commit (Cargo Home - The Cargo Book).

The top-level folder name under both db and checkouts is the package name concatenated with some sort of hash (basically confirmed here) ; for example, I have a git dependency on tokio in one of my projects that is checked out in a folder named tokio-17689456922d6a5f. The individually checked out commits appear as subfolders of this top-level folder.

Is there any documentation on where this hash comes from or how it is calculated, and why it is useful to have it (probably for package name collisions across registries?)? I understand that it might be an unstable/internal detail. It seems that for git dependencies of the same package the hash is stable, but across packages it might not be.

The hash is a hash of cargo's internal representation of the repo path. It isn't guaranteed to be stable, but in practice rarely changes to allow reusing the same cloned repo between multiple cargo versions and thus avoid having to clone it again every time you update rust.

1 Like

I see; thanks for the info!

Hi :grinning:, I am curious why this path is calculated as a hash value, avoid some escape symbols in the URL? or performance ?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.