summaryrefslogtreecommitdiff
path: root/object-file.c
diff options
context:
space:
mode:
authorbrian m. carlson <sandals@crustytoothpaste.net>2021-04-26 01:02:56 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-04-27 07:31:39 (GMT)
commit14228447c9ce664a4e9c31ba10344ec5e4ea4ba5 (patch)
tree75e66ea8ad821e4684497a995d9648658c37fcbf /object-file.c
parent5a6dce70d7bb12ee2bc7926254c5b6741b91ac5f (diff)
downloadgit-14228447c9ce664a4e9c31ba10344ec5e4ea4ba5.zip
git-14228447c9ce664a4e9c31ba10344ec5e4ea4ba5.tar.gz
git-14228447c9ce664a4e9c31ba10344ec5e4ea4ba5.tar.bz2
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>
Diffstat (limited to 'object-file.c')
-rw-r--r--object-file.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/object-file.c b/object-file.c
index d4ba0c4..884855b 100644
--- a/object-file.c
+++ b/object-file.c
@@ -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];