Git fork

global: adapt callers to use generic hash context helpers

Adapt callers to use generic hash context helpers instead of using the
hash algorithm to update them. This makes the callsites easier to reason
about and removes the possibility that the wrong hash algorithm is used
to update the hash context's state. And as a nice side effect this also
gets rid of a bunch of users of `the_hash_algo`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
0578f1e6 b2755c15

+103 -107
+6 -6
builtin/fast-import.c
··· 959 959 hdrlen = format_object_header((char *)hdr, sizeof(hdr), type, 960 960 dat->len); 961 961 the_hash_algo->init_fn(&c); 962 - the_hash_algo->update_fn(&c, hdr, hdrlen); 963 - the_hash_algo->update_fn(&c, dat->buf, dat->len); 964 - the_hash_algo->final_oid_fn(&oid, &c); 962 + git_hash_update(&c, hdr, hdrlen); 963 + git_hash_update(&c, dat->buf, dat->len); 964 + git_hash_final_oid(&oid, &c); 965 965 if (oidout) 966 966 oidcpy(oidout, &oid); 967 967 ··· 1113 1113 hdrlen = format_object_header((char *)out_buf, out_sz, OBJ_BLOB, len); 1114 1114 1115 1115 the_hash_algo->init_fn(&c); 1116 - the_hash_algo->update_fn(&c, out_buf, hdrlen); 1116 + git_hash_update(&c, out_buf, hdrlen); 1117 1117 1118 1118 crc32_begin(pack_file); 1119 1119 ··· 1131 1131 if (!n && feof(stdin)) 1132 1132 die("EOF in data (%" PRIuMAX " bytes remaining)", len); 1133 1133 1134 - the_hash_algo->update_fn(&c, in_buf, n); 1134 + git_hash_update(&c, in_buf, n); 1135 1135 s.next_in = in_buf; 1136 1136 s.avail_in = n; 1137 1137 len -= n; ··· 1157 1157 } 1158 1158 } 1159 1159 git_deflate_end(&s); 1160 - the_hash_algo->final_oid_fn(&oid, &c); 1160 + git_hash_final_oid(&oid, &c); 1161 1161 1162 1162 if (oidout) 1163 1163 oidcpy(oidout, &oid);
+6 -7
builtin/index-pack.c
··· 301 301 if (input_offset) { 302 302 if (output_fd >= 0) 303 303 write_or_die(output_fd, input_buffer, input_offset); 304 - the_hash_algo->update_fn(&input_ctx, input_buffer, input_offset); 304 + git_hash_update(&input_ctx, input_buffer, input_offset); 305 305 memmove(input_buffer, input_buffer + input_offset, input_len); 306 306 input_offset = 0; 307 307 } ··· 482 482 if (!is_delta_type(type)) { 483 483 hdrlen = format_object_header(hdr, sizeof(hdr), type, size); 484 484 the_hash_algo->init_fn(&c); 485 - the_hash_algo->update_fn(&c, hdr, hdrlen); 485 + git_hash_update(&c, hdr, hdrlen); 486 486 } else 487 487 oid = NULL; 488 488 if (type == OBJ_BLOB && size > big_file_threshold) ··· 502 502 status = git_inflate(&stream, 0); 503 503 use(input_len - stream.avail_in); 504 504 if (oid) 505 - the_hash_algo->update_fn(&c, last_out, stream.next_out - last_out); 505 + git_hash_update(&c, last_out, stream.next_out - last_out); 506 506 if (buf == fixed_buf) { 507 507 stream.next_out = buf; 508 508 stream.avail_out = sizeof(fixed_buf); ··· 512 512 bad_object(offset, _("inflate returned %d"), status); 513 513 git_inflate_end(&stream); 514 514 if (oid) 515 - the_hash_algo->final_oid_fn(oid, &c); 515 + git_hash_final_oid(oid, &c); 516 516 return buf == fixed_buf ? NULL : buf; 517 517 } 518 518 ··· 1286 1286 1287 1287 /* Check pack integrity */ 1288 1288 flush(); 1289 - the_hash_algo->init_fn(&tmp_ctx); 1290 - the_hash_algo->clone_fn(&tmp_ctx, &input_ctx); 1291 - the_hash_algo->final_fn(hash, &tmp_ctx); 1289 + git_hash_clone(&tmp_ctx, &input_ctx); 1290 + git_hash_final(hash, &tmp_ctx); 1292 1291 if (!hasheq(fill(the_hash_algo->rawsz), hash, the_repository->hash_algo)) 1293 1292 die(_("pack is corrupted (SHA1 mismatch)")); 1294 1293 use(the_hash_algo->rawsz);
+6 -6
builtin/patch-id.c
··· 85 85 !skip_prefix(line, "From ", &p) && 86 86 starts_with(line, "\\ ") && 12 < strlen(line)) { 87 87 if (verbatim) 88 - the_hash_algo->update_fn(&ctx, line, strlen(line)); 88 + git_hash_update(&ctx, line, strlen(line)); 89 89 continue; 90 90 } 91 91 ··· 104 104 starts_with(line, "Binary files")) { 105 105 diff_is_binary = 1; 106 106 before = 0; 107 - the_hash_algo->update_fn(&ctx, pre_oid_str, 108 - strlen(pre_oid_str)); 109 - the_hash_algo->update_fn(&ctx, post_oid_str, 110 - strlen(post_oid_str)); 107 + git_hash_update(&ctx, pre_oid_str, 108 + strlen(pre_oid_str)); 109 + git_hash_update(&ctx, post_oid_str, 110 + strlen(post_oid_str)); 111 111 if (stable) 112 112 flush_one_hunk(result, &ctx); 113 113 continue; ··· 165 165 /* Add line to hash algo (possibly removing whitespace) */ 166 166 len = verbatim ? strlen(line) : remove_space(line); 167 167 patchlen += len; 168 - the_hash_algo->update_fn(&ctx, line, len); 168 + git_hash_update(&ctx, line, len); 169 169 } 170 170 171 171 if (!found_next)
+8 -8
builtin/receive-pack.c
··· 572 572 memset(key, '\0', GIT_MAX_BLKSZ); 573 573 if (the_hash_algo->blksz < key_len) { 574 574 the_hash_algo->init_fn(&ctx); 575 - the_hash_algo->update_fn(&ctx, key_in, key_len); 576 - the_hash_algo->final_fn(key, &ctx); 575 + git_hash_update(&ctx, key_in, key_len); 576 + git_hash_final(key, &ctx); 577 577 } else { 578 578 memcpy(key, key_in, key_len); 579 579 } ··· 586 586 587 587 /* RFC 2104 2. (3) & (4) */ 588 588 the_hash_algo->init_fn(&ctx); 589 - the_hash_algo->update_fn(&ctx, k_ipad, sizeof(k_ipad)); 590 - the_hash_algo->update_fn(&ctx, text, text_len); 591 - the_hash_algo->final_fn(out, &ctx); 589 + git_hash_update(&ctx, k_ipad, sizeof(k_ipad)); 590 + git_hash_update(&ctx, text, text_len); 591 + git_hash_final(out, &ctx); 592 592 593 593 /* RFC 2104 2. (6) & (7) */ 594 594 the_hash_algo->init_fn(&ctx); 595 - the_hash_algo->update_fn(&ctx, k_opad, sizeof(k_opad)); 596 - the_hash_algo->update_fn(&ctx, out, the_hash_algo->rawsz); 597 - the_hash_algo->final_fn(out, &ctx); 595 + git_hash_update(&ctx, k_opad, sizeof(k_opad)); 596 + git_hash_update(&ctx, out, the_hash_algo->rawsz); 597 + git_hash_final(out, &ctx); 598 598 } 599 599 600 600 static char *prepare_push_cert_nonce(const char *path, timestamp_t stamp)
+4 -5
builtin/unpack-objects.c
··· 70 70 if (min > sizeof(buffer)) 71 71 die("cannot fill %d bytes", min); 72 72 if (offset) { 73 - the_hash_algo->update_fn(&ctx, buffer, offset); 73 + git_hash_update(&ctx, buffer, offset); 74 74 memmove(buffer, buffer + offset, len); 75 75 offset = 0; 76 76 } ··· 667 667 } 668 668 the_hash_algo->init_fn(&ctx); 669 669 unpack_all(); 670 - the_hash_algo->update_fn(&ctx, buffer, offset); 671 - the_hash_algo->init_fn(&tmp_ctx); 672 - the_hash_algo->clone_fn(&tmp_ctx, &ctx); 673 - the_hash_algo->final_oid_fn(&oid, &tmp_ctx); 670 + git_hash_update(&ctx, buffer, offset); 671 + git_hash_clone(&tmp_ctx, &ctx); 672 + git_hash_final_oid(&oid, &tmp_ctx); 674 673 if (strict) { 675 674 write_rest(); 676 675 if (fsck_finish(&fsck_options))
+3 -3
bulk-checkin.c
··· 194 194 if (rsize < hsize) 195 195 hsize = rsize; 196 196 if (hsize) 197 - the_hash_algo->update_fn(ctx, ibuf, hsize); 197 + git_hash_update(ctx, ibuf, hsize); 198 198 *already_hashed_to = offset; 199 199 } 200 200 s.next_in = ibuf; ··· 271 271 header_len = format_object_header((char *)obuf, sizeof(obuf), 272 272 OBJ_BLOB, size); 273 273 the_hash_algo->init_fn(&ctx); 274 - the_hash_algo->update_fn(&ctx, obuf, header_len); 274 + git_hash_update(&ctx, obuf, header_len); 275 275 276 276 /* Note: idx is non-NULL when we are writing */ 277 277 if ((flags & HASH_WRITE_OBJECT) != 0) { ··· 306 306 if (lseek(fd, seekback, SEEK_SET) == (off_t) -1) 307 307 return error("cannot seek back"); 308 308 } 309 - the_hash_algo->final_oid_fn(result_oid, &ctx); 309 + git_hash_final_oid(result_oid, &ctx); 310 310 if (!idx) 311 311 return 0; 312 312
+7 -7
csum-file.c
··· 50 50 51 51 if (offset) { 52 52 if (!f->skip_hash) 53 - f->algop->update_fn(&f->ctx, f->buffer, offset); 53 + git_hash_update(&f->ctx, f->buffer, offset); 54 54 flush(f, f->buffer, offset); 55 55 f->offset = 0; 56 56 } ··· 73 73 if (f->skip_hash) 74 74 hashclr(f->buffer, f->algop); 75 75 else 76 - f->algop->final_fn(f->buffer, &f->ctx); 76 + git_hash_final(f->buffer, &f->ctx); 77 77 78 78 if (result) 79 79 hashcpy(result, f->buffer, f->algop); ··· 128 128 * f->offset is necessarily zero. 129 129 */ 130 130 if (!f->skip_hash) 131 - f->algop->update_fn(&f->ctx, buf, nr); 131 + git_hash_update(&f->ctx, buf, nr); 132 132 flush(f, buf, nr); 133 133 } else { 134 134 /* ··· 217 217 { 218 218 hashflush(f); 219 219 checkpoint->offset = f->total; 220 - f->algop->clone_fn(&checkpoint->ctx, &f->ctx); 220 + git_hash_clone(&checkpoint->ctx, &f->ctx); 221 221 } 222 222 223 223 int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint) ··· 228 228 lseek(f->fd, offset, SEEK_SET) != offset) 229 229 return -1; 230 230 f->total = offset; 231 - f->algop->clone_fn(&f->ctx, &checkpoint->ctx); 231 + git_hash_clone(&f->ctx, &checkpoint->ctx); 232 232 f->offset = 0; /* hashflush() was called in checkpoint */ 233 233 return 0; 234 234 } ··· 256 256 return 0; /* say "too short"? */ 257 257 258 258 algop->init_fn(&ctx); 259 - algop->update_fn(&ctx, data, data_len); 260 - algop->final_fn(got, &ctx); 259 + git_hash_update(&ctx, data, data_len); 260 + git_hash_final(got, &ctx); 261 261 262 262 return hasheq(got, data + data_len, algop); 263 263 }
+12 -12
diff.c
··· 6415 6415 unsigned short carry = 0; 6416 6416 int i; 6417 6417 6418 - the_hash_algo->final_fn(hash, ctx); 6418 + git_hash_final(hash, ctx); 6419 6419 the_hash_algo->init_fn(ctx); 6420 6420 /* 20-byte sum, with carry */ 6421 6421 for (i = 0; i < the_hash_algo->rawsz; ++i) { ··· 6434 6434 return 0; 6435 6435 new_len = remove_space(line, len); 6436 6436 6437 - the_hash_algo->update_fn(data->ctx, line, new_len); 6437 + git_hash_update(data->ctx, line, new_len); 6438 6438 data->patchlen += new_len; 6439 6439 return 0; 6440 6440 } 6441 6441 6442 6442 static void patch_id_add_string(struct git_hash_ctx *ctx, const char *str) 6443 6443 { 6444 - the_hash_algo->update_fn(ctx, str, strlen(str)); 6444 + git_hash_update(ctx, str, strlen(str)); 6445 6445 } 6446 6446 6447 6447 static void patch_id_add_mode(struct git_hash_ctx *ctx, unsigned mode) ··· 6449 6449 /* large enough for 2^32 in octal */ 6450 6450 char buf[12]; 6451 6451 int len = xsnprintf(buf, sizeof(buf), "%06o", mode); 6452 - the_hash_algo->update_fn(ctx, buf, len); 6452 + git_hash_update(ctx, buf, len); 6453 6453 } 6454 6454 6455 6455 /* returns 0 upon success, and writes result into oid */ ··· 6493 6493 len2 = remove_space(p->two->path, strlen(p->two->path)); 6494 6494 patch_id_add_string(&ctx, "diff--git"); 6495 6495 patch_id_add_string(&ctx, "a/"); 6496 - the_hash_algo->update_fn(&ctx, p->one->path, len1); 6496 + git_hash_update(&ctx, p->one->path, len1); 6497 6497 patch_id_add_string(&ctx, "b/"); 6498 - the_hash_algo->update_fn(&ctx, p->two->path, len2); 6498 + git_hash_update(&ctx, p->two->path, len2); 6499 6499 6500 6500 if (p->one->mode == 0) { 6501 6501 patch_id_add_string(&ctx, "newfilemode"); ··· 6514 6514 /* don't do anything since we're only populating header info */ 6515 6515 } else if (diff_filespec_is_binary(options->repo, p->one) || 6516 6516 diff_filespec_is_binary(options->repo, p->two)) { 6517 - the_hash_algo->update_fn(&ctx, oid_to_hex(&p->one->oid), 6517 + git_hash_update(&ctx, oid_to_hex(&p->one->oid), 6518 6518 the_hash_algo->hexsz); 6519 - the_hash_algo->update_fn(&ctx, oid_to_hex(&p->two->oid), 6519 + git_hash_update(&ctx, oid_to_hex(&p->two->oid), 6520 6520 the_hash_algo->hexsz); 6521 6521 } else { 6522 6522 if (p->one->mode == 0) { 6523 6523 patch_id_add_string(&ctx, "---/dev/null"); 6524 6524 patch_id_add_string(&ctx, "+++b/"); 6525 - the_hash_algo->update_fn(&ctx, p->two->path, len2); 6525 + git_hash_update(&ctx, p->two->path, len2); 6526 6526 } else if (p->two->mode == 0) { 6527 6527 patch_id_add_string(&ctx, "---a/"); 6528 - the_hash_algo->update_fn(&ctx, p->one->path, len1); 6528 + git_hash_update(&ctx, p->one->path, len1); 6529 6529 patch_id_add_string(&ctx, "+++/dev/null"); 6530 6530 } else { 6531 6531 patch_id_add_string(&ctx, "---a/"); 6532 - the_hash_algo->update_fn(&ctx, p->one->path, len1); 6532 + git_hash_update(&ctx, p->one->path, len1); 6533 6533 patch_id_add_string(&ctx, "+++b/"); 6534 - the_hash_algo->update_fn(&ctx, p->two->path, len2); 6534 + git_hash_update(&ctx, p->two->path, len2); 6535 6535 } 6536 6536 6537 6537 if (fill_mmfile(options->repo, &mf1, p->one) < 0 ||
+2 -2
http-push.c
··· 774 774 lock->token = xstrdup(ctx->cdata); 775 775 776 776 the_hash_algo->init_fn(&hash_ctx); 777 - the_hash_algo->update_fn(&hash_ctx, lock->token, strlen(lock->token)); 778 - the_hash_algo->final_fn(lock_token_hash, &hash_ctx); 777 + git_hash_update(&hash_ctx, lock->token, strlen(lock->token)); 778 + git_hash_final(lock_token_hash, &hash_ctx); 779 779 780 780 lock->tmpfile_suffix[0] = '_'; 781 781 memcpy(lock->tmpfile_suffix + 1, hash_to_hex(lock_token_hash), the_hash_algo->hexsz);
+3 -3
http.c
··· 2597 2597 freq->stream.next_out = expn; 2598 2598 freq->stream.avail_out = sizeof(expn); 2599 2599 freq->zret = git_inflate(&freq->stream, Z_SYNC_FLUSH); 2600 - the_hash_algo->update_fn(&freq->c, expn, 2601 - sizeof(expn) - freq->stream.avail_out); 2600 + git_hash_update(&freq->c, expn, 2601 + sizeof(expn) - freq->stream.avail_out); 2602 2602 } while (freq->stream.avail_in && freq->zret == Z_OK); 2603 2603 return nmemb; 2604 2604 } ··· 2763 2763 return -1; 2764 2764 } 2765 2765 2766 - the_hash_algo->final_oid_fn(&freq->real_oid, &freq->c); 2766 + git_hash_final_oid(&freq->real_oid, &freq->c); 2767 2767 if (freq->zret != Z_STREAM_END) { 2768 2768 unlink_or_warn(freq->tmpfile.buf); 2769 2769 return -1;
+15 -17
object-file.c
··· 1199 1199 1200 1200 /* Sha1.. */ 1201 1201 r->hash_algo->init_fn(&c); 1202 - r->hash_algo->update_fn(&c, hdr, hdrlen); 1202 + git_hash_update(&c, hdr, hdrlen); 1203 1203 for (;;) { 1204 1204 char buf[1024 * 16]; 1205 1205 ssize_t readlen = read_istream(st, buf, sizeof(buf)); ··· 1210 1210 } 1211 1211 if (!readlen) 1212 1212 break; 1213 - r->hash_algo->update_fn(&c, buf, readlen); 1213 + git_hash_update(&c, buf, readlen); 1214 1214 } 1215 - r->hash_algo->final_oid_fn(&real_oid, &c); 1215 + git_hash_final_oid(&real_oid, &c); 1216 1216 close_istream(st); 1217 1217 return !oideq(oid, &real_oid) ? -1 : 0; 1218 1218 } ··· 1957 1957 char *hdr, int *hdrlen) 1958 1958 { 1959 1959 algo->init_fn(c); 1960 - algo->update_fn(c, hdr, *hdrlen); 1961 - algo->update_fn(c, buf, len); 1962 - algo->final_oid_fn(oid, c); 1960 + git_hash_update(c, hdr, *hdrlen); 1961 + git_hash_update(c, buf, len); 1962 + git_hash_final_oid(oid, c); 1963 1963 } 1964 1964 1965 1965 static void write_object_file_prepare(const struct git_hash_algo *algo, ··· 2246 2246 stream->avail_in = hdrlen; 2247 2247 while (git_deflate(stream, 0) == Z_OK) 2248 2248 ; /* nothing */ 2249 - algo->update_fn(c, hdr, hdrlen); 2249 + git_hash_update(c, hdr, hdrlen); 2250 2250 if (compat && compat_c) 2251 - compat->update_fn(compat_c, hdr, hdrlen); 2251 + git_hash_update(compat_c, hdr, hdrlen); 2252 2252 2253 2253 return fd; 2254 2254 } ··· 2264 2264 const size_t compressed_len) 2265 2265 { 2266 2266 struct repository *repo = the_repository; 2267 - const struct git_hash_algo *algo = repo->hash_algo; 2268 2267 const struct git_hash_algo *compat = repo->compat_hash_algo; 2269 2268 int ret; 2270 2269 2271 2270 ret = git_deflate(stream, flush ? Z_FINISH : 0); 2272 - algo->update_fn(c, in0, stream->next_in - in0); 2271 + git_hash_update(c, in0, stream->next_in - in0); 2273 2272 if (compat && compat_c) 2274 - compat->update_fn(compat_c, in0, stream->next_in - in0); 2273 + git_hash_update(compat_c, in0, stream->next_in - in0); 2275 2274 if (write_in_full(fd, compressed, stream->next_out - compressed) < 0) 2276 2275 die_errno(_("unable to write loose object file")); 2277 2276 stream->next_out = compressed; ··· 2291 2290 struct object_id *compat_oid) 2292 2291 { 2293 2292 struct repository *repo = the_repository; 2294 - const struct git_hash_algo *algo = repo->hash_algo; 2295 2293 const struct git_hash_algo *compat = repo->compat_hash_algo; 2296 2294 int ret; 2297 2295 2298 2296 ret = git_deflate_end_gently(stream); 2299 2297 if (ret != Z_OK) 2300 2298 return ret; 2301 - algo->final_oid_fn(oid, c); 2299 + git_hash_final_oid(oid, c); 2302 2300 if (compat && compat_c) 2303 - compat->final_oid_fn(compat_oid, compat_c); 2301 + git_hash_final_oid(compat_oid, compat_c); 2304 2302 2305 2303 return Z_OK; 2306 2304 } ··· 3059 3057 int status = Z_OK; 3060 3058 3061 3059 the_hash_algo->init_fn(&c); 3062 - the_hash_algo->update_fn(&c, hdr, stream->total_out); 3060 + git_hash_update(&c, hdr, stream->total_out); 3063 3061 3064 3062 /* 3065 3063 * We already read some bytes into hdr, but the ones up to the NUL ··· 3079 3077 if (size - total_read < stream->avail_out) 3080 3078 stream->avail_out = size - total_read; 3081 3079 status = git_inflate(stream, Z_FINISH); 3082 - the_hash_algo->update_fn(&c, buf, stream->next_out - buf); 3080 + git_hash_update(&c, buf, stream->next_out - buf); 3083 3081 total_read += stream->next_out - buf; 3084 3082 } 3085 3083 git_inflate_end(stream); ··· 3094 3092 return -1; 3095 3093 } 3096 3094 3097 - the_hash_algo->final_oid_fn(&real_oid, &c); 3095 + git_hash_final_oid(&real_oid, &c); 3098 3096 if (!oideq(expected_oid, &real_oid)) { 3099 3097 error(_("hash mismatch for %s (expected %s)"), path, 3100 3098 oid_to_hex(expected_oid));
+2 -2
pack-check.c
··· 77 77 pack_sig_ofs = p->pack_size - r->hash_algo->rawsz; 78 78 if (offset > pack_sig_ofs) 79 79 remaining -= (unsigned int)(offset - pack_sig_ofs); 80 - r->hash_algo->update_fn(&ctx, in, remaining); 80 + git_hash_update(&ctx, in, remaining); 81 81 } while (offset < pack_sig_ofs); 82 - r->hash_algo->final_fn(hash, &ctx); 82 + git_hash_final(hash, &ctx); 83 83 pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL); 84 84 if (!hasheq(hash, pack_sig, the_repository->hash_algo)) 85 85 err = error("%s pack checksum mismatch",
+7 -7
pack-write.c
··· 406 406 pack_name); 407 407 if (lseek(pack_fd, 0, SEEK_SET) != 0) 408 408 die_errno("Failed seeking to start of '%s'", pack_name); 409 - the_hash_algo->update_fn(&old_hash_ctx, &hdr, sizeof(hdr)); 409 + git_hash_update(&old_hash_ctx, &hdr, sizeof(hdr)); 410 410 hdr.hdr_entries = htonl(object_count); 411 - the_hash_algo->update_fn(&new_hash_ctx, &hdr, sizeof(hdr)); 411 + git_hash_update(&new_hash_ctx, &hdr, sizeof(hdr)); 412 412 write_or_die(pack_fd, &hdr, sizeof(hdr)); 413 413 partial_pack_offset -= sizeof(hdr); 414 414 ··· 423 423 break; 424 424 if (n < 0) 425 425 die_errno("Failed to checksum '%s'", pack_name); 426 - the_hash_algo->update_fn(&new_hash_ctx, buf, n); 426 + git_hash_update(&new_hash_ctx, buf, n); 427 427 428 428 aligned_sz -= n; 429 429 if (!aligned_sz) ··· 432 432 if (!partial_pack_hash) 433 433 continue; 434 434 435 - the_hash_algo->update_fn(&old_hash_ctx, buf, n); 435 + git_hash_update(&old_hash_ctx, buf, n); 436 436 partial_pack_offset -= n; 437 437 if (partial_pack_offset == 0) { 438 438 unsigned char hash[GIT_MAX_RAWSZ]; 439 - the_hash_algo->final_fn(hash, &old_hash_ctx); 439 + git_hash_final(hash, &old_hash_ctx); 440 440 if (!hasheq(hash, partial_pack_hash, 441 441 the_repository->hash_algo)) 442 442 die("Unexpected checksum for %s " ··· 454 454 free(buf); 455 455 456 456 if (partial_pack_hash) 457 - the_hash_algo->final_fn(partial_pack_hash, &old_hash_ctx); 458 - the_hash_algo->final_fn(new_pack_hash, &new_hash_ctx); 457 + git_hash_final(partial_pack_hash, &old_hash_ctx); 458 + git_hash_final(new_pack_hash, &new_hash_ctx); 459 459 write_or_die(pack_fd, new_pack_hash, the_hash_algo->rawsz); 460 460 fsync_component_or_die(FSYNC_COMPONENT_PACK, pack_fd, pack_name); 461 461 }
+7 -7
read-cache.c
··· 1739 1739 return 0; 1740 1740 1741 1741 the_hash_algo->init_fn(&c); 1742 - the_hash_algo->update_fn(&c, hdr, size - the_hash_algo->rawsz); 1743 - the_hash_algo->final_fn(hash, &c); 1742 + git_hash_update(&c, hdr, size - the_hash_algo->rawsz); 1743 + git_hash_final(hash, &c); 1744 1744 if (!hasheq(hash, start, the_repository->hash_algo)) 1745 1745 return error(_("bad index file sha1 signature")); 1746 1746 return 0; ··· 2576 2576 if (eoie_f) { 2577 2577 ext = htonl(ext); 2578 2578 sz = htonl(sz); 2579 - the_hash_algo->update_fn(eoie_f, &ext, sizeof(ext)); 2580 - the_hash_algo->update_fn(eoie_f, &sz, sizeof(sz)); 2579 + git_hash_update(eoie_f, &ext, sizeof(ext)); 2580 + git_hash_update(eoie_f, &sz, sizeof(sz)); 2581 2581 } 2582 2582 return 0; 2583 2583 } ··· 3634 3634 if (src_offset + 8 + extsize < src_offset) 3635 3635 return 0; 3636 3636 3637 - the_hash_algo->update_fn(&c, mmap + src_offset, 8); 3637 + git_hash_update(&c, mmap + src_offset, 8); 3638 3638 3639 3639 src_offset += 8; 3640 3640 src_offset += extsize; 3641 3641 } 3642 - the_hash_algo->final_fn(hash, &c); 3642 + git_hash_final(hash, &c); 3643 3643 if (!hasheq(hash, (const unsigned char *)index, the_repository->hash_algo)) 3644 3644 return 0; 3645 3645 ··· 3660 3660 strbuf_add(sb, &buffer, sizeof(uint32_t)); 3661 3661 3662 3662 /* hash */ 3663 - the_hash_algo->final_fn(hash, eoie_context); 3663 + git_hash_final(hash, eoie_context); 3664 3664 strbuf_add(sb, hash, the_hash_algo->rawsz); 3665 3665 } 3666 3666
+7 -7
rerere.c
··· 396 396 strbuf_addbuf(out, &two); 397 397 rerere_strbuf_putconflict(out, '>', marker_size); 398 398 if (ctx) { 399 - the_hash_algo->update_fn(ctx, one.buf ? 400 - one.buf : "", 401 - one.len + 1); 402 - the_hash_algo->update_fn(ctx, two.buf ? 403 - two.buf : "", 404 - two.len + 1); 399 + git_hash_update(ctx, one.buf ? 400 + one.buf : "", 401 + one.len + 1); 402 + git_hash_update(ctx, two.buf ? 403 + two.buf : "", 404 + two.len + 1); 405 405 } 406 406 break; 407 407 } else if (hunk == RR_SIDE_1) ··· 453 453 strbuf_release(&out); 454 454 455 455 if (hash) 456 - the_hash_algo->final_fn(hash, &ctx); 456 + git_hash_final(hash, &ctx); 457 457 458 458 return has_conflicts; 459 459 }
+2 -2
t/helper/test-hash-speed.c
··· 6 6 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) 7 7 { 8 8 algo->init_fn(ctx); 9 - algo->update_fn(ctx, p, len); 10 - algo->final_fn(final, ctx); 9 + git_hash_update(ctx, p, len); 10 + git_hash_final(final, ctx); 11 11 } 12 12 13 13 int cmd__hash_speed(int ac, const char **av)
+2 -2
t/helper/test-hash.c
··· 48 48 } 49 49 if (this_sz == 0) 50 50 break; 51 - algop->update_fn(&ctx, buffer, this_sz); 51 + git_hash_update(&ctx, buffer, this_sz); 52 52 } 53 - algop->final_fn(hash, &ctx); 53 + git_hash_final(hash, &ctx); 54 54 55 55 if (binary) 56 56 fwrite(hash, 1, algop->rawsz, stdout);
+2 -2
t/unit-tests/u-hash.c
··· 13 13 const struct git_hash_algo *algop = &hash_algos[i]; 14 14 15 15 algop->init_fn(&ctx); 16 - algop->update_fn(&ctx, data, data_length); 17 - algop->final_fn(hash, &ctx); 16 + git_hash_update(&ctx, data, data_length); 17 + git_hash_final(hash, &ctx); 18 18 19 19 cl_assert_equal_s(hash_to_hex_algop(hash,algop), expected_hashes[i - 1]); 20 20 }
+2 -2
trace2/tr2_sid.c
··· 46 46 strbuf_add(&tr2sid_buf, "Localhost", 9); 47 47 else { 48 48 algo->init_fn(&ctx); 49 - algo->update_fn(&ctx, hostname, strlen(hostname)); 50 - algo->final_fn(hash, &ctx); 49 + git_hash_update(&ctx, hostname, strlen(hostname)); 50 + git_hash_final(hash, &ctx); 51 51 hash_to_hex_algop_r(hex, hash, algo); 52 52 strbuf_addch(&tr2sid_buf, 'H'); 53 53 strbuf_add(&tr2sid_buf, hex, 8);