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

Re: Refactoring hardcoded SHA-1 constants

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Apr 19, 2014, 00:06 UTC
Message-ID
<5351BE03.2070604@alum.mit.edu>
In-Reply-To
<20140418224049.GA15516@google.com>
> brian m. carlson wrote:
>> I'd like to introduce a set of preprocessor constants that we'd use
>> instead of hard-coded 20s and 40s everywhere.

I agree that it would help code clarity to have symbolic constants for these numbers.

On 04/19/2014 12:40 AM, Jonathan Nieder wrote:
> Lukewarm on that.  It's hard to do consistently and unless they're
> named well it can be harder to know what something like
> BINARY_OBJECT_NAME_LENGTH means than plain '20' when first reading.

OK, so let's see if we can name them well. (Though I think if the names come into wide use then we'll get familiar with them quickly.)

libgit2 seems to use the name "oid" (for "object ID") where we tend to use "sha1" or "name". That might be a good convention for us to move towards.

Their constants are called GIT_OID_RAWSZ (== 20) and GIT_OID_HEXSZ (== 40). They don't exactly roll off the tongue, I'll admit.

We wouldn't need a "GIT_" prefix, I think, since our code is not meant to be used as a library.

Let the brainstorming (and bikeshedding) begin!
1. GIT_OID_RAWSZ / GIT_OID_HEXSZ
2. OID_RAWSZ / OID_HEXSZ
3. OID_BINARY_LEN / OID_ASCII_LEN
4. BINARY_OID_LEN / ASCII_OID_LEN
Michael
-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
Previous: Jonathan NiederNext: Duy Nguyen
Message 3 of 6 in “Refactoring hardcoded SHA-1 constants”
  1. brian m. carlsonApr 18, 2014
  2. Jonathan NiederApr 18, 2014
  3. Michael HaggertyApr 19, 2014
  4. Duy NguyenApr 19, 2014
  5. Junio C HamanoApr 19, 2014
  6. Duy NguyenApr 19, 2014

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.