Checkout hash from SourceId

How can I get the hash for a SourceId that is used in ~/.cargo/git/checkouts/?

Or in other words:
How can I get the path to the git sources of a dependency defined in a Cargo.lock file?

I tried:

let source_id = SourceId::from_url(source).unwrap();
let hash = cargo::util::hex::short_hash(&source_id);

But this is different from what I found in the filesystem.

I think you have to use SourceId::from_git with the git repo url (not the file path) and the git reference (commit id, branch name, ...) as argument.

@bjorn3 there is no SourceId::from_git but SourceId::for_git that do not create the expected hash :disappointed_face:

I found it!
It's the ident function that is not public but easy to copy :wink: