path: root/builtin/describe.c
diff options
authorKarsten Blees <>2014-07-02 22:20:20 (GMT)
committerJunio C Hamano <>2014-07-07 20:56:24 (GMT)
commit039dc71a7cb824300e242f8abc0fcb19dac93641 (patch)
tree9c38bb8655e0314cfe122b7355922c2413533825 /builtin/describe.c
parent6f92e5ff3cdc813de8ef5327fd4bad492fb7d6c9 (diff)
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 <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/describe.c')
1 files changed, 2 insertions, 9 deletions
diff --git a/builtin/describe.c b/builtin/describe.c
index 24d740c..57e84c8 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -56,17 +56,10 @@ static int commit_name_cmp(const struct commit_name *cn1,
return hashcmp(cn1->peeled, peeled ? peeled : cn2->peeled);
-static inline unsigned int hash_sha1(const unsigned char *sha1)
- unsigned int hash;
- memcpy(&hash, sha1, sizeof(hash));
- return hash;
static inline struct commit_name *find_commit_name(const unsigned char *peeled)
struct commit_name key;
- hashmap_entry_init(&key, hash_sha1(peeled));
+ hashmap_entry_init(&key, sha1hash(peeled));
return hashmap_get(&names, &key, peeled);
@@ -114,7 +107,7 @@ static void add_to_known_names(const char *path,
if (!e) {
e = xmalloc(sizeof(struct commit_name));
hashcpy(e->peeled, peeled);
- hashmap_entry_init(e, hash_sha1(peeled));
+ hashmap_entry_init(e, sha1hash(peeled));
hashmap_add(&names, e);
e->path = NULL;