git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Why SHA are 40 bytes? (aka looking for flames)

From
MCMarco Costalba <mcostalba@gmail.com>
Date
Apr 21, 2007, 13:35 UTC
Message-ID
<e5bfff550704210635r4008c3c6tf5f55f970bf85e44@mail.gmail.com>
Well, why to store always the full length SHA?

I know that looking at the code it is better then asking, but indeed asking is better then guessing and in my case looking at the scary sha low level code is almost like (bad) guessing.

We use 40 bytes to disambiguate two unlucky revisions or it is due to UI concerns?

In case it is the former does this apply?

40bytes-sha1 + 40bytes-sha2 == 7**bytes-sha1 + 7bytes-sha2 + "a way to disambiguate the two"*

(*) as example calculating on the fly the full length sha in the unlikely event it is needed, or storing complete 40bytes sha when needed.

(**) 7 is my lucky number ;-)

If in the packed tree truncated sha are stored, togheter of course with corresponding revision data, does it is enough to keep the *same* information of a complete pack?

For performance reasons, probably the inflating should be done only when necessary, it means all git code should use shrinked sha-s, leaving inflating as a remote and unlikely event. What are the real walls about using small length sha everywhere in git code?

Ok. It's enough for collecting a long list of very bad answers. I think I've done my day now!

Thanks for your *kind* reply Marco

Next: Andy Parkins
Message 1 of 18 in “Why SHA are 40 bytes? (aka looking for flames)”
  1. Marco CostalbaApr 21, 2007
  2. Andy ParkinsApr 21, 2007
  3. Karl HasselströmApr 21, 2007
  4. Marco CostalbaApr 21, 2007
  5. Marco CostalbaApr 21, 2007
  6. Jon SmirlApr 21, 2007
  7. Marco CostalbaApr 21, 2007
  8. Jon SmirlApr 21, 2007
  9. Marco CostalbaApr 21, 2007
  10. Jon SmirlApr 21, 2007
  11. Andreas EricssonApr 24, 2007
  12. Nicolas PitreApr 24, 2007
  13. Andreas EricssonApr 24, 2007
  14. Nicolas PitreApr 24, 2007
  15. Nicolas PitreApr 22, 2007
  16. H. Peter AnvinApr 24, 2007
  17. Shawn O. PearceApr 24, 2007
  18. Nicolas PitreApr 24, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.