Git fork

hash-ll, hashmap: move oidhash() to hash-ll

oidhash() was used by both hashmap and khash, which makes sense.
However, the location of this function in hashmap.[ch] meant that
khash.h had to depend upon hashmap.h, making people unfamiliar with
khash think that it was built upon hashmap. (Or at least, I personally
was confused for a while about this in the past.)

Move this function to hash-ll, so that khash.h can stop depending upon
hashmap.h.

This has another benefit as well: it allows us to remove hashmap.h's
dependency on hash-ll.h. While some callers of hashmap.h were making
use of oidhash, most were not, so this change provides another way to
reduce the number of includes.

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Elijah Newren and committed by
Junio C Hamano
b9a7ac2c a034e910

+22 -23
-1
decorate.c
··· 3 * data. 4 */ 5 #include "git-compat-util.h" 6 - #include "hashmap.h" 7 #include "object.h" 8 #include "decorate.h" 9
··· 3 * data. 4 */ 5 #include "git-compat-util.h" 6 #include "object.h" 7 #include "decorate.h" 8
+1
dir.h
··· 1 #ifndef DIR_H 2 #define DIR_H 3 4 #include "hashmap.h" 5 #include "pathspec.h" 6 #include "statinfo.h"
··· 1 #ifndef DIR_H 2 #define DIR_H 3 4 + #include "hash-ll.h" 5 #include "hashmap.h" 6 #include "pathspec.h" 7 #include "statinfo.h"
+19
hash-ll.h
··· 270 oid->algo = hash_algo_by_ptr(algop); 271 } 272 273 const char *empty_tree_oid_hex(void); 274 const char *empty_blob_oid_hex(void); 275
··· 270 oid->algo = hash_algo_by_ptr(algop); 271 } 272 273 + /* 274 + * Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code 275 + * for use in hash tables. Cryptographic hashes are supposed to have 276 + * uniform distribution, so in contrast to `memhash()`, this just copies 277 + * the first `sizeof(int)` bytes without shuffling any bits. Note that 278 + * the results will be different on big-endian and little-endian 279 + * platforms, so they should not be stored or transferred over the net. 280 + */ 281 + static inline unsigned int oidhash(const struct object_id *oid) 282 + { 283 + /* 284 + * Equivalent to 'return *(unsigned int *)oid->hash;', but safe on 285 + * platforms that don't support unaligned reads. 286 + */ 287 + unsigned int hash; 288 + memcpy(&hash, oid->hash, sizeof(hash)); 289 + return hash; 290 + } 291 + 292 const char *empty_tree_oid_hex(void); 293 const char *empty_blob_oid_hex(void); 294
-21
hashmap.h
··· 1 #ifndef HASHMAP_H 2 #define HASHMAP_H 3 4 - #include "hash-ll.h" 5 - 6 /* 7 * Generic implementation of hash-based key-value mappings. 8 * ··· 119 unsigned int memhash(const void *buf, size_t len); 120 unsigned int memihash(const void *buf, size_t len); 121 unsigned int memihash_cont(unsigned int hash_seed, const void *buf, size_t len); 122 - 123 - /* 124 - * Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code 125 - * for use in hash tables. Cryptographic hashes are supposed to have 126 - * uniform distribution, so in contrast to `memhash()`, this just copies 127 - * the first `sizeof(int)` bytes without shuffling any bits. Note that 128 - * the results will be different on big-endian and little-endian 129 - * platforms, so they should not be stored or transferred over the net. 130 - */ 131 - static inline unsigned int oidhash(const struct object_id *oid) 132 - { 133 - /* 134 - * Equivalent to 'return *(unsigned int *)oid->hash;', but safe on 135 - * platforms that don't support unaligned reads. 136 - */ 137 - unsigned int hash; 138 - memcpy(&hash, oid->hash, sizeof(hash)); 139 - return hash; 140 - } 141 142 /* 143 * struct hashmap_entry is an opaque structure representing an entry in the
··· 1 #ifndef HASHMAP_H 2 #define HASHMAP_H 3 4 /* 5 * Generic implementation of hash-based key-value mappings. 6 * ··· 117 unsigned int memhash(const void *buf, size_t len); 118 unsigned int memihash(const void *buf, size_t len); 119 unsigned int memihash_cont(unsigned int hash_seed, const void *buf, size_t len); 120 121 /* 122 * struct hashmap_entry is an opaque structure representing an entry in the
-1
khash.h
··· 26 #ifndef __AC_KHASH_H 27 #define __AC_KHASH_H 28 29 - #include "hashmap.h" 30 #include "hash.h" 31 32 #define AC_VERSION_KHASH_H "0.2.8"
··· 26 #ifndef __AC_KHASH_H 27 #define __AC_KHASH_H 28 29 #include "hash.h" 30 31 #define AC_VERSION_KHASH_H "0.2.8"
+1
remote.h
··· 1 #ifndef REMOTE_H 2 #define REMOTE_H 3 4 #include "hashmap.h" 5 #include "refspec.h" 6
··· 1 #ifndef REMOTE_H 2 #define REMOTE_H 3 4 + #include "hash-ll.h" 5 #include "hashmap.h" 6 #include "refspec.h" 7
+1
serve.c
··· 1 #include "git-compat-util.h" 2 #include "repository.h" 3 #include "config.h" 4 #include "pkt-line.h" 5 #include "version.h" 6 #include "ls-refs.h"
··· 1 #include "git-compat-util.h" 2 #include "repository.h" 3 #include "config.h" 4 + #include "hash-ll.h" 5 #include "pkt-line.h" 6 #include "version.h" 7 #include "ls-refs.h"