summaryrefslogtreecommitdiff
path: root/hex.c
diff options
context:
space:
mode:
authorbrian m. carlson <sandals@crustytoothpaste.net>2021-04-26 01:02:55 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-04-27 07:31:38 (GMT)
commit5a6dce70d7bb12ee2bc7926254c5b6741b91ac5f (patch)
treea4350b3f781b36cda38fc645a5eb54b161eb4536 /hex.c
parent0e5e2284f1267293e56e8948143f6cd04c74e2ed (diff)
downloadgit-5a6dce70d7bb12ee2bc7926254c5b6741b91ac5f.zip
git-5a6dce70d7bb12ee2bc7926254c5b6741b91ac5f.tar.gz
git-5a6dce70d7bb12ee2bc7926254c5b6741b91ac5f.tar.bz2
hash: set, copy, and use algo field in struct object_id
Now that struct object_id has an algorithm field, we should populate it. This will allow us to handle object IDs in any supported algorithm and distinguish between them. Ensure that the field is written whenever we write an object ID by storing it explicitly every time we write an object. Set values for the empty blob and tree values as well. In addition, use the algorithm field to compare object IDs. Note that because we zero-initialize struct object_id in many places throughout the codebase, we default to the default algorithm in cases where the algorithm field is zero rather than explicitly initialize all of those locations. This leads to a branch on every comparison, but the alternative is to compare the entire buffer each time and padding the buffer for SHA-1. That alternative ranges up to 3.9% worse than this approach on the perf t0001, t1450, and t1451. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'hex.c')
-rw-r--r--hex.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/hex.c b/hex.c
index da51e64..e7af18f 100644
--- a/hex.c
+++ b/hex.c
@@ -69,7 +69,10 @@ int get_sha1_hex(const char *hex, unsigned char *sha1)
int get_oid_hex_algop(const char *hex, struct object_id *oid,
const struct git_hash_algo *algop)
{
- return get_hash_hex_algop(hex, oid->hash, algop);
+ int ret = get_hash_hex_algop(hex, oid->hash, algop);
+ if (!ret)
+ oid_set_algo(oid, algop);
+ return ret;
}
/*
@@ -80,7 +83,7 @@ int get_oid_hex_any(const char *hex, struct object_id *oid)
{
int i;
for (i = GIT_HASH_NALGOS - 1; i > 0; i--) {
- if (!get_hash_hex_algop(hex, oid->hash, &hash_algos[i]))
+ if (!get_oid_hex_algop(hex, oid, &hash_algos[i]))
return i;
}
return GIT_HASH_UNKNOWN;
@@ -95,7 +98,7 @@ int parse_oid_hex_algop(const char *hex, struct object_id *oid,
const char **end,
const struct git_hash_algo *algop)
{
- int ret = get_hash_hex_algop(hex, oid->hash, algop);
+ int ret = get_oid_hex_algop(hex, oid, algop);
if (!ret)
*end = hex + algop->hexsz;
return ret;