diff options
author | Patrick Steinhardt <ps@pks.im> | 2017-04-21 07:31:56 +0000 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2017-04-28 14:05:45 +0200 |
commit | 35079f507b5287a2a4726cae7753439f753453e2 (patch) | |
tree | 65ead793083b46ad4a813d1b488a6f01af451c87 /src/odb.c | |
parent | 28a0741f1ae6f5e1261c8e73854dda69e7a61067 (diff) | |
download | libgit2-35079f507b5287a2a4726cae7753439f753453e2.tar.gz |
odb: add option to turn off hash verification
Verifying hashsums of objects we are reading from the ODB may be costly
as we have to perform an additional hashsum calculation on the object.
Especially when reading large objects, the penalty can be as high as
35%, as can be seen when executing the equivalent of `git cat-file` with
and without verification enabled. To mitigate for this, we add a global
option for libgit2 which enables the developer to turn off the
verification, e.g. when he can be reasonably sure that the objects on
disk won't be corrupted.
Diffstat (limited to 'src/odb.c')
-rw-r--r-- | src/odb.c | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -31,6 +31,8 @@ #define GIT_ALTERNATES_MAX_DEPTH 5 +bool git_odb__strict_hash_verification = true; + typedef struct { git_odb_backend *backend; @@ -1027,12 +1029,14 @@ static int odb_read_1(git_odb_object **out, git_odb *db, const git_oid *id, if (!found) return GIT_ENOTFOUND; - if ((error = git_odb_hash(&hashed, raw.data, raw.len, raw.type)) < 0) - goto out; + if (git_odb__strict_hash_verification) { + if ((error = git_odb_hash(&hashed, raw.data, raw.len, raw.type)) < 0) + goto out; - if (!git_oid_equal(id, &hashed)) { - error = git_odb__error_mismatch(id, &hashed); - goto out; + if (!git_oid_equal(id, &hashed)) { + error = git_odb__error_mismatch(id, &hashed); + goto out; + } } giterr_clear(); |