Skip to content
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

🐛 submodules SHA are truncated to a too small value #1408

Closed
matttbe opened this issue May 3, 2023 · 5 comments · Fixed by #1421
Closed

🐛 submodules SHA are truncated to a too small value #1408

matttbe opened this issue May 3, 2023 · 5 comments · Fixed by #1421

Comments

@matttbe
Copy link

matttbe commented May 3, 2023

Hello,

First, thank you for this very nice project, it really improves many git commands output!

I recently noticed that when a submodule is modified, the 'diff' shows truncated SHA, e.g.

Δ kernelspace
1234567..7654321

Limiting the output to 7 chars is an issue with repos having a lot of commits (e.g. the Linux kernel) and you can get errors like this one if you are unlucky:

error: short object ID 1234567 is ambiguous
hint: The candidates are:
hint:   1234567xxxxxx commit (...)
hint:   1234567yyyyyy tree

It looks like the limitation to 7 chars is hardcoded:

self.config
.minus_style
.paint(minus_commit.chars().take(7).collect::<String>()),
self.config
.plus_style
.paint(commit.chars().take(7).collect::<String>()),

Could it be possible to make this number configurable?
Or showing more chars by default? For the Linux kernel, they recommend to use min 12 digits (but this number might increase in the future)

@dandavison
Copy link
Owner

Hi @matttbe, thanks! How about we bump it to 12? It's not going to have a big effect on the UI if it only affects submodules. Do you feel like making the change?

@matttbe
Copy link
Author

matttbe commented May 3, 2023

Hi @dandavison

Thank you for your quick reply!

Yes, bumping it to 12 would of course be OK for me.
I don't know if there are many (real) repos with more than 1M of commits.

@joshtriplett
Copy link
Contributor

Hardcoding it to 12 just makes the issue less likely, not impossible. And it's possible to brute-force generate objects with partial collisions that shortened hashes would hit.

@matttbe
Copy link
Author

matttbe commented May 26, 2023

Or having a config option?

If not, 12, 14, 16 might be a good compromise. Even with the full sha1, we can have (very unlikely) collisions

@dandavison
Copy link
Owner

dandavison commented May 26, 2023

Yep exactly, collisions are always possible, even using all the bytes in git's object hashes! It's standard in Git UIs to display shorter versions of hashes in places, accepting the fact that the probability of collision is higher. It's just a question of a sensible length; I don't think a config option is necessary.

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 a pull request may close this issue.

3 participants