Skip to content

Commit 27f3796

Browse files
hanwengitster
authored andcommitted
hash.h: provide constants for the hash IDs
This will simplify referencing them from code that is not deeply integrated with Git, in particular, the reftable library. Signed-off-by: Han-Wen Nienhuys <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c420321 commit 27f3796

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

hash.h

+6
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,18 @@ static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *s
9595
/* Number of algorithms supported (including unknown). */
9696
#define GIT_HASH_NALGOS (GIT_HASH_SHA256 + 1)
9797

98+
/* "sha1", big-endian */
99+
#define GIT_SHA1_FORMAT_ID 0x73686131
100+
98101
/* The length in bytes and in hex digits of an object name (SHA-1 value). */
99102
#define GIT_SHA1_RAWSZ 20
100103
#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)
101104
/* The block size of SHA-1. */
102105
#define GIT_SHA1_BLKSZ 64
103106

107+
/* "s256", big-endian */
108+
#define GIT_SHA256_FORMAT_ID 0x73323536
109+
104110
/* The length in bytes and in hex digits of an object name (SHA-256 value). */
105111
#define GIT_SHA256_RAWSZ 32
106112
#define GIT_SHA256_HEXSZ (2 * GIT_SHA256_RAWSZ)

object-file.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ static void git_hash_unknown_final_oid(struct object_id *oid, git_hash_ctx *ctx)
164164
BUG("trying to finalize unknown hash");
165165
}
166166

167-
168167
const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
169168
{
170169
NULL,
@@ -183,8 +182,7 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
183182
},
184183
{
185184
"sha1",
186-
/* "sha1", big-endian */
187-
0x73686131,
185+
GIT_SHA1_FORMAT_ID,
188186
GIT_SHA1_RAWSZ,
189187
GIT_SHA1_HEXSZ,
190188
GIT_SHA1_BLKSZ,
@@ -199,8 +197,7 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
199197
},
200198
{
201199
"sha256",
202-
/* "s256", big-endian */
203-
0x73323536,
200+
GIT_SHA256_FORMAT_ID,
204201
GIT_SHA256_RAWSZ,
205202
GIT_SHA256_HEXSZ,
206203
GIT_SHA256_BLKSZ,

0 commit comments

Comments
 (0)