Merge branch 'jk/git-hash-cleanups' into next
The 'git_hash_*()' wrappers have been updated to be used consistently across the codebase instead of direct calls to members of 'struct git_hash_algo', and 'git_hash_discard()' has been made idempotent to simplify cleanups. * jk/git-hash-cleanups: hash: check ctx->active flag in all wrapper functions http: use idempotent git_hash_discard() csum-file: use idempotent git_hash_discard() hash: make git_hash_discard() idempotent hash: document function pointers and wrappers hash: convert remaining direct function calls hash: use git_hash_init() consistentlynext
commit
12a4856545
|
|
@ -969,7 +969,7 @@ static int store_object(
|
|||
|
||||
hdrlen = format_object_header((char *)hdr, sizeof(hdr), type,
|
||||
dat->len);
|
||||
the_hash_algo->init_fn(&c);
|
||||
git_hash_init(&c, the_hash_algo);
|
||||
git_hash_update(&c, hdr, hdrlen);
|
||||
git_hash_update(&c, dat->buf, dat->len);
|
||||
git_hash_final_oid(&oid, &c);
|
||||
|
|
@ -1131,7 +1131,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
|
|||
|
||||
hdrlen = format_object_header((char *)out_buf, out_sz, OBJ_BLOB, len);
|
||||
|
||||
the_hash_algo->init_fn(&c);
|
||||
git_hash_init(&c, the_hash_algo);
|
||||
git_hash_update(&c, out_buf, hdrlen);
|
||||
|
||||
crc32_begin(pack_file);
|
||||
|
|
|
|||
|
|
@ -374,7 +374,7 @@ static const char *open_pack_file(const char *pack_name)
|
|||
output_fd = -1;
|
||||
nothread_data.pack_fd = input_fd;
|
||||
}
|
||||
the_hash_algo->init_fn(&input_ctx);
|
||||
git_hash_init(&input_ctx, the_hash_algo);
|
||||
return pack_name;
|
||||
}
|
||||
|
||||
|
|
@ -481,7 +481,7 @@ static void *unpack_entry_data(off_t offset, size_t size,
|
|||
|
||||
if (!is_delta_type(type)) {
|
||||
hdrlen = format_object_header(hdr, sizeof(hdr), type, size);
|
||||
the_hash_algo->init_fn(&c);
|
||||
git_hash_init(&c, the_hash_algo);
|
||||
git_hash_update(&c, hdr, hdrlen);
|
||||
} else
|
||||
oid = NULL;
|
||||
|
|
@ -1291,7 +1291,7 @@ static void parse_pack_objects(unsigned char *hash)
|
|||
|
||||
/* Check pack integrity */
|
||||
flush();
|
||||
the_hash_algo->init_fn(&tmp_ctx);
|
||||
git_hash_init(&tmp_ctx, the_hash_algo);
|
||||
git_hash_clone(&tmp_ctx, &input_ctx);
|
||||
git_hash_final(hash, &tmp_ctx);
|
||||
if (!hasheq(fill(the_hash_algo->rawsz), hash, the_repository->hash_algo))
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ static size_t get_one_patchid(struct object_id *next_oid, struct object_id *resu
|
|||
char pre_oid_str[GIT_MAX_HEXSZ + 1], post_oid_str[GIT_MAX_HEXSZ + 1];
|
||||
struct git_hash_ctx ctx;
|
||||
|
||||
the_hash_algo->init_fn(&ctx);
|
||||
git_hash_init(&ctx, the_hash_algo);
|
||||
oidclr(result, the_repository->hash_algo);
|
||||
|
||||
while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
|
||||
|
|
|
|||
|
|
@ -615,7 +615,7 @@ static void hmac_hash(unsigned char *out,
|
|||
/* RFC 2104 2. (1) */
|
||||
memset(key, '\0', GIT_MAX_BLKSZ);
|
||||
if (the_hash_algo->blksz < key_len) {
|
||||
the_hash_algo->init_fn(&ctx);
|
||||
git_hash_init(&ctx, the_hash_algo);
|
||||
git_hash_update(&ctx, key_in, key_len);
|
||||
git_hash_final(key, &ctx);
|
||||
} else {
|
||||
|
|
@ -629,13 +629,13 @@ static void hmac_hash(unsigned char *out,
|
|||
}
|
||||
|
||||
/* RFC 2104 2. (3) & (4) */
|
||||
the_hash_algo->init_fn(&ctx);
|
||||
git_hash_init(&ctx, the_hash_algo);
|
||||
git_hash_update(&ctx, k_ipad, sizeof(k_ipad));
|
||||
git_hash_update(&ctx, text, text_len);
|
||||
git_hash_final(out, &ctx);
|
||||
|
||||
/* RFC 2104 2. (6) & (7) */
|
||||
the_hash_algo->init_fn(&ctx);
|
||||
git_hash_init(&ctx, the_hash_algo);
|
||||
git_hash_update(&ctx, k_opad, sizeof(k_opad));
|
||||
git_hash_update(&ctx, out, the_hash_algo->rawsz);
|
||||
git_hash_final(out, &ctx);
|
||||
|
|
|
|||
|
|
@ -550,11 +550,11 @@ static void create_default_gitdir_config(const char *submodule_name)
|
|||
|
||||
/* Case 2.4: If all the above failed, try a hash of the name as a last resort */
|
||||
header_len = snprintf(header, sizeof(header), "blob %zu", strlen(submodule_name));
|
||||
the_hash_algo->init_fn(&ctx);
|
||||
the_hash_algo->update_fn(&ctx, header, header_len);
|
||||
the_hash_algo->update_fn(&ctx, "\0", 1);
|
||||
the_hash_algo->update_fn(&ctx, submodule_name, strlen(submodule_name));
|
||||
the_hash_algo->final_fn(raw_name_hash, &ctx);
|
||||
git_hash_init(&ctx, the_hash_algo);
|
||||
git_hash_update(&ctx, header, header_len);
|
||||
git_hash_update(&ctx, "\0", 1);
|
||||
git_hash_update(&ctx, submodule_name, strlen(submodule_name));
|
||||
git_hash_final(raw_name_hash, &ctx);
|
||||
hash_to_hex_algop_r(hex_name_hash, raw_name_hash, the_hash_algo);
|
||||
strbuf_reset(&gitdir_path);
|
||||
repo_git_path_append(the_repository, &gitdir_path, "modules/%s", hex_name_hash);
|
||||
|
|
|
|||
|
|
@ -670,10 +670,10 @@ int cmd_unpack_objects(int argc,
|
|||
/* We don't take any non-flag arguments now.. Maybe some day */
|
||||
usage(unpack_usage);
|
||||
}
|
||||
the_hash_algo->init_fn(&ctx);
|
||||
git_hash_init(&ctx, the_hash_algo);
|
||||
unpack_all();
|
||||
git_hash_update(&ctx, buffer, offset);
|
||||
the_hash_algo->init_fn(&tmp_ctx);
|
||||
git_hash_init(&tmp_ctx, the_hash_algo);
|
||||
git_hash_clone(&tmp_ctx, &ctx);
|
||||
git_hash_final_oid(&oid, &tmp_ctx);
|
||||
if (strict) {
|
||||
|
|
|
|||
25
csum-file.c
25
csum-file.c
|
|
@ -55,17 +55,12 @@ void hashflush(struct hashfile *f)
|
|||
}
|
||||
}
|
||||
|
||||
static void free_hashfile_memory(struct hashfile *f)
|
||||
{
|
||||
free(f->buffer);
|
||||
free(f->check_buffer);
|
||||
free(f);
|
||||
}
|
||||
|
||||
void free_hashfile(struct hashfile *f)
|
||||
{
|
||||
git_hash_discard(&f->ctx);
|
||||
free_hashfile_memory(f);
|
||||
free(f->buffer);
|
||||
free(f->check_buffer);
|
||||
free(f);
|
||||
}
|
||||
|
||||
int finalize_hashfile(struct hashfile *f, unsigned char *result,
|
||||
|
|
@ -75,12 +70,10 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result,
|
|||
|
||||
hashflush(f);
|
||||
|
||||
if (f->skip_hash) {
|
||||
git_hash_discard(&f->ctx);
|
||||
if (f->skip_hash)
|
||||
hashclr(f->buffer, f->algop);
|
||||
} else {
|
||||
else
|
||||
git_hash_final(f->buffer, &f->ctx);
|
||||
}
|
||||
|
||||
if (result)
|
||||
hashcpy(result, f->buffer, f->algop);
|
||||
|
|
@ -105,7 +98,7 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result,
|
|||
if (close(f->check_fd))
|
||||
die_errno("%s: sha1 file error on close", f->name);
|
||||
}
|
||||
free_hashfile_memory(f);
|
||||
free_hashfile(f);
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
|
@ -175,7 +168,7 @@ struct hashfile *hashfd_ext(const struct git_hash_algo *algop,
|
|||
f->skip_hash = 0;
|
||||
|
||||
f->algop = unsafe_hash_algo(algop);
|
||||
f->algop->init_fn(&f->ctx);
|
||||
git_hash_init(&f->ctx, f->algop);
|
||||
|
||||
f->buffer_len = opts->buffer_len ? opts->buffer_len : DEFAULT_IO_BUFFER_SIZE;
|
||||
f->buffer = xmalloc(f->buffer_len);
|
||||
|
|
@ -200,7 +193,7 @@ void hashfile_checkpoint_init(struct hashfile *f,
|
|||
struct hashfile_checkpoint *checkpoint)
|
||||
{
|
||||
memset(checkpoint, 0, sizeof(*checkpoint));
|
||||
f->algop->init_fn(&checkpoint->ctx);
|
||||
git_hash_init(&checkpoint->ctx, f->algop);
|
||||
}
|
||||
|
||||
void hashfile_checkpoint(struct hashfile *f, struct hashfile_checkpoint *checkpoint)
|
||||
|
|
@ -252,7 +245,7 @@ int hashfile_checksum_valid(const struct git_hash_algo *algop,
|
|||
if (total_len < algop->rawsz)
|
||||
return 0; /* say "too short"? */
|
||||
|
||||
algop->init_fn(&ctx);
|
||||
git_hash_init(&ctx, algop);
|
||||
git_hash_update(&ctx, data, data_len);
|
||||
git_hash_final(got, &ctx);
|
||||
|
||||
|
|
|
|||
4
diff.c
4
diff.c
|
|
@ -6855,7 +6855,7 @@ void flush_one_hunk(struct object_id *result, struct git_hash_ctx *ctx)
|
|||
int i;
|
||||
|
||||
git_hash_final(hash, ctx);
|
||||
the_hash_algo->init_fn(ctx);
|
||||
git_hash_init(ctx, the_hash_algo);
|
||||
/* 20-byte sum, with carry */
|
||||
for (i = 0; i < the_hash_algo->rawsz; ++i) {
|
||||
carry += result->hash[i] + hash[i];
|
||||
|
|
@ -6899,7 +6899,7 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
|
|||
struct git_hash_ctx ctx;
|
||||
struct patch_id_t data;
|
||||
|
||||
the_hash_algo->init_fn(&ctx);
|
||||
git_hash_init(&ctx, the_hash_algo);
|
||||
memset(&data, 0, sizeof(struct patch_id_t));
|
||||
data.ctx = &ctx;
|
||||
oidclr(oid, the_repository->hash_algo);
|
||||
|
|
|
|||
16
hash.c
16
hash.c
|
|
@ -285,31 +285,47 @@ void git_hash_free(struct git_hash_ctx *ctx)
|
|||
void git_hash_init(struct git_hash_ctx *ctx, const struct git_hash_algo *algop)
|
||||
{
|
||||
algop->init_fn(ctx);
|
||||
ctx->active = true;
|
||||
}
|
||||
|
||||
void git_hash_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src)
|
||||
{
|
||||
if (!src->active)
|
||||
BUG("attempt to copy from an inactive hash context");
|
||||
if (!dst->active)
|
||||
BUG("attempt to copy to an inactive hash context");
|
||||
src->algop->clone_fn(dst, src);
|
||||
}
|
||||
|
||||
void git_hash_update(struct git_hash_ctx *ctx, const void *in, size_t len)
|
||||
{
|
||||
if (!ctx->active)
|
||||
BUG("attempt to update an inactive hash context");
|
||||
ctx->algop->update_fn(ctx, in, len);
|
||||
}
|
||||
|
||||
void git_hash_final(unsigned char *hash, struct git_hash_ctx *ctx)
|
||||
{
|
||||
if (!ctx->active)
|
||||
BUG("attempt to finalize an inactive hash context");
|
||||
ctx->algop->final_fn(hash, ctx);
|
||||
ctx->active = false;
|
||||
}
|
||||
|
||||
void git_hash_final_oid(struct object_id *oid, struct git_hash_ctx *ctx)
|
||||
{
|
||||
if (!ctx->active)
|
||||
BUG("attempt to finalize an inactive hash context");
|
||||
ctx->algop->final_oid_fn(oid, ctx);
|
||||
ctx->active = false;
|
||||
}
|
||||
|
||||
void git_hash_discard(struct git_hash_ctx *ctx)
|
||||
{
|
||||
if (!ctx->active)
|
||||
return;
|
||||
ctx->algop->discard_fn(ctx);
|
||||
ctx->active = false;
|
||||
}
|
||||
|
||||
uint32_t hash_algo_by_name(const char *name)
|
||||
|
|
|
|||
44
hash.h
44
hash.h
|
|
@ -281,6 +281,7 @@ struct git_hash_ctx {
|
|||
git_SHA_CTX_unsafe sha1_unsafe;
|
||||
git_SHA256_CTX sha256;
|
||||
} state;
|
||||
bool active;
|
||||
};
|
||||
|
||||
typedef void (*git_hash_init_fn)(struct git_hash_ctx *ctx);
|
||||
|
|
@ -309,22 +310,15 @@ struct git_hash_algo {
|
|||
/* The block size of the hash. */
|
||||
size_t blksz;
|
||||
|
||||
/* The hash initialization function. */
|
||||
/*
|
||||
* Low-level implementation hooks. Callers should use the git_hash_*
|
||||
* wrappers below rather than invoking these directly.
|
||||
*/
|
||||
git_hash_init_fn init_fn;
|
||||
|
||||
/* The hash context cloning function. */
|
||||
git_hash_clone_fn clone_fn;
|
||||
|
||||
/* The hash update function. */
|
||||
git_hash_update_fn update_fn;
|
||||
|
||||
/* The hash finalization function. */
|
||||
git_hash_final_fn final_fn;
|
||||
|
||||
/* The hash finalization function for object IDs. */
|
||||
git_hash_final_oid_fn final_oid_fn;
|
||||
|
||||
/* Discard an initialized hash without finalizing. */
|
||||
git_hash_discard_fn discard_fn;
|
||||
|
||||
/* The OID of the empty tree. */
|
||||
|
|
@ -341,12 +335,40 @@ struct git_hash_algo {
|
|||
};
|
||||
extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS];
|
||||
|
||||
/*
|
||||
* Prepare an uninitialized hash context for use. You must eventually release
|
||||
* the context with git_hash_final() (or final_oid()) or by calling
|
||||
* git_hash_discard().
|
||||
*/
|
||||
void git_hash_init(struct git_hash_ctx *ctx, const struct git_hash_algo *algop);
|
||||
|
||||
/*
|
||||
* Clone the state of a hash. Both src and dst must have been initialized with
|
||||
* git_hash_init().
|
||||
*/
|
||||
void git_hash_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src);
|
||||
|
||||
/*
|
||||
* Add more data to an initialized hash context.
|
||||
*/
|
||||
void git_hash_update(struct git_hash_ctx *ctx, const void *in, size_t len);
|
||||
|
||||
/*
|
||||
* Retrieve the final hash value from a context, releasing any resources.
|
||||
*/
|
||||
void git_hash_final(unsigned char *hash, struct git_hash_ctx *ctx);
|
||||
|
||||
/*
|
||||
* Like git_hash_final(), but write the result into an object_id.
|
||||
*/
|
||||
void git_hash_final_oid(struct object_id *oid, struct git_hash_ctx *ctx);
|
||||
|
||||
/*
|
||||
* Discard a hash context without computing the final value, but still
|
||||
* releasing any resources.
|
||||
*/
|
||||
void git_hash_discard(struct git_hash_ctx *ctx);
|
||||
|
||||
const struct git_hash_algo *hash_algo_ptr_by_number(uint32_t algo);
|
||||
struct git_hash_ctx *git_hash_alloc(void);
|
||||
void git_hash_free(struct git_hash_ctx *ctx);
|
||||
|
|
|
|||
|
|
@ -776,7 +776,7 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
|
|||
} else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) {
|
||||
lock->token = xstrdup(ctx->cdata);
|
||||
|
||||
the_hash_algo->init_fn(&hash_ctx);
|
||||
git_hash_init(&hash_ctx, the_hash_algo);
|
||||
git_hash_update(&hash_ctx, lock->token, strlen(lock->token));
|
||||
git_hash_final(lock_token_hash, &hash_ctx);
|
||||
|
||||
|
|
|
|||
9
http.c
9
http.c
|
|
@ -2879,8 +2879,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
|
|||
|
||||
git_inflate_init(&freq->stream);
|
||||
|
||||
the_hash_algo->init_fn(&freq->c);
|
||||
freq->hash_ctx_valid = 1;
|
||||
git_hash_init(&freq->c, the_hash_algo);
|
||||
|
||||
freq->url = get_remote_object_url(base_url, hex, 0);
|
||||
|
||||
|
|
@ -2916,7 +2915,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
|
|||
git_inflate_end(&freq->stream);
|
||||
memset(&freq->stream, 0, sizeof(freq->stream));
|
||||
git_inflate_init(&freq->stream);
|
||||
the_hash_algo->init_fn(&freq->c);
|
||||
git_hash_init(&freq->c, the_hash_algo);
|
||||
if (prev_posn>0) {
|
||||
prev_posn = 0;
|
||||
lseek(freq->localfile, 0, SEEK_SET);
|
||||
|
|
@ -2989,7 +2988,6 @@ int finish_http_object_request(struct http_object_request *freq)
|
|||
}
|
||||
|
||||
git_hash_final_oid(&freq->real_oid, &freq->c);
|
||||
freq->hash_ctx_valid = 0;
|
||||
if (freq->zret != Z_STREAM_END) {
|
||||
unlink_or_warn(freq->tmpfile.buf);
|
||||
return -1;
|
||||
|
|
@ -3030,8 +3028,7 @@ void release_http_object_request(struct http_object_request **freq_p)
|
|||
curl_slist_free_all(freq->headers);
|
||||
strbuf_release(&freq->tmpfile);
|
||||
git_inflate_end(&freq->stream);
|
||||
if (freq->hash_ctx_valid)
|
||||
git_hash_discard(&freq->c);
|
||||
git_hash_discard(&freq->c);
|
||||
|
||||
free(freq);
|
||||
*freq_p = NULL;
|
||||
|
|
|
|||
1
http.h
1
http.h
|
|
@ -255,7 +255,6 @@ struct http_object_request {
|
|||
struct object_id oid;
|
||||
struct object_id real_oid;
|
||||
struct git_hash_ctx c;
|
||||
int hash_ctx_valid;
|
||||
git_zstream stream;
|
||||
int zret;
|
||||
int rename;
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ int stream_object_signature(struct repository *r,
|
|||
hdrlen = format_object_header(hdr, sizeof(hdr), st->type, st->size);
|
||||
|
||||
/* Sha1.. */
|
||||
r->hash_algo->init_fn(&c);
|
||||
git_hash_init(&c, r->hash_algo);
|
||||
git_hash_update(&c, hdr, hdrlen);
|
||||
for (;;) {
|
||||
char buf[1024 * 16];
|
||||
|
|
@ -320,7 +320,7 @@ static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_c
|
|||
struct object_id *oid,
|
||||
char *hdr, size_t *hdrlen)
|
||||
{
|
||||
algo->init_fn(c);
|
||||
git_hash_init(c, algo);
|
||||
git_hash_update(c, hdr, *hdrlen);
|
||||
git_hash_update(c, buf, len);
|
||||
git_hash_final_oid(oid, c);
|
||||
|
|
@ -681,9 +681,9 @@ static int start_loose_object_common(struct odb_source_loose *loose,
|
|||
git_deflate_init(stream, cfg->zlib_compression_level);
|
||||
stream->next_out = buf;
|
||||
stream->avail_out = buflen;
|
||||
algo->init_fn(c);
|
||||
git_hash_init(c, algo);
|
||||
if (compat && compat_c)
|
||||
compat->init_fn(compat_c);
|
||||
git_hash_init(compat_c, compat);
|
||||
|
||||
/* Start to feed header to zlib stream */
|
||||
stream->next_in = (unsigned char *)hdr;
|
||||
|
|
@ -1141,7 +1141,7 @@ static int hash_blob_stream(struct odb_write_stream *stream,
|
|||
|
||||
header_len = format_object_header((char *)buf, sizeof(buf),
|
||||
OBJ_BLOB, size);
|
||||
hash_algo->init_fn(&ctx);
|
||||
git_hash_init(&ctx, hash_algo);
|
||||
git_hash_update(&ctx, buf, header_len);
|
||||
|
||||
while (!stream->is_finished) {
|
||||
|
|
@ -1313,7 +1313,7 @@ static int odb_transaction_files_write_object_stream(struct odb_transaction *bas
|
|||
|
||||
header_len = format_object_header((char *)obuf, sizeof(obuf),
|
||||
OBJ_BLOB, size);
|
||||
transaction->base.source->odb->repo->hash_algo->init_fn(&ctx);
|
||||
git_hash_init(&ctx, transaction->base.source->odb->repo->hash_algo);
|
||||
git_hash_update(&ctx, obuf, header_len);
|
||||
|
||||
/*
|
||||
|
|
@ -1560,7 +1560,7 @@ static int check_stream_oid(git_zstream *stream,
|
|||
unsigned long total_read;
|
||||
int status = Z_OK;
|
||||
|
||||
algop->init_fn(&c);
|
||||
git_hash_init(&c, algop);
|
||||
git_hash_update(&c, hdr, stream->total_out);
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ static int verify_packfile(struct repository *r,
|
|||
if (!is_pack_valid(p))
|
||||
return error("packfile %s cannot be accessed", p->pack_name);
|
||||
|
||||
r->hash_algo->init_fn(&ctx);
|
||||
git_hash_init(&ctx, r->hash_algo);
|
||||
do {
|
||||
unsigned long remaining;
|
||||
unsigned char *in = use_pack(p, w_curs, offset, &remaining);
|
||||
|
|
|
|||
|
|
@ -402,8 +402,8 @@ void fixup_pack_header_footer(const struct git_hash_algo *hash_algo,
|
|||
char *buf;
|
||||
ssize_t read_result;
|
||||
|
||||
hash_algo->init_fn(&old_hash_ctx);
|
||||
hash_algo->init_fn(&new_hash_ctx);
|
||||
git_hash_init(&old_hash_ctx, hash_algo);
|
||||
git_hash_init(&new_hash_ctx, hash_algo);
|
||||
|
||||
if (lseek(pack_fd, 0, SEEK_SET) != 0)
|
||||
die_errno("Failed seeking to start of '%s'", pack_name);
|
||||
|
|
@ -455,7 +455,7 @@ void fixup_pack_header_footer(const struct git_hash_algo *hash_algo,
|
|||
* pack, which also means making partial_pack_offset
|
||||
* big enough not to matter anymore.
|
||||
*/
|
||||
hash_algo->init_fn(&old_hash_ctx);
|
||||
git_hash_init(&old_hash_ctx, hash_algo);
|
||||
partial_pack_offset = ~partial_pack_offset;
|
||||
partial_pack_offset -= MSB(partial_pack_offset, 1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1722,7 +1722,7 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size)
|
|||
if (oideq(&oid, null_oid(the_hash_algo)))
|
||||
return 0;
|
||||
|
||||
the_hash_algo->init_fn(&c);
|
||||
git_hash_init(&c, the_hash_algo);
|
||||
git_hash_update(&c, hdr, size - the_hash_algo->rawsz);
|
||||
git_hash_final(hash, &c);
|
||||
if (!hasheq(hash, start, the_repository->hash_algo))
|
||||
|
|
@ -2957,7 +2957,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
|
|||
*/
|
||||
if (offset && record_eoie()) {
|
||||
CALLOC_ARRAY(eoie_c, 1);
|
||||
the_hash_algo->init_fn(eoie_c);
|
||||
git_hash_init(eoie_c, the_hash_algo);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -3600,7 +3600,7 @@ static size_t read_eoie_extension(const char *mmap, size_t mmap_size)
|
|||
* "REUC" + <binary representation of M>)
|
||||
*/
|
||||
src_offset = offset;
|
||||
the_hash_algo->init_fn(&c);
|
||||
git_hash_init(&c, the_hash_algo);
|
||||
while (src_offset < mmap_size - the_hash_algo->rawsz - EOIE_SIZE_WITH_HEADER) {
|
||||
/* After an array of active_nr index entries,
|
||||
* there can be arbitrary number of extended
|
||||
|
|
|
|||
2
rerere.c
2
rerere.c
|
|
@ -439,7 +439,7 @@ static int handle_path(unsigned char *hash, struct rerere_io *io, int marker_siz
|
|||
struct strbuf buf = STRBUF_INIT, out = STRBUF_INIT;
|
||||
int has_conflicts = 0;
|
||||
if (hash)
|
||||
the_hash_algo->init_fn(&ctx);
|
||||
git_hash_init(&ctx, the_hash_algo);
|
||||
|
||||
while (!io->getline(&buf, io)) {
|
||||
if (is_cmarker(buf.buf, '<', marker_size)) {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
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);
|
||||
git_hash_init(ctx, algo);
|
||||
git_hash_update(ctx, p, len);
|
||||
git_hash_final(final, ctx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ int cmd_hash_impl(int ac, const char **av, int algo, int unsafe)
|
|||
die("OOPS");
|
||||
}
|
||||
|
||||
algop->init_fn(&ctx);
|
||||
git_hash_init(&ctx, algop);
|
||||
|
||||
while (1) {
|
||||
ssize_t sz, this_sz;
|
||||
|
|
|
|||
|
|
@ -25,8 +25,7 @@ static const unsigned char zeros[BLOCK_SIZE];
|
|||
* Updates the pack checksum context.
|
||||
*/
|
||||
static void write_uncompressed_zlib(FILE *f, struct git_hash_ctx *pack_ctx,
|
||||
const void *data, size_t len,
|
||||
const struct git_hash_algo *algo)
|
||||
const void *data, size_t len)
|
||||
{
|
||||
unsigned char zlib_header[2] = { 0x78, 0x01 }; /* CMF, FLG */
|
||||
unsigned char block_header[5];
|
||||
|
|
@ -37,7 +36,7 @@ static void write_uncompressed_zlib(FILE *f, struct git_hash_ctx *pack_ctx,
|
|||
|
||||
/* Write zlib header */
|
||||
fwrite_or_die(f, zlib_header, sizeof(zlib_header));
|
||||
algo->update_fn(pack_ctx, zlib_header, 2);
|
||||
git_hash_update(pack_ctx, zlib_header, 2);
|
||||
|
||||
/* Write uncompressed blocks (max 64KB each) */
|
||||
do {
|
||||
|
|
@ -52,11 +51,11 @@ static void write_uncompressed_zlib(FILE *f, struct git_hash_ctx *pack_ctx,
|
|||
block_header[4] = block_header[2] ^ 0xff;
|
||||
|
||||
fwrite_or_die(f, block_header, sizeof(block_header));
|
||||
algo->update_fn(pack_ctx, block_header, 5);
|
||||
git_hash_update(pack_ctx, block_header, 5);
|
||||
|
||||
if (block_len) {
|
||||
fwrite_or_die(f, block_data, block_len);
|
||||
algo->update_fn(pack_ctx, block_data, block_len);
|
||||
git_hash_update(pack_ctx, block_data, block_len);
|
||||
adler = adler32(adler, block_data, block_len);
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +67,7 @@ static void write_uncompressed_zlib(FILE *f, struct git_hash_ctx *pack_ctx,
|
|||
/* Write adler32 checksum */
|
||||
put_be32(adler_buf, adler);
|
||||
fwrite_or_die(f, adler_buf, sizeof(adler_buf));
|
||||
algo->update_fn(pack_ctx, adler_buf, 4);
|
||||
git_hash_update(pack_ctx, adler_buf, 4);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -92,24 +91,24 @@ static void write_pack_object(FILE *f, struct git_hash_ctx *pack_ctx,
|
|||
sizeof(pack_header),
|
||||
type, len);
|
||||
fwrite_or_die(f, pack_header, pack_header_len);
|
||||
algo->update_fn(pack_ctx, pack_header, pack_header_len);
|
||||
git_hash_update(pack_ctx, pack_header, pack_header_len);
|
||||
|
||||
/* Write the data as uncompressed zlib */
|
||||
write_uncompressed_zlib(f, pack_ctx, data, len, algo);
|
||||
write_uncompressed_zlib(f, pack_ctx, data, len);
|
||||
|
||||
algo->init_fn(&ctx);
|
||||
git_hash_init(&ctx, algo);
|
||||
object_header_len = format_object_header(object_header,
|
||||
sizeof(object_header),
|
||||
type, len);
|
||||
algo->update_fn(&ctx, object_header, object_header_len);
|
||||
git_hash_update(&ctx, object_header, object_header_len);
|
||||
if (data)
|
||||
algo->update_fn(&ctx, data, len);
|
||||
git_hash_update(&ctx, data, len);
|
||||
else {
|
||||
for (size_t i = len / BLOCK_SIZE; i; i--)
|
||||
algo->update_fn(&ctx, zeros, BLOCK_SIZE);
|
||||
algo->update_fn(&ctx, zeros, len % BLOCK_SIZE);
|
||||
git_hash_update(&ctx, zeros, BLOCK_SIZE);
|
||||
git_hash_update(&ctx, zeros, len % BLOCK_SIZE);
|
||||
}
|
||||
algo->final_oid_fn(oid, &ctx);
|
||||
git_hash_final_oid(oid, &ctx);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -430,11 +429,11 @@ static int generate_pack_with_large_object(const char *path, size_t blob_size,
|
|||
|
||||
f = xfopen(path, "wb");
|
||||
|
||||
algo->init_fn(&pack_ctx);
|
||||
git_hash_init(&pack_ctx, algo);
|
||||
|
||||
/* Write pack header */
|
||||
fwrite_or_die(f, &pack_header, sizeof(pack_header));
|
||||
algo->update_fn(&pack_ctx, &pack_header, sizeof(pack_header));
|
||||
git_hash_update(&pack_ctx, &pack_header, sizeof(pack_header));
|
||||
|
||||
/* 1. Write the large blob */
|
||||
write_pack_object(f, &pack_ctx, OBJ_BLOB, NULL, blob_size, &blob_oid, algo);
|
||||
|
|
@ -472,7 +471,7 @@ static int generate_pack_with_large_object(const char *path, size_t blob_size,
|
|||
write_pack_object(f, &pack_ctx, OBJ_COMMIT, buf.buf, buf.len, &final_commit_oid, algo);
|
||||
|
||||
/* Write pack trailer (checksum) */
|
||||
algo->final_fn(pack_hash, &pack_ctx);
|
||||
git_hash_final(pack_hash, &pack_ctx);
|
||||
fwrite_or_die(f, pack_hash, algo->rawsz);
|
||||
if (fclose(f))
|
||||
die_errno(_("could not close '%s'"), path);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ static void check_hash_data(const void *data, size_t data_length,
|
|||
unsigned char hash[GIT_MAX_HEXSZ];
|
||||
const struct git_hash_algo *algop = &hash_algos[i];
|
||||
|
||||
algop->init_fn(&ctx);
|
||||
git_hash_init(&ctx, algop);
|
||||
git_hash_update(&ctx, data, data_length);
|
||||
git_hash_final(hash, &ctx);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
@@
|
||||
identifier f != git_hash_init;
|
||||
expression ALGO;
|
||||
struct git_hash_ctx *CTX;
|
||||
@@
|
||||
f(...) {<...
|
||||
- ALGO->init_fn(CTX);
|
||||
+ git_hash_init(CTX, ALGO);
|
||||
...>}
|
||||
|
||||
@@
|
||||
identifier f != git_hash_clone;
|
||||
expression ALGO;
|
||||
struct git_hash_ctx *SRC;
|
||||
struct git_hash_ctx *DST;
|
||||
@@
|
||||
f(...) {<...
|
||||
- ALGO->clone_fn(DST, SRC);
|
||||
+ git_hash_clone(DST, SRC);
|
||||
...>}
|
||||
|
||||
@@
|
||||
identifier f != git_hash_update;
|
||||
expression ALGO;
|
||||
struct git_hash_ctx *CTX;
|
||||
expression list ARGS;
|
||||
@@
|
||||
f(...) {<...
|
||||
- ALGO->update_fn(CTX, ARGS);
|
||||
+ git_hash_update(CTX, ARGS);
|
||||
...>}
|
||||
|
||||
@@
|
||||
identifier f != git_hash_final;
|
||||
expression ALGO;
|
||||
struct git_hash_ctx *CTX;
|
||||
expression list ARGS;
|
||||
@@
|
||||
f(...) {<...
|
||||
- ALGO->final_fn(ARGS, CTX);
|
||||
+ git_hash_final(ARGS, CTX);
|
||||
...>}
|
||||
|
||||
@@
|
||||
identifier f != git_hash_final_oid;
|
||||
expression ALGO;
|
||||
struct git_hash_ctx *CTX;
|
||||
expression list ARGS;
|
||||
@@
|
||||
f(...) {<...
|
||||
- ALGO->final_oid_fn(ARGS, CTX);
|
||||
+ git_hash_final_oid(ARGS, CTX);
|
||||
...>}
|
||||
|
||||
@@
|
||||
identifier f != git_hash_discard;
|
||||
expression ALGO;
|
||||
struct git_hash_ctx *CTX;
|
||||
@@
|
||||
f(...) {<...
|
||||
- ALGO->discard_fn(CTX);
|
||||
+ git_hash_discard(CTX);
|
||||
...>}
|
||||
|
|
@ -45,7 +45,7 @@ static void tr2_sid_append_my_sid_component(void)
|
|||
if (xgethostname(hostname, sizeof(hostname)))
|
||||
strbuf_add(&tr2sid_buf, "Localhost", 9);
|
||||
else {
|
||||
algo->init_fn(&ctx);
|
||||
git_hash_init(&ctx, algo);
|
||||
git_hash_update(&ctx, hostname, strlen(hostname));
|
||||
git_hash_final(hash, &ctx);
|
||||
hash_to_hex_algop_r(hex, hash, algo);
|
||||
|
|
|
|||
Loading…
Reference in New Issue