diff options
| -rw-r--r-- | builtin/fast-import.c | 16 | ||||
| -rw-r--r-- | builtin/index-pack.c | 19 | ||||
| -rw-r--r-- | builtin/patch-id.c | 14 | ||||
| -rw-r--r-- | builtin/receive-pack.c | 18 | ||||
| -rw-r--r-- | builtin/unpack-objects.c | 13 | ||||
| -rw-r--r-- | bulk-checkin.c | 10 | ||||
| -rw-r--r-- | csum-file.c | 16 | ||||
| -rw-r--r-- | csum-file.h | 4 | ||||
| -rw-r--r-- | diff.c | 34 | ||||
| -rw-r--r-- | diff.h | 2 | ||||
| -rw-r--r-- | hash.h | 43 | ||||
| -rw-r--r-- | http-push.c | 6 | ||||
| -rw-r--r-- | http.c | 6 | ||||
| -rw-r--r-- | http.h | 2 | ||||
| -rw-r--r-- | object-file.c | 130 | ||||
| -rw-r--r-- | pack-check.c | 6 | ||||
| -rw-r--r-- | pack-write.c | 19 | ||||
| -rw-r--r-- | read-cache.c | 26 | ||||
| -rw-r--r-- | rerere.c | 18 | ||||
| -rw-r--r-- | t/helper/test-hash-speed.c | 8 | ||||
| -rw-r--r-- | t/helper/test-hash.c | 6 | ||||
| -rw-r--r-- | t/unit-tests/u-hash.c | 6 | ||||
| -rw-r--r-- | trace2/tr2_sid.c | 6 |
23 files changed, 226 insertions, 202 deletions
diff --git a/builtin/fast-import.c b/builtin/fast-import.c index a6a84058cd..d6a368a566 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -954,15 +954,15 @@ static int store_object( unsigned char hdr[96]; struct object_id oid; unsigned long hdrlen, deltalen; - git_hash_ctx c; + struct git_hash_ctx c; git_zstream s; hdrlen = format_object_header((char *)hdr, sizeof(hdr), type, dat->len); the_hash_algo->init_fn(&c); - the_hash_algo->update_fn(&c, hdr, hdrlen); - the_hash_algo->update_fn(&c, dat->buf, dat->len); - the_hash_algo->final_oid_fn(&oid, &c); + git_hash_update(&c, hdr, hdrlen); + git_hash_update(&c, dat->buf, dat->len); + git_hash_final_oid(&oid, &c); if (oidout) oidcpy(oidout, &oid); @@ -1096,7 +1096,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark) struct object_id oid; unsigned long hdrlen; off_t offset; - git_hash_ctx c; + struct git_hash_ctx c; git_zstream s; struct hashfile_checkpoint checkpoint; int status = Z_OK; @@ -1114,7 +1114,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); - the_hash_algo->update_fn(&c, out_buf, hdrlen); + git_hash_update(&c, out_buf, hdrlen); crc32_begin(pack_file); @@ -1132,7 +1132,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark) if (!n && feof(stdin)) die("EOF in data (%" PRIuMAX " bytes remaining)", len); - the_hash_algo->update_fn(&c, in_buf, n); + git_hash_update(&c, in_buf, n); s.next_in = in_buf; s.avail_in = n; len -= n; @@ -1158,7 +1158,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark) } } git_deflate_end(&s); - the_hash_algo->final_oid_fn(&oid, &c); + git_hash_final_oid(&oid, &c); if (oidout) oidcpy(oidout, &oid); diff --git a/builtin/index-pack.c b/builtin/index-pack.c index c2a1750631..52cc97d52c 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -151,7 +151,7 @@ static unsigned int input_offset, input_len; static off_t consumed_bytes; static off_t max_input_size; static unsigned deepest_delta; -static git_hash_ctx input_ctx; +static struct git_hash_ctx input_ctx; static uint32_t input_crc32; static int input_fd, output_fd; static const char *curr_pack; @@ -301,7 +301,7 @@ static void flush(void) if (input_offset) { if (output_fd >= 0) write_or_die(output_fd, input_buffer, input_offset); - the_hash_algo->update_fn(&input_ctx, input_buffer, input_offset); + git_hash_update(&input_ctx, input_buffer, input_offset); memmove(input_buffer, input_buffer + input_offset, input_len); input_offset = 0; } @@ -475,14 +475,14 @@ static void *unpack_entry_data(off_t offset, unsigned long size, int status; git_zstream stream; void *buf; - git_hash_ctx c; + struct git_hash_ctx c; char hdr[32]; int hdrlen; if (!is_delta_type(type)) { hdrlen = format_object_header(hdr, sizeof(hdr), type, size); the_hash_algo->init_fn(&c); - the_hash_algo->update_fn(&c, hdr, hdrlen); + git_hash_update(&c, hdr, hdrlen); } else oid = NULL; if (type == OBJ_BLOB && size > big_file_threshold) @@ -502,7 +502,7 @@ static void *unpack_entry_data(off_t offset, unsigned long size, status = git_inflate(&stream, 0); use(input_len - stream.avail_in); if (oid) - the_hash_algo->update_fn(&c, last_out, stream.next_out - last_out); + git_hash_update(&c, last_out, stream.next_out - last_out); if (buf == fixed_buf) { stream.next_out = buf; stream.avail_out = sizeof(fixed_buf); @@ -512,7 +512,7 @@ static void *unpack_entry_data(off_t offset, unsigned long size, bad_object(offset, _("inflate returned %d"), status); git_inflate_end(&stream); if (oid) - the_hash_algo->final_oid_fn(oid, &c); + git_hash_final_oid(oid, &c); return buf == fixed_buf ? NULL : buf; } @@ -1248,7 +1248,7 @@ static void parse_pack_objects(unsigned char *hash) struct ofs_delta_entry *ofs_delta = ofs_deltas; struct object_id ref_delta_oid; struct stat st; - git_hash_ctx tmp_ctx; + struct git_hash_ctx tmp_ctx; if (verbose) progress = start_progress( @@ -1286,9 +1286,8 @@ static void parse_pack_objects(unsigned char *hash) /* Check pack integrity */ flush(); - the_hash_algo->init_fn(&tmp_ctx); - the_hash_algo->clone_fn(&tmp_ctx, &input_ctx); - the_hash_algo->final_fn(hash, &tmp_ctx); + 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)) die(_("pack is corrupted (SHA1 mismatch)")); use(the_hash_algo->rawsz); diff --git a/builtin/patch-id.c b/builtin/patch-id.c index f540d8daa7..cdef2ec10a 100644 --- a/builtin/patch-id.c +++ b/builtin/patch-id.c @@ -70,7 +70,7 @@ static size_t get_one_patchid(struct object_id *next_oid, struct object_id *resu int before = -1, after = -1; int diff_is_binary = 0; char pre_oid_str[GIT_MAX_HEXSZ + 1], post_oid_str[GIT_MAX_HEXSZ + 1]; - git_hash_ctx ctx; + struct git_hash_ctx ctx; the_hash_algo->init_fn(&ctx); oidclr(result, the_repository->hash_algo); @@ -85,7 +85,7 @@ static size_t get_one_patchid(struct object_id *next_oid, struct object_id *resu !skip_prefix(line, "From ", &p) && starts_with(line, "\\ ") && 12 < strlen(line)) { if (verbatim) - the_hash_algo->update_fn(&ctx, line, strlen(line)); + git_hash_update(&ctx, line, strlen(line)); continue; } @@ -104,10 +104,10 @@ static size_t get_one_patchid(struct object_id *next_oid, struct object_id *resu starts_with(line, "Binary files")) { diff_is_binary = 1; before = 0; - the_hash_algo->update_fn(&ctx, pre_oid_str, - strlen(pre_oid_str)); - the_hash_algo->update_fn(&ctx, post_oid_str, - strlen(post_oid_str)); + git_hash_update(&ctx, pre_oid_str, + strlen(pre_oid_str)); + git_hash_update(&ctx, post_oid_str, + strlen(post_oid_str)); if (stable) flush_one_hunk(result, &ctx); continue; @@ -165,7 +165,7 @@ static size_t get_one_patchid(struct object_id *next_oid, struct object_id *resu /* Add line to hash algo (possibly removing whitespace) */ len = verbatim ? strlen(line) : remove_space(line); patchlen += len; - the_hash_algo->update_fn(&ctx, line, len); + git_hash_update(&ctx, line, len); } if (!found_next) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index b7ea774609..129305700c 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -566,14 +566,14 @@ static void hmac_hash(unsigned char *out, unsigned char k_ipad[GIT_MAX_BLKSZ]; unsigned char k_opad[GIT_MAX_BLKSZ]; int i; - git_hash_ctx ctx; + struct git_hash_ctx ctx; /* RFC 2104 2. (1) */ memset(key, '\0', GIT_MAX_BLKSZ); if (the_hash_algo->blksz < key_len) { the_hash_algo->init_fn(&ctx); - the_hash_algo->update_fn(&ctx, key_in, key_len); - the_hash_algo->final_fn(key, &ctx); + git_hash_update(&ctx, key_in, key_len); + git_hash_final(key, &ctx); } else { memcpy(key, key_in, key_len); } @@ -586,15 +586,15 @@ static void hmac_hash(unsigned char *out, /* RFC 2104 2. (3) & (4) */ the_hash_algo->init_fn(&ctx); - the_hash_algo->update_fn(&ctx, k_ipad, sizeof(k_ipad)); - the_hash_algo->update_fn(&ctx, text, text_len); - the_hash_algo->final_fn(out, &ctx); + 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); - the_hash_algo->update_fn(&ctx, k_opad, sizeof(k_opad)); - the_hash_algo->update_fn(&ctx, out, the_hash_algo->rawsz); - the_hash_algo->final_fn(out, &ctx); + git_hash_update(&ctx, k_opad, sizeof(k_opad)); + git_hash_update(&ctx, out, the_hash_algo->rawsz); + git_hash_final(out, &ctx); } static char *prepare_push_cert_nonce(const char *path, timestamp_t stamp) diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index f6b9825fb0..8383bcf404 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -28,7 +28,7 @@ static unsigned char buffer[4096]; static unsigned int offset, len; static off_t consumed_bytes; static off_t max_input_size; -static git_hash_ctx ctx; +static struct git_hash_ctx ctx; static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT; static struct progress *progress; @@ -70,7 +70,7 @@ static void *fill(int min) if (min > sizeof(buffer)) die("cannot fill %d bytes", min); if (offset) { - the_hash_algo->update_fn(&ctx, buffer, offset); + git_hash_update(&ctx, buffer, offset); memmove(buffer, buffer + offset, len); offset = 0; } @@ -614,7 +614,7 @@ int cmd_unpack_objects(int argc, { int i; struct object_id oid; - git_hash_ctx tmp_ctx; + struct git_hash_ctx tmp_ctx; disable_replace_refs(); @@ -667,10 +667,9 @@ int cmd_unpack_objects(int argc, } the_hash_algo->init_fn(&ctx); unpack_all(); - the_hash_algo->update_fn(&ctx, buffer, offset); - the_hash_algo->init_fn(&tmp_ctx); - the_hash_algo->clone_fn(&tmp_ctx, &ctx); - the_hash_algo->final_oid_fn(&oid, &tmp_ctx); + git_hash_update(&ctx, buffer, offset); + git_hash_clone(&tmp_ctx, &ctx); + git_hash_final_oid(&oid, &tmp_ctx); if (strict) { write_rest(); if (fsck_finish(&fsck_options)) diff --git a/bulk-checkin.c b/bulk-checkin.c index c0ab31a961..20f2da67b9 100644 --- a/bulk-checkin.c +++ b/bulk-checkin.c @@ -162,7 +162,7 @@ static int already_written(struct bulk_checkin_packfile *state, struct object_id * with a new pack. */ static int stream_blob_to_pack(struct bulk_checkin_packfile *state, - git_hash_ctx *ctx, off_t *already_hashed_to, + struct git_hash_ctx *ctx, off_t *already_hashed_to, int fd, size_t size, const char *path, unsigned flags) { @@ -195,7 +195,7 @@ static int stream_blob_to_pack(struct bulk_checkin_packfile *state, if (rsize < hsize) hsize = rsize; if (hsize) - the_hash_algo->update_fn(ctx, ibuf, hsize); + git_hash_update(ctx, ibuf, hsize); *already_hashed_to = offset; } s.next_in = ibuf; @@ -259,7 +259,7 @@ static int deflate_blob_to_pack(struct bulk_checkin_packfile *state, const char *path, unsigned flags) { off_t seekback, already_hashed_to; - git_hash_ctx ctx; + struct git_hash_ctx ctx; unsigned char obuf[16384]; unsigned header_len; struct hashfile_checkpoint checkpoint; @@ -272,7 +272,7 @@ static int deflate_blob_to_pack(struct bulk_checkin_packfile *state, header_len = format_object_header((char *)obuf, sizeof(obuf), OBJ_BLOB, size); the_hash_algo->init_fn(&ctx); - the_hash_algo->update_fn(&ctx, obuf, header_len); + git_hash_update(&ctx, obuf, header_len); /* Note: idx is non-NULL when we are writing */ if ((flags & HASH_WRITE_OBJECT) != 0) { @@ -307,7 +307,7 @@ static int deflate_blob_to_pack(struct bulk_checkin_packfile *state, if (lseek(fd, seekback, SEEK_SET) == (off_t) -1) return error("cannot seek back"); } - the_hash_algo->final_oid_fn(result_oid, &ctx); + git_hash_final_oid(result_oid, &ctx); if (!idx) return 0; diff --git a/csum-file.c b/csum-file.c index c81645ba08..b58c183a4f 100644 --- a/csum-file.c +++ b/csum-file.c @@ -51,7 +51,7 @@ void hashflush(struct hashfile *f) if (offset) { if (!f->skip_hash) - f->algop->update_fn(&f->ctx, f->buffer, offset); + git_hash_update(&f->ctx, f->buffer, offset); flush(f, f->buffer, offset); f->offset = 0; } @@ -74,7 +74,7 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result, if (f->skip_hash) hashclr(f->buffer, f->algop); else - f->algop->final_fn(f->buffer, &f->ctx); + git_hash_final(f->buffer, &f->ctx); if (result) hashcpy(result, f->buffer, f->algop); @@ -129,7 +129,7 @@ void hashwrite(struct hashfile *f, const void *buf, unsigned int count) * f->offset is necessarily zero. */ if (!f->skip_hash) - f->algop->update_fn(&f->ctx, buf, nr); + git_hash_update(&f->ctx, buf, nr); flush(f, buf, nr); } else { /* @@ -218,7 +218,7 @@ void hashfile_checkpoint(struct hashfile *f, struct hashfile_checkpoint *checkpo { hashflush(f); checkpoint->offset = f->total; - f->algop->clone_fn(&checkpoint->ctx, &f->ctx); + git_hash_clone(&checkpoint->ctx, &f->ctx); } int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint) @@ -229,7 +229,7 @@ int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint lseek(f->fd, offset, SEEK_SET) != offset) return -1; f->total = offset; - f->algop->clone_fn(&f->ctx, &checkpoint->ctx); + git_hash_clone(&f->ctx, &checkpoint->ctx); f->offset = 0; /* hashflush() was called in checkpoint */ return 0; } @@ -249,7 +249,7 @@ uint32_t crc32_end(struct hashfile *f) int hashfile_checksum_valid(const unsigned char *data, size_t total_len) { unsigned char got[GIT_MAX_RAWSZ]; - git_hash_ctx ctx; + struct git_hash_ctx ctx; const struct git_hash_algo *algop = unsafe_hash_algo(the_hash_algo); size_t data_len = total_len - algop->rawsz; @@ -257,8 +257,8 @@ int hashfile_checksum_valid(const unsigned char *data, size_t total_len) return 0; /* say "too short"? */ algop->init_fn(&ctx); - algop->update_fn(&ctx, data, data_len); - algop->final_fn(got, &ctx); + git_hash_update(&ctx, data, data_len); + git_hash_final(got, &ctx); return hasheq(got, data + data_len, algop); } diff --git a/csum-file.h b/csum-file.h index b7475f16c2..ffccbf0996 100644 --- a/csum-file.h +++ b/csum-file.h @@ -11,7 +11,7 @@ struct hashfile { int fd; int check_fd; unsigned int offset; - git_hash_ctx ctx; + struct git_hash_ctx ctx; off_t total; struct progress *tp; const char *name; @@ -33,7 +33,7 @@ struct hashfile { /* Checkpoint */ struct hashfile_checkpoint { off_t offset; - git_hash_ctx ctx; + struct git_hash_ctx ctx; }; void hashfile_checkpoint_init(struct hashfile *, struct hashfile_checkpoint *); @@ -6392,7 +6392,7 @@ static void diff_summary(struct diff_options *opt, struct diff_filepair *p) } struct patch_id_t { - git_hash_ctx *ctx; + struct git_hash_ctx *ctx; int patchlen; }; @@ -6409,13 +6409,13 @@ static int remove_space(char *line, int len) return dst - line; } -void flush_one_hunk(struct object_id *result, git_hash_ctx *ctx) +void flush_one_hunk(struct object_id *result, struct git_hash_ctx *ctx) { unsigned char hash[GIT_MAX_RAWSZ]; unsigned short carry = 0; int i; - the_hash_algo->final_fn(hash, ctx); + git_hash_final(hash, ctx); the_hash_algo->init_fn(ctx); /* 20-byte sum, with carry */ for (i = 0; i < the_hash_algo->rawsz; ++i) { @@ -6434,22 +6434,22 @@ static int patch_id_consume(void *priv, char *line, unsigned long len) return 0; new_len = remove_space(line, len); - the_hash_algo->update_fn(data->ctx, line, new_len); + git_hash_update(data->ctx, line, new_len); data->patchlen += new_len; return 0; } -static void patch_id_add_string(git_hash_ctx *ctx, const char *str) +static void patch_id_add_string(struct git_hash_ctx *ctx, const char *str) { - the_hash_algo->update_fn(ctx, str, strlen(str)); + git_hash_update(ctx, str, strlen(str)); } -static void patch_id_add_mode(git_hash_ctx *ctx, unsigned mode) +static void patch_id_add_mode(struct git_hash_ctx *ctx, unsigned mode) { /* large enough for 2^32 in octal */ char buf[12]; int len = xsnprintf(buf, sizeof(buf), "%06o", mode); - the_hash_algo->update_fn(ctx, buf, len); + git_hash_update(ctx, buf, len); } /* returns 0 upon success, and writes result into oid */ @@ -6457,7 +6457,7 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid { struct diff_queue_struct *q = &diff_queued_diff; int i; - git_hash_ctx ctx; + struct git_hash_ctx ctx; struct patch_id_t data; the_hash_algo->init_fn(&ctx); @@ -6493,9 +6493,9 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid len2 = remove_space(p->two->path, strlen(p->two->path)); patch_id_add_string(&ctx, "diff--git"); patch_id_add_string(&ctx, "a/"); - the_hash_algo->update_fn(&ctx, p->one->path, len1); + git_hash_update(&ctx, p->one->path, len1); patch_id_add_string(&ctx, "b/"); - the_hash_algo->update_fn(&ctx, p->two->path, len2); + git_hash_update(&ctx, p->two->path, len2); if (p->one->mode == 0) { patch_id_add_string(&ctx, "newfilemode"); @@ -6514,24 +6514,24 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid /* don't do anything since we're only populating header info */ } else if (diff_filespec_is_binary(options->repo, p->one) || diff_filespec_is_binary(options->repo, p->two)) { - the_hash_algo->update_fn(&ctx, oid_to_hex(&p->one->oid), + git_hash_update(&ctx, oid_to_hex(&p->one->oid), the_hash_algo->hexsz); - the_hash_algo->update_fn(&ctx, oid_to_hex(&p->two->oid), + git_hash_update(&ctx, oid_to_hex(&p->two->oid), the_hash_algo->hexsz); } else { if (p->one->mode == 0) { patch_id_add_string(&ctx, "---/dev/null"); patch_id_add_string(&ctx, "+++b/"); - the_hash_algo->update_fn(&ctx, p->two->path, len2); + git_hash_update(&ctx, p->two->path, len2); } else if (p->two->mode == 0) { patch_id_add_string(&ctx, "---a/"); - the_hash_algo->update_fn(&ctx, p->one->path, len1); + git_hash_update(&ctx, p->one->path, len1); patch_id_add_string(&ctx, "+++/dev/null"); } else { patch_id_add_string(&ctx, "---a/"); - the_hash_algo->update_fn(&ctx, p->one->path, len1); + git_hash_update(&ctx, p->one->path, len1); patch_id_add_string(&ctx, "+++b/"); - the_hash_algo->update_fn(&ctx, p->two->path, len2); + git_hash_update(&ctx, p->two->path, len2); } if (fill_mmfile(options->repo, &mf1, p->one) < 0 || @@ -652,7 +652,7 @@ void run_diff_index(struct rev_info *revs, unsigned int option); int do_diff_cache(const struct object_id *, struct diff_options *); int diff_flush_patch_id(struct diff_options *, struct object_id *, int); -void flush_one_hunk(struct object_id *result, git_hash_ctx *ctx); +void flush_one_hunk(struct object_id *result, struct git_hash_ctx *ctx); int diff_result_code(struct rev_info *); @@ -234,19 +234,20 @@ enum get_oid_result { #endif /* A suitably aligned type for stack allocations of hash contexts. */ -union git_hash_ctx { - git_SHA_CTX sha1; - git_SHA_CTX_unsafe sha1_unsafe; - - git_SHA256_CTX sha256; +struct git_hash_ctx { + const struct git_hash_algo *algop; + union { + git_SHA_CTX sha1; + git_SHA_CTX_unsafe sha1_unsafe; + git_SHA256_CTX sha256; + } state; }; -typedef union git_hash_ctx git_hash_ctx; -typedef void (*git_hash_init_fn)(git_hash_ctx *ctx); -typedef void (*git_hash_clone_fn)(git_hash_ctx *dst, const git_hash_ctx *src); -typedef void (*git_hash_update_fn)(git_hash_ctx *ctx, const void *in, size_t len); -typedef void (*git_hash_final_fn)(unsigned char *hash, git_hash_ctx *ctx); -typedef void (*git_hash_final_oid_fn)(struct object_id *oid, git_hash_ctx *ctx); +typedef void (*git_hash_init_fn)(struct git_hash_ctx *ctx); +typedef void (*git_hash_clone_fn)(struct git_hash_ctx *dst, const struct git_hash_ctx *src); +typedef void (*git_hash_update_fn)(struct git_hash_ctx *ctx, const void *in, size_t len); +typedef void (*git_hash_final_fn)(unsigned char *hash, struct git_hash_ctx *ctx); +typedef void (*git_hash_final_oid_fn)(struct object_id *oid, struct git_hash_ctx *ctx); struct git_hash_algo { /* @@ -296,6 +297,26 @@ struct git_hash_algo { }; extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS]; +static inline void git_hash_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src) +{ + src->algop->clone_fn(dst, src); +} + +static inline void git_hash_update(struct git_hash_ctx *ctx, const void *in, size_t len) +{ + ctx->algop->update_fn(ctx, in, len); +} + +static inline void git_hash_final(unsigned char *hash, struct git_hash_ctx *ctx) +{ + ctx->algop->final_fn(hash, ctx); +} + +static inline void git_hash_final_oid(struct object_id *oid, struct git_hash_ctx *ctx) +{ + ctx->algop->final_oid_fn(oid, ctx); +} + /* * Return a GIT_HASH_* constant based on the name. Returns GIT_HASH_UNKNOWN if * the name doesn't match a known algorithm. diff --git a/http-push.c b/http-push.c index 43da1c7cd3..1b030d96f4 100644 --- a/http-push.c +++ b/http-push.c @@ -760,7 +760,7 @@ static void handle_lockprop_ctx(struct xml_ctx *ctx, int tag_closed) static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed) { struct remote_lock *lock = (struct remote_lock *)ctx->userData; - git_hash_ctx hash_ctx; + struct git_hash_ctx hash_ctx; unsigned char lock_token_hash[GIT_MAX_RAWSZ]; if (tag_closed && ctx->cdata) { @@ -774,8 +774,8 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed) lock->token = xstrdup(ctx->cdata); the_hash_algo->init_fn(&hash_ctx); - the_hash_algo->update_fn(&hash_ctx, lock->token, strlen(lock->token)); - the_hash_algo->final_fn(lock_token_hash, &hash_ctx); + git_hash_update(&hash_ctx, lock->token, strlen(lock->token)); + git_hash_final(lock_token_hash, &hash_ctx); lock->tmpfile_suffix[0] = '_'; memcpy(lock->tmpfile_suffix + 1, hash_to_hex(lock_token_hash), the_hash_algo->hexsz); @@ -2597,8 +2597,8 @@ static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb, freq->stream.next_out = expn; freq->stream.avail_out = sizeof(expn); freq->zret = git_inflate(&freq->stream, Z_SYNC_FLUSH); - the_hash_algo->update_fn(&freq->c, expn, - sizeof(expn) - freq->stream.avail_out); + git_hash_update(&freq->c, expn, + sizeof(expn) - freq->stream.avail_out); } while (freq->stream.avail_in && freq->zret == Z_OK); return nmemb; } @@ -2763,7 +2763,7 @@ int finish_http_object_request(struct http_object_request *freq) return -1; } - the_hash_algo->final_oid_fn(&freq->real_oid, &freq->c); + git_hash_final_oid(&freq->real_oid, &freq->c); if (freq->zret != Z_STREAM_END) { unlink_or_warn(freq->tmpfile.buf); return -1; @@ -228,7 +228,7 @@ struct http_object_request { long http_code; struct object_id oid; struct object_id real_oid; - git_hash_ctx c; + struct git_hash_ctx c; git_zstream stream; int zret; int rename; diff --git a/object-file.c b/object-file.c index 6ce1caacae..00c3a4b910 100644 --- a/object-file.c +++ b/object-file.c @@ -86,84 +86,90 @@ static const struct object_id null_oid_sha256 = { .algo = GIT_HASH_SHA256, }; -static void git_hash_sha1_init(git_hash_ctx *ctx) +static void git_hash_sha1_init(struct git_hash_ctx *ctx) { - git_SHA1_Init(&ctx->sha1); + ctx->algop = &hash_algos[GIT_HASH_SHA1]; + git_SHA1_Init(&ctx->state.sha1); } -static void git_hash_sha1_clone(git_hash_ctx *dst, const git_hash_ctx *src) +static void git_hash_sha1_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src) { - git_SHA1_Clone(&dst->sha1, &src->sha1); + dst->algop = src->algop; + git_SHA1_Clone(&dst->state.sha1, &src->state.sha1); } -static void git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len) +static void git_hash_sha1_update(struct git_hash_ctx *ctx, const void *data, size_t len) { - git_SHA1_Update(&ctx->sha1, data, len); + git_SHA1_Update(&ctx->state.sha1, data, len); } -static void git_hash_sha1_final(unsigned char *hash, git_hash_ctx *ctx) +static void git_hash_sha1_final(unsigned char *hash, struct git_hash_ctx *ctx) { - git_SHA1_Final(hash, &ctx->sha1); + git_SHA1_Final(hash, &ctx->state.sha1); } -static void git_hash_sha1_final_oid(struct object_id *oid, git_hash_ctx *ctx) +static void git_hash_sha1_final_oid(struct object_id *oid, struct git_hash_ctx *ctx) { - git_SHA1_Final(oid->hash, &ctx->sha1); + git_SHA1_Final(oid->hash, &ctx->state.sha1); memset(oid->hash + GIT_SHA1_RAWSZ, 0, GIT_MAX_RAWSZ - GIT_SHA1_RAWSZ); oid->algo = GIT_HASH_SHA1; } -static void git_hash_sha1_init_unsafe(git_hash_ctx *ctx) +static void git_hash_sha1_init_unsafe(struct git_hash_ctx *ctx) { - git_SHA1_Init_unsafe(&ctx->sha1_unsafe); + ctx->algop = unsafe_hash_algo(&hash_algos[GIT_HASH_SHA1]); + git_SHA1_Init_unsafe(&ctx->state.sha1_unsafe); } -static void git_hash_sha1_clone_unsafe(git_hash_ctx *dst, const git_hash_ctx *src) +static void git_hash_sha1_clone_unsafe(struct git_hash_ctx *dst, const struct git_hash_ctx *src) { - git_SHA1_Clone_unsafe(&dst->sha1_unsafe, &src->sha1_unsafe); + dst->algop = src->algop; + git_SHA1_Clone_unsafe(&dst->state.sha1_unsafe, &src->state.sha1_unsafe); } -static void git_hash_sha1_update_unsafe(git_hash_ctx *ctx, const void *data, +static void git_hash_sha1_update_unsafe(struct git_hash_ctx *ctx, const void *data, size_t len) { - git_SHA1_Update_unsafe(&ctx->sha1_unsafe, data, len); + git_SHA1_Update_unsafe(&ctx->state.sha1_unsafe, data, len); } -static void git_hash_sha1_final_unsafe(unsigned char *hash, git_hash_ctx *ctx) +static void git_hash_sha1_final_unsafe(unsigned char *hash, struct git_hash_ctx *ctx) { - git_SHA1_Final_unsafe(hash, &ctx->sha1_unsafe); + git_SHA1_Final_unsafe(hash, &ctx->state.sha1_unsafe); } -static void git_hash_sha1_final_oid_unsafe(struct object_id *oid, git_hash_ctx *ctx) +static void git_hash_sha1_final_oid_unsafe(struct object_id *oid, struct git_hash_ctx *ctx) { - git_SHA1_Final_unsafe(oid->hash, &ctx->sha1_unsafe); + git_SHA1_Final_unsafe(oid->hash, &ctx->state.sha1_unsafe); memset(oid->hash + GIT_SHA1_RAWSZ, 0, GIT_MAX_RAWSZ - GIT_SHA1_RAWSZ); oid->algo = GIT_HASH_SHA1; } -static void git_hash_sha256_init(git_hash_ctx *ctx) +static void git_hash_sha256_init(struct git_hash_ctx *ctx) { - git_SHA256_Init(&ctx->sha256); + ctx->algop = unsafe_hash_algo(&hash_algos[GIT_HASH_SHA256]); + git_SHA256_Init(&ctx->state.sha256); } -static void git_hash_sha256_clone(git_hash_ctx *dst, const git_hash_ctx *src) +static void git_hash_sha256_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src) { - git_SHA256_Clone(&dst->sha256, &src->sha256); + dst->algop = src->algop; + git_SHA256_Clone(&dst->state.sha256, &src->state.sha256); } -static void git_hash_sha256_update(git_hash_ctx *ctx, const void *data, size_t len) +static void git_hash_sha256_update(struct git_hash_ctx *ctx, const void *data, size_t len) { - git_SHA256_Update(&ctx->sha256, data, len); + git_SHA256_Update(&ctx->state.sha256, data, len); } -static void git_hash_sha256_final(unsigned char *hash, git_hash_ctx *ctx) +static void git_hash_sha256_final(unsigned char *hash, struct git_hash_ctx *ctx) { - git_SHA256_Final(hash, &ctx->sha256); + git_SHA256_Final(hash, &ctx->state.sha256); } -static void git_hash_sha256_final_oid(struct object_id *oid, git_hash_ctx *ctx) +static void git_hash_sha256_final_oid(struct object_id *oid, struct git_hash_ctx *ctx) { - git_SHA256_Final(oid->hash, &ctx->sha256); + git_SHA256_Final(oid->hash, &ctx->state.sha256); /* * This currently does nothing, so the compiler should optimize it out, * but keep it in case we extend the hash size again. @@ -172,18 +178,18 @@ static void git_hash_sha256_final_oid(struct object_id *oid, git_hash_ctx *ctx) oid->algo = GIT_HASH_SHA256; } -static void git_hash_unknown_init(git_hash_ctx *ctx UNUSED) +static void git_hash_unknown_init(struct git_hash_ctx *ctx UNUSED) { BUG("trying to init unknown hash"); } -static void git_hash_unknown_clone(git_hash_ctx *dst UNUSED, - const git_hash_ctx *src UNUSED) +static void git_hash_unknown_clone(struct git_hash_ctx *dst UNUSED, + const struct git_hash_ctx *src UNUSED) { BUG("trying to clone unknown hash"); } -static void git_hash_unknown_update(git_hash_ctx *ctx UNUSED, +static void git_hash_unknown_update(struct git_hash_ctx *ctx UNUSED, const void *data UNUSED, size_t len UNUSED) { @@ -191,13 +197,13 @@ static void git_hash_unknown_update(git_hash_ctx *ctx UNUSED, } static void git_hash_unknown_final(unsigned char *hash UNUSED, - git_hash_ctx *ctx UNUSED) + struct git_hash_ctx *ctx UNUSED) { BUG("trying to finalize unknown hash"); } static void git_hash_unknown_final_oid(struct object_id *oid UNUSED, - git_hash_ctx *ctx UNUSED) + struct git_hash_ctx *ctx UNUSED) { BUG("trying to finalize unknown hash"); } @@ -1180,7 +1186,7 @@ int stream_object_signature(struct repository *r, const struct object_id *oid) unsigned long size; enum object_type obj_type; struct git_istream *st; - git_hash_ctx c; + struct git_hash_ctx c; char hdr[MAX_HEADER_LEN]; int hdrlen; @@ -1193,7 +1199,7 @@ int stream_object_signature(struct repository *r, const struct object_id *oid) /* Sha1.. */ r->hash_algo->init_fn(&c); - r->hash_algo->update_fn(&c, hdr, hdrlen); + git_hash_update(&c, hdr, hdrlen); for (;;) { char buf[1024 * 16]; ssize_t readlen = read_istream(st, buf, sizeof(buf)); @@ -1204,9 +1210,9 @@ int stream_object_signature(struct repository *r, const struct object_id *oid) } if (!readlen) break; - r->hash_algo->update_fn(&c, buf, readlen); + git_hash_update(&c, buf, readlen); } - r->hash_algo->final_oid_fn(&real_oid, &c); + git_hash_final_oid(&real_oid, &c); close_istream(st); return !oideq(oid, &real_oid) ? -1 : 0; } @@ -1945,15 +1951,15 @@ void *read_object_with_reference(struct repository *r, } } -static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c, +static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_ctx *c, const void *buf, unsigned long len, struct object_id *oid, char *hdr, int *hdrlen) { algo->init_fn(c); - algo->update_fn(c, hdr, *hdrlen); - algo->update_fn(c, buf, len); - algo->final_oid_fn(oid, c); + git_hash_update(c, hdr, *hdrlen); + git_hash_update(c, buf, len); + git_hash_final_oid(oid, c); } static void write_object_file_prepare(const struct git_hash_algo *algo, @@ -1961,7 +1967,7 @@ static void write_object_file_prepare(const struct git_hash_algo *algo, enum object_type type, struct object_id *oid, char *hdr, int *hdrlen) { - git_hash_ctx c; + struct git_hash_ctx c; /* Generate the header */ *hdrlen = format_object_header(hdr, *hdrlen, type, len); @@ -1975,7 +1981,7 @@ static void write_object_file_prepare_literally(const struct git_hash_algo *algo const char *type, struct object_id *oid, char *hdr, int *hdrlen) { - git_hash_ctx c; + struct git_hash_ctx c; *hdrlen = format_object_header_literally(hdr, *hdrlen, type, len); hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen); @@ -2206,7 +2212,7 @@ static int start_loose_object_common(struct strbuf *tmp_file, const char *filename, unsigned flags, git_zstream *stream, unsigned char *buf, size_t buflen, - git_hash_ctx *c, git_hash_ctx *compat_c, + struct git_hash_ctx *c, struct git_hash_ctx *compat_c, char *hdr, int hdrlen) { struct repository *repo = the_repository; @@ -2240,9 +2246,9 @@ static int start_loose_object_common(struct strbuf *tmp_file, stream->avail_in = hdrlen; while (git_deflate(stream, 0) == Z_OK) ; /* nothing */ - algo->update_fn(c, hdr, hdrlen); + git_hash_update(c, hdr, hdrlen); if (compat && compat_c) - compat->update_fn(compat_c, hdr, hdrlen); + git_hash_update(compat_c, hdr, hdrlen); return fd; } @@ -2251,21 +2257,20 @@ static int start_loose_object_common(struct strbuf *tmp_file, * Common steps for the inner git_deflate() loop for writing loose * objects. Returns what git_deflate() returns. */ -static int write_loose_object_common(git_hash_ctx *c, git_hash_ctx *compat_c, +static int write_loose_object_common(struct git_hash_ctx *c, struct git_hash_ctx *compat_c, git_zstream *stream, const int flush, unsigned char *in0, const int fd, unsigned char *compressed, const size_t compressed_len) { struct repository *repo = the_repository; - const struct git_hash_algo *algo = repo->hash_algo; const struct git_hash_algo *compat = repo->compat_hash_algo; int ret; ret = git_deflate(stream, flush ? Z_FINISH : 0); - algo->update_fn(c, in0, stream->next_in - in0); + git_hash_update(c, in0, stream->next_in - in0); if (compat && compat_c) - compat->update_fn(compat_c, in0, stream->next_in - in0); + git_hash_update(compat_c, in0, stream->next_in - in0); if (write_in_full(fd, compressed, stream->next_out - compressed) < 0) die_errno(_("unable to write loose object file")); stream->next_out = compressed; @@ -2280,21 +2285,20 @@ static int write_loose_object_common(git_hash_ctx *c, git_hash_ctx *compat_c, * - End the compression of zlib stream. * - Get the calculated oid to "oid". */ -static int end_loose_object_common(git_hash_ctx *c, git_hash_ctx *compat_c, +static int end_loose_object_common(struct git_hash_ctx *c, struct git_hash_ctx *compat_c, git_zstream *stream, struct object_id *oid, struct object_id *compat_oid) { struct repository *repo = the_repository; - const struct git_hash_algo *algo = repo->hash_algo; const struct git_hash_algo *compat = repo->compat_hash_algo; int ret; ret = git_deflate_end_gently(stream); if (ret != Z_OK) return ret; - algo->final_oid_fn(oid, c); + git_hash_final_oid(oid, c); if (compat && compat_c) - compat->final_oid_fn(compat_oid, compat_c); + git_hash_final_oid(compat_oid, compat_c); return Z_OK; } @@ -2306,7 +2310,7 @@ static int write_loose_object(const struct object_id *oid, char *hdr, int fd, ret; unsigned char compressed[4096]; git_zstream stream; - git_hash_ctx c; + struct git_hash_ctx c; struct object_id parano_oid; static struct strbuf tmp_file = STRBUF_INIT; static struct strbuf filename = STRBUF_INIT; @@ -2386,7 +2390,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len, int fd, ret, err = 0, flush = 0; unsigned char compressed[4096]; git_zstream stream; - git_hash_ctx c, compat_c; + struct git_hash_ctx c, compat_c; struct strbuf tmp_file = STRBUF_INIT; struct strbuf filename = STRBUF_INIT; int dirlen; @@ -3046,14 +3050,14 @@ static int check_stream_oid(git_zstream *stream, const char *path, const struct object_id *expected_oid) { - git_hash_ctx c; + struct git_hash_ctx c; struct object_id real_oid; unsigned char buf[4096]; unsigned long total_read; int status = Z_OK; the_hash_algo->init_fn(&c); - the_hash_algo->update_fn(&c, hdr, stream->total_out); + git_hash_update(&c, hdr, stream->total_out); /* * We already read some bytes into hdr, but the ones up to the NUL @@ -3073,7 +3077,7 @@ static int check_stream_oid(git_zstream *stream, if (size - total_read < stream->avail_out) stream->avail_out = size - total_read; status = git_inflate(stream, Z_FINISH); - the_hash_algo->update_fn(&c, buf, stream->next_out - buf); + git_hash_update(&c, buf, stream->next_out - buf); total_read += stream->next_out - buf; } git_inflate_end(stream); @@ -3088,7 +3092,7 @@ static int check_stream_oid(git_zstream *stream, return -1; } - the_hash_algo->final_oid_fn(&real_oid, &c); + git_hash_final_oid(&real_oid, &c); if (!oideq(expected_oid, &real_oid)) { error(_("hash mismatch for %s (expected %s)"), path, oid_to_hex(expected_oid)); diff --git a/pack-check.c b/pack-check.c index 8d9f6da7ce..d0aeb5ec41 100644 --- a/pack-check.c +++ b/pack-check.c @@ -58,7 +58,7 @@ static int verify_packfile(struct repository *r, { off_t index_size = p->index_size; const unsigned char *index_base = p->index_data; - git_hash_ctx ctx; + struct git_hash_ctx ctx; unsigned char hash[GIT_MAX_RAWSZ], *pack_sig; off_t offset = 0, pack_sig_ofs = 0; uint32_t nr_objects, i; @@ -77,9 +77,9 @@ static int verify_packfile(struct repository *r, pack_sig_ofs = p->pack_size - r->hash_algo->rawsz; if (offset > pack_sig_ofs) remaining -= (unsigned int)(offset - pack_sig_ofs); - r->hash_algo->update_fn(&ctx, in, remaining); + git_hash_update(&ctx, in, remaining); } while (offset < pack_sig_ofs); - r->hash_algo->final_fn(hash, &ctx); + git_hash_final(hash, &ctx); pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL); if (!hasheq(hash, pack_sig, the_repository->hash_algo)) err = error("%s pack checksum mismatch", diff --git a/pack-write.c b/pack-write.c index a2faeb1895..d61e29ba4e 100644 --- a/pack-write.c +++ b/pack-write.c @@ -395,7 +395,7 @@ void fixup_pack_header_footer(const struct git_hash_algo *hash_algo, off_t partial_pack_offset) { int aligned_sz, buf_sz = 8 * 1024; - git_hash_ctx old_hash_ctx, new_hash_ctx; + struct git_hash_ctx old_hash_ctx, new_hash_ctx; struct pack_header hdr; char *buf; ssize_t read_result; @@ -413,9 +413,9 @@ void fixup_pack_header_footer(const struct git_hash_algo *hash_algo, pack_name); if (lseek(pack_fd, 0, SEEK_SET) != 0) die_errno("Failed seeking to start of '%s'", pack_name); - hash_algo->update_fn(&old_hash_ctx, &hdr, sizeof(hdr)); + git_hash_update(&old_hash_ctx, &hdr, sizeof(hdr)); hdr.hdr_entries = htonl(object_count); - hash_algo->update_fn(&new_hash_ctx, &hdr, sizeof(hdr)); + git_hash_update(&new_hash_ctx, &hdr, sizeof(hdr)); write_or_die(pack_fd, &hdr, sizeof(hdr)); partial_pack_offset -= sizeof(hdr); @@ -430,7 +430,7 @@ void fixup_pack_header_footer(const struct git_hash_algo *hash_algo, break; if (n < 0) die_errno("Failed to checksum '%s'", pack_name); - hash_algo->update_fn(&new_hash_ctx, buf, n); + git_hash_update(&new_hash_ctx, buf, n); aligned_sz -= n; if (!aligned_sz) @@ -439,12 +439,13 @@ void fixup_pack_header_footer(const struct git_hash_algo *hash_algo, if (!partial_pack_hash) continue; - hash_algo->update_fn(&old_hash_ctx, buf, n); + git_hash_update(&old_hash_ctx, buf, n); partial_pack_offset -= n; if (partial_pack_offset == 0) { unsigned char hash[GIT_MAX_RAWSZ]; - hash_algo->final_fn(hash, &old_hash_ctx); - if (!hasheq(hash, partial_pack_hash, hash_algo)) + git_hash_final(hash, &old_hash_ctx); + if (!hasheq(hash, partial_pack_hash, + hash_algo)) die("Unexpected checksum for %s " "(disk corruption?)", pack_name); /* @@ -460,8 +461,8 @@ void fixup_pack_header_footer(const struct git_hash_algo *hash_algo, free(buf); if (partial_pack_hash) - hash_algo->final_fn(partial_pack_hash, &old_hash_ctx); - hash_algo->final_fn(new_pack_hash, &new_hash_ctx); + git_hash_final(partial_pack_hash, &old_hash_ctx); + git_hash_final(new_pack_hash, &new_hash_ctx); write_or_die(pack_fd, new_pack_hash, hash_algo->rawsz); fsync_component_or_die(FSYNC_COMPONENT_PACK, pack_fd, pack_name); } diff --git a/read-cache.c b/read-cache.c index d54be2c172..7ef01c3806 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1717,7 +1717,7 @@ int verify_ce_order; static int verify_hdr(const struct cache_header *hdr, unsigned long size) { - git_hash_ctx c; + struct git_hash_ctx c; unsigned char hash[GIT_MAX_RAWSZ]; int hdr_version; unsigned char *start, *end; @@ -1739,8 +1739,8 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size) return 0; the_hash_algo->init_fn(&c); - the_hash_algo->update_fn(&c, hdr, size - the_hash_algo->rawsz); - the_hash_algo->final_fn(hash, &c); + git_hash_update(&c, hdr, size - the_hash_algo->rawsz); + git_hash_final(hash, &c); if (!hasheq(hash, start, the_repository->hash_algo)) return error(_("bad index file sha1 signature")); return 0; @@ -2002,7 +2002,7 @@ static struct index_entry_offset_table *read_ieot_extension(const char *mmap, si static void write_ieot_extension(struct strbuf *sb, struct index_entry_offset_table *ieot); static size_t read_eoie_extension(const char *mmap, size_t mmap_size); -static void write_eoie_extension(struct strbuf *sb, git_hash_ctx *eoie_context, size_t offset); +static void write_eoie_extension(struct strbuf *sb, struct git_hash_ctx *eoie_context, size_t offset); struct load_index_extensions { @@ -2566,7 +2566,7 @@ int repo_index_has_changes(struct repository *repo, } static int write_index_ext_header(struct hashfile *f, - git_hash_ctx *eoie_f, + struct git_hash_ctx *eoie_f, unsigned int ext, unsigned int sz) { @@ -2576,8 +2576,8 @@ static int write_index_ext_header(struct hashfile *f, if (eoie_f) { ext = htonl(ext); sz = htonl(sz); - the_hash_algo->update_fn(eoie_f, &ext, sizeof(ext)); - the_hash_algo->update_fn(eoie_f, &sz, sizeof(sz)); + git_hash_update(eoie_f, &ext, sizeof(ext)); + git_hash_update(eoie_f, &sz, sizeof(sz)); } return 0; } @@ -2831,7 +2831,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, { uint64_t start = getnanotime(); struct hashfile *f; - git_hash_ctx *eoie_c = NULL; + struct git_hash_ctx *eoie_c = NULL; struct cache_header hdr; int i, err = 0, removed, extended, hdr_version; struct cache_entry **cache = istate->cache; @@ -3579,7 +3579,7 @@ static size_t read_eoie_extension(const char *mmap, size_t mmap_size) uint32_t extsize; size_t offset, src_offset; unsigned char hash[GIT_MAX_RAWSZ]; - git_hash_ctx c; + struct git_hash_ctx c; /* ensure we have an index big enough to contain an EOIE extension */ if (mmap_size < sizeof(struct cache_header) + EOIE_SIZE_WITH_HEADER + the_hash_algo->rawsz) @@ -3634,12 +3634,12 @@ static size_t read_eoie_extension(const char *mmap, size_t mmap_size) if (src_offset + 8 + extsize < src_offset) return 0; - the_hash_algo->update_fn(&c, mmap + src_offset, 8); + git_hash_update(&c, mmap + src_offset, 8); src_offset += 8; src_offset += extsize; } - the_hash_algo->final_fn(hash, &c); + git_hash_final(hash, &c); if (!hasheq(hash, (const unsigned char *)index, the_repository->hash_algo)) return 0; @@ -3650,7 +3650,7 @@ static size_t read_eoie_extension(const char *mmap, size_t mmap_size) return offset; } -static void write_eoie_extension(struct strbuf *sb, git_hash_ctx *eoie_context, size_t offset) +static void write_eoie_extension(struct strbuf *sb, struct git_hash_ctx *eoie_context, size_t offset) { uint32_t buffer; unsigned char hash[GIT_MAX_RAWSZ]; @@ -3660,7 +3660,7 @@ static void write_eoie_extension(struct strbuf *sb, git_hash_ctx *eoie_context, strbuf_add(sb, &buffer, sizeof(uint32_t)); /* hash */ - the_hash_algo->final_fn(hash, eoie_context); + git_hash_final(hash, eoie_context); strbuf_add(sb, hash, the_hash_algo->rawsz); } @@ -358,7 +358,7 @@ static void rerere_strbuf_putconflict(struct strbuf *buf, int ch, size_t size) } static int handle_conflict(struct strbuf *out, struct rerere_io *io, - int marker_size, git_hash_ctx *ctx) + int marker_size, struct git_hash_ctx *ctx) { enum { RR_SIDE_1 = 0, RR_SIDE_2, RR_ORIGINAL @@ -396,12 +396,12 @@ static int handle_conflict(struct strbuf *out, struct rerere_io *io, strbuf_addbuf(out, &two); rerere_strbuf_putconflict(out, '>', marker_size); if (ctx) { - the_hash_algo->update_fn(ctx, one.buf ? - one.buf : "", - one.len + 1); - the_hash_algo->update_fn(ctx, two.buf ? - two.buf : "", - two.len + 1); + git_hash_update(ctx, one.buf ? + one.buf : "", + one.len + 1); + git_hash_update(ctx, two.buf ? + two.buf : "", + two.len + 1); } break; } else if (hunk == RR_SIDE_1) @@ -432,7 +432,7 @@ static int handle_conflict(struct strbuf *out, struct rerere_io *io, */ static int handle_path(unsigned char *hash, struct rerere_io *io, int marker_size) { - git_hash_ctx ctx; + struct git_hash_ctx ctx; struct strbuf buf = STRBUF_INIT, out = STRBUF_INIT; int has_conflicts = 0; if (hash) @@ -453,7 +453,7 @@ static int handle_path(unsigned char *hash, struct rerere_io *io, int marker_siz strbuf_release(&out); if (hash) - the_hash_algo->final_fn(hash, &ctx); + git_hash_final(hash, &ctx); return has_conflicts; } diff --git a/t/helper/test-hash-speed.c b/t/helper/test-hash-speed.c index 80df1aae66..fbf67fe6bd 100644 --- a/t/helper/test-hash-speed.c +++ b/t/helper/test-hash-speed.c @@ -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 }; diff --git a/t/helper/test-hash.c b/t/helper/test-hash.c index aa82638c62..f0ee61c8b4 100644 --- a/t/helper/test-hash.c +++ b/t/helper/test-hash.c @@ -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); diff --git a/t/unit-tests/u-hash.c b/t/unit-tests/u-hash.c index a0320efe4b..bd4ac6a6e1 100644 --- a/t/unit-tests/u-hash.c +++ b/t/unit-tests/u-hash.c @@ -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]); } diff --git a/trace2/tr2_sid.c b/trace2/tr2_sid.c index 09c4ef0d17..1c1d27b0ee 100644 --- a/trace2/tr2_sid.c +++ b/trace2/tr2_sid.c @@ -32,7 +32,7 @@ static void tr2_sid_append_my_sid_component(void) { const struct git_hash_algo *algo = &hash_algos[GIT_HASH_SHA1]; struct tr2_tbuf tb_now; - git_hash_ctx ctx; + struct git_hash_ctx ctx; pid_t pid = getpid(); unsigned char hash[GIT_MAX_RAWSZ + 1]; char hex[GIT_MAX_HEXSZ + 1]; @@ -46,8 +46,8 @@ static void tr2_sid_append_my_sid_component(void) strbuf_add(&tr2sid_buf, "Localhost", 9); else { algo->init_fn(&ctx); - algo->update_fn(&ctx, hostname, strlen(hostname)); - algo->final_fn(hash, &ctx); + git_hash_update(&ctx, hostname, strlen(hostname)); + git_hash_final(hash, &ctx); hash_to_hex_algop_r(hex, hash, algo); strbuf_addch(&tr2sid_buf, 'H'); strbuf_add(&tr2sid_buf, hex, 8); |
