hash: provide per-algorithm null OIDs
Up until recently, object IDs did not have an algorithm member, only a hash. Consequently, it was possible to share one null (all-zeros) object ID among all hash algorithms. Now that we're going to be handling objects from multiple hash algorithms, it's important to make sure that all object IDs have a correct algorithm field. Introduce a per-algorithm null OID, and add it to struct hash_algo. Introduce a wrapper function as well, and use it everywhere we used to use the null_oid constant. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
5a6dce70d7
commit
14228447c9
@ -55,7 +55,6 @@
|
||||
"\x6f\xe1\x41\xf7\x74\x91\x20\xa3\x03\x72" \
|
||||
"\x18\x13"
|
||||
|
||||
const struct object_id null_oid;
|
||||
static const struct object_id empty_tree_oid = {
|
||||
.hash = EMPTY_TREE_SHA1_BIN_LITERAL,
|
||||
.algo = GIT_HASH_SHA1,
|
||||
@ -64,6 +63,10 @@ static const struct object_id empty_blob_oid = {
|
||||
.hash = EMPTY_BLOB_SHA1_BIN_LITERAL,
|
||||
.algo = GIT_HASH_SHA1,
|
||||
};
|
||||
static const struct object_id null_oid_sha1 = {
|
||||
.hash = {0},
|
||||
.algo = GIT_HASH_SHA1,
|
||||
};
|
||||
static const struct object_id empty_tree_oid_sha256 = {
|
||||
.hash = EMPTY_TREE_SHA256_BIN_LITERAL,
|
||||
.algo = GIT_HASH_SHA256,
|
||||
@ -72,6 +75,10 @@ static const struct object_id empty_blob_oid_sha256 = {
|
||||
.hash = EMPTY_BLOB_SHA256_BIN_LITERAL,
|
||||
.algo = GIT_HASH_SHA256,
|
||||
};
|
||||
static const struct object_id null_oid_sha256 = {
|
||||
.hash = {0},
|
||||
.algo = GIT_HASH_SHA256,
|
||||
};
|
||||
|
||||
static void git_hash_sha1_init(git_hash_ctx *ctx)
|
||||
{
|
||||
@ -172,6 +179,7 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
|
||||
git_hash_unknown_final_oid,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
},
|
||||
{
|
||||
"sha1",
|
||||
@ -187,6 +195,7 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
|
||||
git_hash_sha1_final_oid,
|
||||
&empty_tree_oid,
|
||||
&empty_blob_oid,
|
||||
&null_oid_sha1,
|
||||
},
|
||||
{
|
||||
"sha256",
|
||||
@ -202,9 +211,15 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
|
||||
git_hash_sha256_final_oid,
|
||||
&empty_tree_oid_sha256,
|
||||
&empty_blob_oid_sha256,
|
||||
&null_oid_sha256,
|
||||
}
|
||||
};
|
||||
|
||||
const struct object_id *null_oid(void)
|
||||
{
|
||||
return the_hash_algo->null_oid;
|
||||
}
|
||||
|
||||
const char *empty_tree_oid_hex(void)
|
||||
{
|
||||
static char buf[GIT_MAX_HEXSZ + 1];
|
||||
|
Reference in New Issue
Block a user