Merge branch 'tb/unsafe-hash-cleanup' into ps/hash-cleanup
* tb/unsafe-hash-cleanup: hash.h: drop unsafe_ function variants csum-file: introduce hashfile_checkpoint_init() t/helper/test-hash.c: use unsafe_hash_algo() csum-file.c: use unsafe_hash_algo() hash.h: introduce `unsafe_hash_algo()` csum-file.c: extract algop from hashfile_checksum_valid() csum-file: store the hash algorithm as a struct field t/helper/test-tool: implement sha1-unsafe helper
This commit is contained in:
@@ -202,6 +202,22 @@ static void git_hash_unknown_final_oid(struct object_id *oid UNUSED,
|
||||
BUG("trying to finalize unknown hash");
|
||||
}
|
||||
|
||||
static const struct git_hash_algo sha1_unsafe_algo = {
|
||||
.name = "sha1",
|
||||
.format_id = GIT_SHA1_FORMAT_ID,
|
||||
.rawsz = GIT_SHA1_RAWSZ,
|
||||
.hexsz = GIT_SHA1_HEXSZ,
|
||||
.blksz = GIT_SHA1_BLKSZ,
|
||||
.init_fn = git_hash_sha1_init_unsafe,
|
||||
.clone_fn = git_hash_sha1_clone_unsafe,
|
||||
.update_fn = git_hash_sha1_update_unsafe,
|
||||
.final_fn = git_hash_sha1_final_unsafe,
|
||||
.final_oid_fn = git_hash_sha1_final_oid_unsafe,
|
||||
.empty_tree = &empty_tree_oid,
|
||||
.empty_blob = &empty_blob_oid,
|
||||
.null_oid = &null_oid_sha1,
|
||||
};
|
||||
|
||||
const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
|
||||
{
|
||||
.name = NULL,
|
||||
@@ -214,11 +230,6 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
|
||||
.update_fn = git_hash_unknown_update,
|
||||
.final_fn = git_hash_unknown_final,
|
||||
.final_oid_fn = git_hash_unknown_final_oid,
|
||||
.unsafe_init_fn = git_hash_unknown_init,
|
||||
.unsafe_clone_fn = git_hash_unknown_clone,
|
||||
.unsafe_update_fn = git_hash_unknown_update,
|
||||
.unsafe_final_fn = git_hash_unknown_final,
|
||||
.unsafe_final_oid_fn = git_hash_unknown_final_oid,
|
||||
.empty_tree = NULL,
|
||||
.empty_blob = NULL,
|
||||
.null_oid = NULL,
|
||||
@@ -234,11 +245,7 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
|
||||
.update_fn = git_hash_sha1_update,
|
||||
.final_fn = git_hash_sha1_final,
|
||||
.final_oid_fn = git_hash_sha1_final_oid,
|
||||
.unsafe_init_fn = git_hash_sha1_init_unsafe,
|
||||
.unsafe_clone_fn = git_hash_sha1_clone_unsafe,
|
||||
.unsafe_update_fn = git_hash_sha1_update_unsafe,
|
||||
.unsafe_final_fn = git_hash_sha1_final_unsafe,
|
||||
.unsafe_final_oid_fn = git_hash_sha1_final_oid_unsafe,
|
||||
.unsafe = &sha1_unsafe_algo,
|
||||
.empty_tree = &empty_tree_oid,
|
||||
.empty_blob = &empty_blob_oid,
|
||||
.null_oid = &null_oid_sha1,
|
||||
@@ -254,11 +261,6 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
|
||||
.update_fn = git_hash_sha256_update,
|
||||
.final_fn = git_hash_sha256_final,
|
||||
.final_oid_fn = git_hash_sha256_final_oid,
|
||||
.unsafe_init_fn = git_hash_sha256_init,
|
||||
.unsafe_clone_fn = git_hash_sha256_clone,
|
||||
.unsafe_update_fn = git_hash_sha256_update,
|
||||
.unsafe_final_fn = git_hash_sha256_final,
|
||||
.unsafe_final_oid_fn = git_hash_sha256_final_oid,
|
||||
.empty_tree = &empty_tree_oid_sha256,
|
||||
.empty_blob = &empty_blob_oid_sha256,
|
||||
.null_oid = &null_oid_sha256,
|
||||
@@ -305,6 +307,15 @@ int hash_algo_by_length(int len)
|
||||
return GIT_HASH_UNKNOWN;
|
||||
}
|
||||
|
||||
const struct git_hash_algo *unsafe_hash_algo(const struct git_hash_algo *algop)
|
||||
{
|
||||
/* If we have a faster "unsafe" implementation, use that. */
|
||||
if (algop->unsafe)
|
||||
return algop->unsafe;
|
||||
/* Otherwise use the default one. */
|
||||
return algop;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is meant to hold a *small* number of objects that you would
|
||||
* want repo_read_object_file() to be able to return, but yet you do not want
|
||||
|
||||
Reference in New Issue
Block a user