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

Re: [PATCH] introduce inline is_same_sha1

From
Junio C Hamano <junkio@cox.net>
Date
Aug 17, 2006, 01:12 UTC
Message-ID
<7vveos17ym.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.63.0608161721020.11465@chino.corp.google.com>
David Rientjes <rientjes@google.com> writes:
Show 15 quoted lines
> Introduces global inline:
> 	is_same_sha1(const unsigned char *sha1,
> 		     const unsigned char *sha2);
>
> Uses memcmp for comparison and returns the result.  All tests
> for comparisons for sha1 have been changed to use the new
> global inline, but existing uses of memcmp have been preserved
> where the return value other than 0 is needed, i.e.:
>
> 	int cmp = !memcmp(old_sha1, new_sha1, 20);
>
> Conversions from char* to unsigned char* casts have been made
> where appropriate.
>
> Signed-off-by: David Rientjes <rientjes@google.com>
I would have expected the inline function to be:
	int cmp_object_name(const void *, const void *)
No need for "unsigned char *" that way [*1*].  

I do not know what your ultimate goal with this patch is, but I like the fact that we do not have to hardcode "20" everywhere. With a yet-to-be-written companion patch to make the "20" into a symbolic constant OBJECT_NAME_LENGTH, we could someday have a flag day to use a hash different from SHA-1 with an updated 'git-convert-objects' ;-).

I would have liked if the function were to give the comparison results similar to standard comparison functions such as memcmp and strcmp. I do not know off-hand if we order by the object names, and we might only be interested in equality tests, but still...

Line-wrap the message for comfortable viewing on 80-column terminals, please.

[Footnote]
*1* On the other hand if stricter type checking is wanted,
    "const unsigned char *" is too weak.  We would need either
    sparse annotation or a new type (maybe a struct that has a
    single member that has 20-byte uchar array).  I personally
    think that is an overkill, though.
Previous: David RientjesNext: David Rientjes
Message 2 of 8 in “introduce inline is_same_sha1”
  1. introduce inline is_same_sha1David Rientjes, Aug 17, 2006
  2. Junio C HamanoAug 17, 2006
  3. David RientjesAug 17, 2006
  4. Junio C HamanoAug 17, 2006
  5. Alex RiesenAug 17, 2006
  6. David RientjesAug 17, 2006
  7. Alex RiesenAug 17, 2006
  8. Junio C HamanoAug 18, 2006

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.