Merge branch 'ps/hash-cleanup'
Further code clean-up on the use of hash functions. Now the context object knows what hash function it is working with. * ps/hash-cleanup: global: adapt callers to use generic hash context helpers hash: provide generic wrappers to update hash contexts hash: stop typedeffing the hash context hash: convert hashing context to a structure
This commit is contained in:
@ -3,16 +3,16 @@
|
||||
|
||||
#define NUM_SECONDS 3
|
||||
|
||||
static inline void compute_hash(const struct git_hash_algo *algo, git_hash_ctx *ctx, uint8_t *final, const void *p, size_t len)
|
||||
static inline void compute_hash(const struct git_hash_algo *algo, struct git_hash_ctx *ctx, uint8_t *final, const void *p, size_t len)
|
||||
{
|
||||
algo->init_fn(ctx);
|
||||
algo->update_fn(ctx, p, len);
|
||||
algo->final_fn(final, ctx);
|
||||
git_hash_update(ctx, p, len);
|
||||
git_hash_final(final, ctx);
|
||||
}
|
||||
|
||||
int cmd__hash_speed(int ac, const char **av)
|
||||
{
|
||||
git_hash_ctx ctx;
|
||||
struct git_hash_ctx ctx;
|
||||
unsigned char hash[GIT_MAX_RAWSZ];
|
||||
clock_t initial, start, end;
|
||||
unsigned bufsizes[] = { 64, 256, 1024, 8192, 16384 };
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
int cmd_hash_impl(int ac, const char **av, int algo, int unsafe)
|
||||
{
|
||||
git_hash_ctx ctx;
|
||||
struct git_hash_ctx ctx;
|
||||
unsigned char hash[GIT_MAX_HEXSZ];
|
||||
unsigned bufsz = 8192;
|
||||
int binary = 0;
|
||||
@ -48,9 +48,9 @@ int cmd_hash_impl(int ac, const char **av, int algo, int unsafe)
|
||||
}
|
||||
if (this_sz == 0)
|
||||
break;
|
||||
algop->update_fn(&ctx, buffer, this_sz);
|
||||
git_hash_update(&ctx, buffer, this_sz);
|
||||
}
|
||||
algop->final_fn(hash, &ctx);
|
||||
git_hash_final(hash, &ctx);
|
||||
|
||||
if (binary)
|
||||
fwrite(hash, 1, algop->rawsz, stdout);
|
||||
|
@ -8,13 +8,13 @@ static void check_hash_data(const void *data, size_t data_length,
|
||||
cl_assert(data != NULL);
|
||||
|
||||
for (size_t i = 1; i < ARRAY_SIZE(hash_algos); i++) {
|
||||
git_hash_ctx ctx;
|
||||
struct git_hash_ctx ctx;
|
||||
unsigned char hash[GIT_MAX_HEXSZ];
|
||||
const struct git_hash_algo *algop = &hash_algos[i];
|
||||
|
||||
algop->init_fn(&ctx);
|
||||
algop->update_fn(&ctx, data, data_length);
|
||||
algop->final_fn(hash, &ctx);
|
||||
git_hash_update(&ctx, data, data_length);
|
||||
git_hash_final(hash, &ctx);
|
||||
|
||||
cl_assert_equal_s(hash_to_hex_algop(hash,algop), expected_hashes[i - 1]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user