Replies: 3 comments 4 replies
-
Today there's no API to do this, though it would be straightforward to iterate all the objects in the repository to determine the minimum short hash length. A PR to provide an API would be welcome. |
Beta Was this translation helpful? Give feedback.
-
Traversing all objects would be way too slow for this, especially since it would be something needed often (every time a hash is printed on screen?). I looked into this a while ago and I believe core git estimates the minimum hash it needs based on the number of objects in the repository. It doesn't guarantee that, at that size, there will not be a conflict, but the probability of that happening is very low. And it's really fast since core git uses it to decide the size of the hashes it prints on every command output. Sadly I don't remember where exactly is that code in core git, but libgit2 should probably implement something similar. |
Beta Was this translation helpful? Give feedback.
-
Interesting. I haven't examined this but I assume that it's returning the minimum of |
Beta Was this translation helpful? Give feedback.
-
When you issue the "git log --format=%h" command, Git returns a short hash which is the minimum hash length for the entire repository. If you issue the same command against a shorter hash which is still unique, it will return the same longer length short hash.
Is there a way in LibGit2 to find the short hash length for the entire repository?
I've tried calling git_object_short_id, but it returns the short hash with the minimum length for the target object which may be somewhat shorter than the minimum for repository which the git log command uses. And the set of git_oid_shorten_xxx functions are documented as returning the shortest hash length for the set of IDs being processed which would not be adequate either.
Beta Was this translation helpful? Give feedback.
All reactions