Re: [PATCH] introduce inline is_same_sha1

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Rientjes <rientjes@xxxxxxxxxx> writes:

> 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@xxxxxxxxxx>

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.

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]