hashmap: factor out getting a hash code from a SHA1

Copying the first bytes of a SHA1 is duplicated in six places,
however, the implications (the actual value would depend on the
endianness of the platform) is documented only once.

Add a properly documented API for this.

Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Karsten Blees
2014-07-03 00:20:20 +02:00
committed by Junio C Hamano
parent 6f92e5ff3c
commit 039dc71a7c
8 changed files with 29 additions and 40 deletions

View File

@ -242,14 +242,12 @@ struct file_similarity {
static unsigned int hash_filespec(struct diff_filespec *filespec)
{
unsigned int hash;
if (!filespec->sha1_valid) {
if (diff_populate_filespec(filespec, 0))
return 0;
hash_sha1_file(filespec->data, filespec->size, "blob", filespec->sha1);
}
memcpy(&hash, filespec->sha1, sizeof(hash));
return hash;
return sha1hash(filespec->sha1);
}
static int find_identical_files(struct hashmap *srcs,