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

Re: [PATCH v3 3/4] The name of the hash function is "SHA-1", not "SHA1"

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Apr 16, 2013, 07:10 UTC
Message-ID
<516CF968.7010606@alum.mit.edu>
In-Reply-To
<7vtxn7slro.fsf@alter.siamese.dyndns.org>
On 04/15/2013 08:15 PM, Junio C Hamano wrote:
Show 12 quoted lines
> Thomas Ackermann <th.acker@arcor.de> writes:
> 
>> Use "SHA-1" instead of "SHA1" whenever we talk about the hash function.
>> When used as a programming symbol, we keep "SHA1".
>>
>> Signed-off-by: Thomas Ackermann <th.acker@arcor.de>
>> ---
> 
> Thanks.  Will queue as-is for now, but I wonder if we want to fix
> them to more official "object name", if we are going to the trouble
> of fixing all of these.  It depends on how many places already
> correctly spell SHA-1, I guess.

I like the idea of making the Git documentation (and the source code) more algorithm-agnostic. But personally, I think "object name" is a bad generic term for describing object hashes. The word "name" suggests a moniker that was intentionally given to the object. I suppose that this is a big reason that the term "SHA-1" is used so frequently rather than "object name"--because it is transparently obvious that an "SHA-1" is a hash as opposed to, say, a filename.

In my opinion, rather than expand the use of the term "object name", we should pick a better official term that makes it more obvious what we are talking about, like "object hash".

While we are at it, if being more algorithm-agnostic is considered a worthy goal, maybe it would be helpful to establish a source code naming convention to be used in new code in favor of "sha1"; for example,

    ohash = hash of an object of unknown type
    chash = hash of a commit object
    etc.

Obviously I'm not suggesting that Git should transition away from using SHA-1s, just that the choice of hashing algorithm need not be quite so explicit in source code that doesn't really need to care.

On a related topic, I find it shocking how often the hard-coded constants "20", "40", and "41" appear in git source code:

    $ git grep -e '\<20\>' -- '*.c' '*.h' '*.sh' '*.perl' | wc -l
    689
    $ git grep -e '\<4[01]\>' -- '*.c' '*.h' '*.sh' '*.perl' | wc -l
    339

The vast majority of these have to do with the length of a SHA-1 hash. I think it would aid source-code readability if there were named constants for the lengths of object hashes in binary and hex format.

Michael
-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
Previous: Junio C HamanoNext: Thomas Ackermann
Message 7 of 10 in “Some small fixes to glossary-content.txt”
  1. 0/4 Some small fixes to glossary-content.txtThomas Ackermann, Apr 15, 2013
  2. 1/4 glossary: remove outdated/misleading/irrelevant entriesThomas Ackermann, Apr 15, 2013
  3. Junio C HamanoApr 15, 2013
  4. 2/4 glossary: improve description of SHA-1 related topicsThomas Ackermann, Apr 15, 2013
  5. 3/4 The name of the hash function is "SHA-1", not "SHA1"Thomas Ackermann, Apr 15, 2013
  6. Junio C HamanoApr 15, 2013
  7. Michael HaggertyApr 16, 2013
  8. 4/4 glossary: improve definitions of refspec and pathspecThomas Ackermann, Apr 15, 2013
  9. Junio C HamanoApr 15, 2013
  10. Aw: Re: [PATCH v3 4/4] glossary: improve definitions of refspec and pathspecThomas Ackermann, Apr 15, 2013

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.