Git fork

Merge branch 'ps/hash-cleanup'

Further code clean-up on the use of hash functions. Now the
context object knows what hash function it is working with.

* ps/hash-cleanup:
global: adapt callers to use generic hash context helpers
hash: provide generic wrappers to update hash contexts
hash: stop typedeffing the hash context
hash: convert hashing context to a structure

+226 -202
+8 -8
builtin/fast-import.c
··· 954 954 unsigned char hdr[96]; 955 955 struct object_id oid; 956 956 unsigned long hdrlen, deltalen; 957 - git_hash_ctx c; 957 + struct git_hash_ctx c; 958 958 git_zstream s; 959 959 960 960 hdrlen = format_object_header((char *)hdr, sizeof(hdr), type, 961 961 dat->len); 962 962 the_hash_algo->init_fn(&c); 963 - the_hash_algo->update_fn(&c, hdr, hdrlen); 964 - the_hash_algo->update_fn(&c, dat->buf, dat->len); 965 - the_hash_algo->final_oid_fn(&oid, &c); 963 + git_hash_update(&c, hdr, hdrlen); 964 + git_hash_update(&c, dat->buf, dat->len); 965 + git_hash_final_oid(&oid, &c); 966 966 if (oidout) 967 967 oidcpy(oidout, &oid); 968 968 ··· 1096 1096 struct object_id oid; 1097 1097 unsigned long hdrlen; 1098 1098 off_t offset; 1099 - git_hash_ctx c; 1099 + struct git_hash_ctx c; 1100 1100 git_zstream s; 1101 1101 struct hashfile_checkpoint checkpoint; 1102 1102 int status = Z_OK; ··· 1114 1114 hdrlen = format_object_header((char *)out_buf, out_sz, OBJ_BLOB, len); 1115 1115 1116 1116 the_hash_algo->init_fn(&c); 1117 - the_hash_algo->update_fn(&c, out_buf, hdrlen); 1117 + git_hash_update(&c, out_buf, hdrlen); 1118 1118 1119 1119 crc32_begin(pack_file); 1120 1120 ··· 1132 1132 if (!n && feof(stdin)) 1133 1133 die("EOF in data (%" PRIuMAX " bytes remaining)", len); 1134 1134 1135 - the_hash_algo->update_fn(&c, in_buf, n); 1135 + git_hash_update(&c, in_buf, n); 1136 1136 s.next_in = in_buf; 1137 1137 s.avail_in = n; 1138 1138 len -= n; ··· 1158 1158 } 1159 1159 } 1160 1160 git_deflate_end(&s); 1161 - the_hash_algo->final_oid_fn(&oid, &c); 1161 + git_hash_final_oid(&oid, &c); 1162 1162 1163 1163 if (oidout) 1164 1164 oidcpy(oidout, &oid);
+9 -10
builtin/index-pack.c
··· 151 151 static off_t consumed_bytes; 152 152 static off_t max_input_size; 153 153 static unsigned deepest_delta; 154 - static git_hash_ctx input_ctx; 154 + static struct git_hash_ctx input_ctx; 155 155 static uint32_t input_crc32; 156 156 static int input_fd, output_fd; 157 157 static const char *curr_pack; ··· 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 } ··· 475 475 int status; 476 476 git_zstream stream; 477 477 void *buf; 478 - git_hash_ctx c; 478 + struct git_hash_ctx c; 479 479 char hdr[32]; 480 480 int hdrlen; 481 481 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 ··· 1248 1248 struct ofs_delta_entry *ofs_delta = ofs_deltas; 1249 1249 struct object_id ref_delta_oid; 1250 1250 struct stat st; 1251 - git_hash_ctx tmp_ctx; 1251 + struct git_hash_ctx tmp_ctx; 1252 1252 1253 1253 if (verbose) 1254 1254 progress = start_progress( ··· 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);
+7 -7
builtin/patch-id.c
··· 70 70 int before = -1, after = -1; 71 71 int diff_is_binary = 0; 72 72 char pre_oid_str[GIT_MAX_HEXSZ + 1], post_oid_str[GIT_MAX_HEXSZ + 1]; 73 - git_hash_ctx ctx; 73 + struct git_hash_ctx ctx; 74 74 75 75 the_hash_algo->init_fn(&ctx); 76 76 oidclr(result, the_repository->hash_algo); ··· 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)
+9 -9
builtin/receive-pack.c
··· 566 566 unsigned char k_ipad[GIT_MAX_BLKSZ]; 567 567 unsigned char k_opad[GIT_MAX_BLKSZ]; 568 568 int i; 569 - git_hash_ctx ctx; 569 + struct git_hash_ctx ctx; 570 570 571 571 /* RFC 2104 2. (1) */ 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)
+6 -7
builtin/unpack-objects.c
··· 28 28 static unsigned int offset, len; 29 29 static off_t consumed_bytes; 30 30 static off_t max_input_size; 31 - static git_hash_ctx ctx; 31 + static struct git_hash_ctx ctx; 32 32 static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT; 33 33 static struct progress *progress; 34 34 ··· 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 } ··· 614 614 { 615 615 int i; 616 616 struct object_id oid; 617 - git_hash_ctx tmp_ctx; 617 + struct git_hash_ctx tmp_ctx; 618 618 619 619 disable_replace_refs(); 620 620 ··· 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))
+5 -5
bulk-checkin.c
··· 162 162 * with a new pack. 163 163 */ 164 164 static int stream_blob_to_pack(struct bulk_checkin_packfile *state, 165 - git_hash_ctx *ctx, off_t *already_hashed_to, 165 + struct git_hash_ctx *ctx, off_t *already_hashed_to, 166 166 int fd, size_t size, const char *path, 167 167 unsigned flags) 168 168 { ··· 195 195 if (rsize < hsize) 196 196 hsize = rsize; 197 197 if (hsize) 198 - the_hash_algo->update_fn(ctx, ibuf, hsize); 198 + git_hash_update(ctx, ibuf, hsize); 199 199 *already_hashed_to = offset; 200 200 } 201 201 s.next_in = ibuf; ··· 259 259 const char *path, unsigned flags) 260 260 { 261 261 off_t seekback, already_hashed_to; 262 - git_hash_ctx ctx; 262 + struct git_hash_ctx ctx; 263 263 unsigned char obuf[16384]; 264 264 unsigned header_len; 265 265 struct hashfile_checkpoint checkpoint; ··· 272 272 header_len = format_object_header((char *)obuf, sizeof(obuf), 273 273 OBJ_BLOB, size); 274 274 the_hash_algo->init_fn(&ctx); 275 - the_hash_algo->update_fn(&ctx, obuf, header_len); 275 + git_hash_update(&ctx, obuf, header_len); 276 276 277 277 /* Note: idx is non-NULL when we are writing */ 278 278 if ((flags & HASH_WRITE_OBJECT) != 0) { ··· 307 307 if (lseek(fd, seekback, SEEK_SET) == (off_t) -1) 308 308 return error("cannot seek back"); 309 309 } 310 - the_hash_algo->final_oid_fn(result_oid, &ctx); 310 + git_hash_final_oid(result_oid, &ctx); 311 311 if (!idx) 312 312 return 0; 313 313
+8 -8
csum-file.c
··· 51 51 52 52 if (offset) { 53 53 if (!f->skip_hash) 54 - f->algop->update_fn(&f->ctx, f->buffer, offset); 54 + git_hash_update(&f->ctx, f->buffer, offset); 55 55 flush(f, f->buffer, offset); 56 56 f->offset = 0; 57 57 } ··· 74 74 if (f->skip_hash) 75 75 hashclr(f->buffer, f->algop); 76 76 else 77 - f->algop->final_fn(f->buffer, &f->ctx); 77 + git_hash_final(f->buffer, &f->ctx); 78 78 79 79 if (result) 80 80 hashcpy(result, f->buffer, f->algop); ··· 129 129 * f->offset is necessarily zero. 130 130 */ 131 131 if (!f->skip_hash) 132 - f->algop->update_fn(&f->ctx, buf, nr); 132 + git_hash_update(&f->ctx, buf, nr); 133 133 flush(f, buf, nr); 134 134 } else { 135 135 /* ··· 218 218 { 219 219 hashflush(f); 220 220 checkpoint->offset = f->total; 221 - f->algop->clone_fn(&checkpoint->ctx, &f->ctx); 221 + git_hash_clone(&checkpoint->ctx, &f->ctx); 222 222 } 223 223 224 224 int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint) ··· 229 229 lseek(f->fd, offset, SEEK_SET) != offset) 230 230 return -1; 231 231 f->total = offset; 232 - f->algop->clone_fn(&f->ctx, &checkpoint->ctx); 232 + git_hash_clone(&f->ctx, &checkpoint->ctx); 233 233 f->offset = 0; /* hashflush() was called in checkpoint */ 234 234 return 0; 235 235 } ··· 249 249 int hashfile_checksum_valid(const unsigned char *data, size_t total_len) 250 250 { 251 251 unsigned char got[GIT_MAX_RAWSZ]; 252 - git_hash_ctx ctx; 252 + struct git_hash_ctx ctx; 253 253 const struct git_hash_algo *algop = unsafe_hash_algo(the_hash_algo); 254 254 size_t data_len = total_len - algop->rawsz; 255 255 ··· 257 257 return 0; /* say "too short"? */ 258 258 259 259 algop->init_fn(&ctx); 260 - algop->update_fn(&ctx, data, data_len); 261 - algop->final_fn(got, &ctx); 260 + git_hash_update(&ctx, data, data_len); 261 + git_hash_final(got, &ctx); 262 262 263 263 return hasheq(got, data + data_len, algop); 264 264 }
+2 -2
csum-file.h
··· 11 11 int fd; 12 12 int check_fd; 13 13 unsigned int offset; 14 - git_hash_ctx ctx; 14 + struct git_hash_ctx ctx; 15 15 off_t total; 16 16 struct progress *tp; 17 17 const char *name; ··· 33 33 /* Checkpoint */ 34 34 struct hashfile_checkpoint { 35 35 off_t offset; 36 - git_hash_ctx ctx; 36 + struct git_hash_ctx ctx; 37 37 }; 38 38 39 39 void hashfile_checkpoint_init(struct hashfile *, struct hashfile_checkpoint *);
+17 -17
diff.c
··· 6392 6392 } 6393 6393 6394 6394 struct patch_id_t { 6395 - git_hash_ctx *ctx; 6395 + struct git_hash_ctx *ctx; 6396 6396 int patchlen; 6397 6397 }; 6398 6398 ··· 6409 6409 return dst - line; 6410 6410 } 6411 6411 6412 - void flush_one_hunk(struct object_id *result, git_hash_ctx *ctx) 6412 + void flush_one_hunk(struct object_id *result, struct git_hash_ctx *ctx) 6413 6413 { 6414 6414 unsigned char hash[GIT_MAX_RAWSZ]; 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 - static void patch_id_add_string(git_hash_ctx *ctx, const char *str) 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 - static void patch_id_add_mode(git_hash_ctx *ctx, unsigned mode) 6447 + static void patch_id_add_mode(struct git_hash_ctx *ctx, unsigned mode) 6448 6448 { 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 */ ··· 6457 6457 { 6458 6458 struct diff_queue_struct *q = &diff_queued_diff; 6459 6459 int i; 6460 - git_hash_ctx ctx; 6460 + struct git_hash_ctx ctx; 6461 6461 struct patch_id_t data; 6462 6462 6463 6463 the_hash_algo->init_fn(&ctx); ··· 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 ||
+1 -1
diff.h
··· 652 652 653 653 int do_diff_cache(const struct object_id *, struct diff_options *); 654 654 int diff_flush_patch_id(struct diff_options *, struct object_id *, int); 655 - void flush_one_hunk(struct object_id *result, git_hash_ctx *ctx); 655 + void flush_one_hunk(struct object_id *result, struct git_hash_ctx *ctx); 656 656 657 657 int diff_result_code(struct rev_info *); 658 658
+32 -11
hash.h
··· 234 234 #endif 235 235 236 236 /* A suitably aligned type for stack allocations of hash contexts. */ 237 - union git_hash_ctx { 238 - git_SHA_CTX sha1; 239 - git_SHA_CTX_unsafe sha1_unsafe; 240 - 241 - git_SHA256_CTX sha256; 237 + struct git_hash_ctx { 238 + const struct git_hash_algo *algop; 239 + union { 240 + git_SHA_CTX sha1; 241 + git_SHA_CTX_unsafe sha1_unsafe; 242 + git_SHA256_CTX sha256; 243 + } state; 242 244 }; 243 - typedef union git_hash_ctx git_hash_ctx; 244 245 245 - typedef void (*git_hash_init_fn)(git_hash_ctx *ctx); 246 - typedef void (*git_hash_clone_fn)(git_hash_ctx *dst, const git_hash_ctx *src); 247 - typedef void (*git_hash_update_fn)(git_hash_ctx *ctx, const void *in, size_t len); 248 - typedef void (*git_hash_final_fn)(unsigned char *hash, git_hash_ctx *ctx); 249 - typedef void (*git_hash_final_oid_fn)(struct object_id *oid, git_hash_ctx *ctx); 246 + typedef void (*git_hash_init_fn)(struct git_hash_ctx *ctx); 247 + typedef void (*git_hash_clone_fn)(struct git_hash_ctx *dst, const struct git_hash_ctx *src); 248 + typedef void (*git_hash_update_fn)(struct git_hash_ctx *ctx, const void *in, size_t len); 249 + typedef void (*git_hash_final_fn)(unsigned char *hash, struct git_hash_ctx *ctx); 250 + typedef void (*git_hash_final_oid_fn)(struct object_id *oid, struct git_hash_ctx *ctx); 250 251 251 252 struct git_hash_algo { 252 253 /* ··· 295 296 const struct git_hash_algo *unsafe; 296 297 }; 297 298 extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS]; 299 + 300 + static inline void git_hash_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src) 301 + { 302 + src->algop->clone_fn(dst, src); 303 + } 304 + 305 + static inline void git_hash_update(struct git_hash_ctx *ctx, const void *in, size_t len) 306 + { 307 + ctx->algop->update_fn(ctx, in, len); 308 + } 309 + 310 + static inline void git_hash_final(unsigned char *hash, struct git_hash_ctx *ctx) 311 + { 312 + ctx->algop->final_fn(hash, ctx); 313 + } 314 + 315 + static inline void git_hash_final_oid(struct object_id *oid, struct git_hash_ctx *ctx) 316 + { 317 + ctx->algop->final_oid_fn(oid, ctx); 318 + } 298 319 299 320 /* 300 321 * Return a GIT_HASH_* constant based on the name. Returns GIT_HASH_UNKNOWN if
+3 -3
http-push.c
··· 760 760 static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed) 761 761 { 762 762 struct remote_lock *lock = (struct remote_lock *)ctx->userData; 763 - git_hash_ctx hash_ctx; 763 + struct git_hash_ctx hash_ctx; 764 764 unsigned char lock_token_hash[GIT_MAX_RAWSZ]; 765 765 766 766 if (tag_closed && ctx->cdata) { ··· 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;
+1 -1
http.h
··· 228 228 long http_code; 229 229 struct object_id oid; 230 230 struct object_id real_oid; 231 - git_hash_ctx c; 231 + struct git_hash_ctx c; 232 232 git_zstream stream; 233 233 int zret; 234 234 int rename;
+67 -63
object-file.c
··· 86 86 .algo = GIT_HASH_SHA256, 87 87 }; 88 88 89 - static void git_hash_sha1_init(git_hash_ctx *ctx) 89 + static void git_hash_sha1_init(struct git_hash_ctx *ctx) 90 90 { 91 - git_SHA1_Init(&ctx->sha1); 91 + ctx->algop = &hash_algos[GIT_HASH_SHA1]; 92 + git_SHA1_Init(&ctx->state.sha1); 92 93 } 93 94 94 - static void git_hash_sha1_clone(git_hash_ctx *dst, const git_hash_ctx *src) 95 + static void git_hash_sha1_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src) 95 96 { 96 - git_SHA1_Clone(&dst->sha1, &src->sha1); 97 + dst->algop = src->algop; 98 + git_SHA1_Clone(&dst->state.sha1, &src->state.sha1); 97 99 } 98 100 99 - static void git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len) 101 + static void git_hash_sha1_update(struct git_hash_ctx *ctx, const void *data, size_t len) 100 102 { 101 - git_SHA1_Update(&ctx->sha1, data, len); 103 + git_SHA1_Update(&ctx->state.sha1, data, len); 102 104 } 103 105 104 - static void git_hash_sha1_final(unsigned char *hash, git_hash_ctx *ctx) 106 + static void git_hash_sha1_final(unsigned char *hash, struct git_hash_ctx *ctx) 105 107 { 106 - git_SHA1_Final(hash, &ctx->sha1); 108 + git_SHA1_Final(hash, &ctx->state.sha1); 107 109 } 108 110 109 - static void git_hash_sha1_final_oid(struct object_id *oid, git_hash_ctx *ctx) 111 + static void git_hash_sha1_final_oid(struct object_id *oid, struct git_hash_ctx *ctx) 110 112 { 111 - git_SHA1_Final(oid->hash, &ctx->sha1); 113 + git_SHA1_Final(oid->hash, &ctx->state.sha1); 112 114 memset(oid->hash + GIT_SHA1_RAWSZ, 0, GIT_MAX_RAWSZ - GIT_SHA1_RAWSZ); 113 115 oid->algo = GIT_HASH_SHA1; 114 116 } 115 117 116 - static void git_hash_sha1_init_unsafe(git_hash_ctx *ctx) 118 + static void git_hash_sha1_init_unsafe(struct git_hash_ctx *ctx) 117 119 { 118 - git_SHA1_Init_unsafe(&ctx->sha1_unsafe); 120 + ctx->algop = unsafe_hash_algo(&hash_algos[GIT_HASH_SHA1]); 121 + git_SHA1_Init_unsafe(&ctx->state.sha1_unsafe); 119 122 } 120 123 121 - static void git_hash_sha1_clone_unsafe(git_hash_ctx *dst, const git_hash_ctx *src) 124 + static void git_hash_sha1_clone_unsafe(struct git_hash_ctx *dst, const struct git_hash_ctx *src) 122 125 { 123 - git_SHA1_Clone_unsafe(&dst->sha1_unsafe, &src->sha1_unsafe); 126 + dst->algop = src->algop; 127 + git_SHA1_Clone_unsafe(&dst->state.sha1_unsafe, &src->state.sha1_unsafe); 124 128 } 125 129 126 - static void git_hash_sha1_update_unsafe(git_hash_ctx *ctx, const void *data, 130 + static void git_hash_sha1_update_unsafe(struct git_hash_ctx *ctx, const void *data, 127 131 size_t len) 128 132 { 129 - git_SHA1_Update_unsafe(&ctx->sha1_unsafe, data, len); 133 + git_SHA1_Update_unsafe(&ctx->state.sha1_unsafe, data, len); 130 134 } 131 135 132 - static void git_hash_sha1_final_unsafe(unsigned char *hash, git_hash_ctx *ctx) 136 + static void git_hash_sha1_final_unsafe(unsigned char *hash, struct git_hash_ctx *ctx) 133 137 { 134 - git_SHA1_Final_unsafe(hash, &ctx->sha1_unsafe); 138 + git_SHA1_Final_unsafe(hash, &ctx->state.sha1_unsafe); 135 139 } 136 140 137 - static void git_hash_sha1_final_oid_unsafe(struct object_id *oid, git_hash_ctx *ctx) 141 + static void git_hash_sha1_final_oid_unsafe(struct object_id *oid, struct git_hash_ctx *ctx) 138 142 { 139 - git_SHA1_Final_unsafe(oid->hash, &ctx->sha1_unsafe); 143 + git_SHA1_Final_unsafe(oid->hash, &ctx->state.sha1_unsafe); 140 144 memset(oid->hash + GIT_SHA1_RAWSZ, 0, GIT_MAX_RAWSZ - GIT_SHA1_RAWSZ); 141 145 oid->algo = GIT_HASH_SHA1; 142 146 } 143 147 144 - static void git_hash_sha256_init(git_hash_ctx *ctx) 148 + static void git_hash_sha256_init(struct git_hash_ctx *ctx) 145 149 { 146 - git_SHA256_Init(&ctx->sha256); 150 + ctx->algop = unsafe_hash_algo(&hash_algos[GIT_HASH_SHA256]); 151 + git_SHA256_Init(&ctx->state.sha256); 147 152 } 148 153 149 - static void git_hash_sha256_clone(git_hash_ctx *dst, const git_hash_ctx *src) 154 + static void git_hash_sha256_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src) 150 155 { 151 - git_SHA256_Clone(&dst->sha256, &src->sha256); 156 + dst->algop = src->algop; 157 + git_SHA256_Clone(&dst->state.sha256, &src->state.sha256); 152 158 } 153 159 154 - static void git_hash_sha256_update(git_hash_ctx *ctx, const void *data, size_t len) 160 + static void git_hash_sha256_update(struct git_hash_ctx *ctx, const void *data, size_t len) 155 161 { 156 - git_SHA256_Update(&ctx->sha256, data, len); 162 + git_SHA256_Update(&ctx->state.sha256, data, len); 157 163 } 158 164 159 - static void git_hash_sha256_final(unsigned char *hash, git_hash_ctx *ctx) 165 + static void git_hash_sha256_final(unsigned char *hash, struct git_hash_ctx *ctx) 160 166 { 161 - git_SHA256_Final(hash, &ctx->sha256); 167 + git_SHA256_Final(hash, &ctx->state.sha256); 162 168 } 163 169 164 - static void git_hash_sha256_final_oid(struct object_id *oid, git_hash_ctx *ctx) 170 + static void git_hash_sha256_final_oid(struct object_id *oid, struct git_hash_ctx *ctx) 165 171 { 166 - git_SHA256_Final(oid->hash, &ctx->sha256); 172 + git_SHA256_Final(oid->hash, &ctx->state.sha256); 167 173 /* 168 174 * This currently does nothing, so the compiler should optimize it out, 169 175 * but keep it in case we extend the hash size again. ··· 172 178 oid->algo = GIT_HASH_SHA256; 173 179 } 174 180 175 - static void git_hash_unknown_init(git_hash_ctx *ctx UNUSED) 181 + static void git_hash_unknown_init(struct git_hash_ctx *ctx UNUSED) 176 182 { 177 183 BUG("trying to init unknown hash"); 178 184 } 179 185 180 - static void git_hash_unknown_clone(git_hash_ctx *dst UNUSED, 181 - const git_hash_ctx *src UNUSED) 186 + static void git_hash_unknown_clone(struct git_hash_ctx *dst UNUSED, 187 + const struct git_hash_ctx *src UNUSED) 182 188 { 183 189 BUG("trying to clone unknown hash"); 184 190 } 185 191 186 - static void git_hash_unknown_update(git_hash_ctx *ctx UNUSED, 192 + static void git_hash_unknown_update(struct git_hash_ctx *ctx UNUSED, 187 193 const void *data UNUSED, 188 194 size_t len UNUSED) 189 195 { ··· 191 197 } 192 198 193 199 static void git_hash_unknown_final(unsigned char *hash UNUSED, 194 - git_hash_ctx *ctx UNUSED) 200 + struct git_hash_ctx *ctx UNUSED) 195 201 { 196 202 BUG("trying to finalize unknown hash"); 197 203 } 198 204 199 205 static void git_hash_unknown_final_oid(struct object_id *oid UNUSED, 200 - git_hash_ctx *ctx UNUSED) 206 + struct git_hash_ctx *ctx UNUSED) 201 207 { 202 208 BUG("trying to finalize unknown hash"); 203 209 } ··· 1180 1186 unsigned long size; 1181 1187 enum object_type obj_type; 1182 1188 struct git_istream *st; 1183 - git_hash_ctx c; 1189 + struct git_hash_ctx c; 1184 1190 char hdr[MAX_HEADER_LEN]; 1185 1191 int hdrlen; 1186 1192 ··· 1193 1199 1194 1200 /* Sha1.. */ 1195 1201 r->hash_algo->init_fn(&c); 1196 - r->hash_algo->update_fn(&c, hdr, hdrlen); 1202 + git_hash_update(&c, hdr, hdrlen); 1197 1203 for (;;) { 1198 1204 char buf[1024 * 16]; 1199 1205 ssize_t readlen = read_istream(st, buf, sizeof(buf)); ··· 1204 1210 } 1205 1211 if (!readlen) 1206 1212 break; 1207 - r->hash_algo->update_fn(&c, buf, readlen); 1213 + git_hash_update(&c, buf, readlen); 1208 1214 } 1209 - r->hash_algo->final_oid_fn(&real_oid, &c); 1215 + git_hash_final_oid(&real_oid, &c); 1210 1216 close_istream(st); 1211 1217 return !oideq(oid, &real_oid) ? -1 : 0; 1212 1218 } ··· 1945 1951 } 1946 1952 } 1947 1953 1948 - static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c, 1954 + static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_ctx *c, 1949 1955 const void *buf, unsigned long len, 1950 1956 struct object_id *oid, 1951 1957 char *hdr, int *hdrlen) 1952 1958 { 1953 1959 algo->init_fn(c); 1954 - algo->update_fn(c, hdr, *hdrlen); 1955 - algo->update_fn(c, buf, len); 1956 - 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); 1957 1963 } 1958 1964 1959 1965 static void write_object_file_prepare(const struct git_hash_algo *algo, ··· 1961 1967 enum object_type type, struct object_id *oid, 1962 1968 char *hdr, int *hdrlen) 1963 1969 { 1964 - git_hash_ctx c; 1970 + struct git_hash_ctx c; 1965 1971 1966 1972 /* Generate the header */ 1967 1973 *hdrlen = format_object_header(hdr, *hdrlen, type, len); ··· 1975 1981 const char *type, struct object_id *oid, 1976 1982 char *hdr, int *hdrlen) 1977 1983 { 1978 - git_hash_ctx c; 1984 + struct git_hash_ctx c; 1979 1985 1980 1986 *hdrlen = format_object_header_literally(hdr, *hdrlen, type, len); 1981 1987 hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen); ··· 2206 2212 const char *filename, unsigned flags, 2207 2213 git_zstream *stream, 2208 2214 unsigned char *buf, size_t buflen, 2209 - git_hash_ctx *c, git_hash_ctx *compat_c, 2215 + struct git_hash_ctx *c, struct git_hash_ctx *compat_c, 2210 2216 char *hdr, int hdrlen) 2211 2217 { 2212 2218 struct repository *repo = the_repository; ··· 2240 2246 stream->avail_in = hdrlen; 2241 2247 while (git_deflate(stream, 0) == Z_OK) 2242 2248 ; /* nothing */ 2243 - algo->update_fn(c, hdr, hdrlen); 2249 + git_hash_update(c, hdr, hdrlen); 2244 2250 if (compat && compat_c) 2245 - compat->update_fn(compat_c, hdr, hdrlen); 2251 + git_hash_update(compat_c, hdr, hdrlen); 2246 2252 2247 2253 return fd; 2248 2254 } ··· 2251 2257 * Common steps for the inner git_deflate() loop for writing loose 2252 2258 * objects. Returns what git_deflate() returns. 2253 2259 */ 2254 - static int write_loose_object_common(git_hash_ctx *c, git_hash_ctx *compat_c, 2260 + static int write_loose_object_common(struct git_hash_ctx *c, struct git_hash_ctx *compat_c, 2255 2261 git_zstream *stream, const int flush, 2256 2262 unsigned char *in0, const int fd, 2257 2263 unsigned char *compressed, 2258 2264 const size_t compressed_len) 2259 2265 { 2260 2266 struct repository *repo = the_repository; 2261 - const struct git_hash_algo *algo = repo->hash_algo; 2262 2267 const struct git_hash_algo *compat = repo->compat_hash_algo; 2263 2268 int ret; 2264 2269 2265 2270 ret = git_deflate(stream, flush ? Z_FINISH : 0); 2266 - algo->update_fn(c, in0, stream->next_in - in0); 2271 + git_hash_update(c, in0, stream->next_in - in0); 2267 2272 if (compat && compat_c) 2268 - compat->update_fn(compat_c, in0, stream->next_in - in0); 2273 + git_hash_update(compat_c, in0, stream->next_in - in0); 2269 2274 if (write_in_full(fd, compressed, stream->next_out - compressed) < 0) 2270 2275 die_errno(_("unable to write loose object file")); 2271 2276 stream->next_out = compressed; ··· 2280 2285 * - End the compression of zlib stream. 2281 2286 * - Get the calculated oid to "oid". 2282 2287 */ 2283 - static int end_loose_object_common(git_hash_ctx *c, git_hash_ctx *compat_c, 2288 + static int end_loose_object_common(struct git_hash_ctx *c, struct git_hash_ctx *compat_c, 2284 2289 git_zstream *stream, struct object_id *oid, 2285 2290 struct object_id *compat_oid) 2286 2291 { 2287 2292 struct repository *repo = the_repository; 2288 - const struct git_hash_algo *algo = repo->hash_algo; 2289 2293 const struct git_hash_algo *compat = repo->compat_hash_algo; 2290 2294 int ret; 2291 2295 2292 2296 ret = git_deflate_end_gently(stream); 2293 2297 if (ret != Z_OK) 2294 2298 return ret; 2295 - algo->final_oid_fn(oid, c); 2299 + git_hash_final_oid(oid, c); 2296 2300 if (compat && compat_c) 2297 - compat->final_oid_fn(compat_oid, compat_c); 2301 + git_hash_final_oid(compat_oid, compat_c); 2298 2302 2299 2303 return Z_OK; 2300 2304 } ··· 2306 2310 int fd, ret; 2307 2311 unsigned char compressed[4096]; 2308 2312 git_zstream stream; 2309 - git_hash_ctx c; 2313 + struct git_hash_ctx c; 2310 2314 struct object_id parano_oid; 2311 2315 static struct strbuf tmp_file = STRBUF_INIT; 2312 2316 static struct strbuf filename = STRBUF_INIT; ··· 2386 2390 int fd, ret, err = 0, flush = 0; 2387 2391 unsigned char compressed[4096]; 2388 2392 git_zstream stream; 2389 - git_hash_ctx c, compat_c; 2393 + struct git_hash_ctx c, compat_c; 2390 2394 struct strbuf tmp_file = STRBUF_INIT; 2391 2395 struct strbuf filename = STRBUF_INIT; 2392 2396 int dirlen; ··· 3046 3050 const char *path, 3047 3051 const struct object_id *expected_oid) 3048 3052 { 3049 - git_hash_ctx c; 3053 + struct git_hash_ctx c; 3050 3054 struct object_id real_oid; 3051 3055 unsigned char buf[4096]; 3052 3056 unsigned long total_read; 3053 3057 int status = Z_OK; 3054 3058 3055 3059 the_hash_algo->init_fn(&c); 3056 - the_hash_algo->update_fn(&c, hdr, stream->total_out); 3060 + git_hash_update(&c, hdr, stream->total_out); 3057 3061 3058 3062 /* 3059 3063 * We already read some bytes into hdr, but the ones up to the NUL ··· 3073 3077 if (size - total_read < stream->avail_out) 3074 3078 stream->avail_out = size - total_read; 3075 3079 status = git_inflate(stream, Z_FINISH); 3076 - the_hash_algo->update_fn(&c, buf, stream->next_out - buf); 3080 + git_hash_update(&c, buf, stream->next_out - buf); 3077 3081 total_read += stream->next_out - buf; 3078 3082 } 3079 3083 git_inflate_end(stream); ··· 3088 3092 return -1; 3089 3093 } 3090 3094 3091 - the_hash_algo->final_oid_fn(&real_oid, &c); 3095 + git_hash_final_oid(&real_oid, &c); 3092 3096 if (!oideq(expected_oid, &real_oid)) { 3093 3097 error(_("hash mismatch for %s (expected %s)"), path, 3094 3098 oid_to_hex(expected_oid));
+3 -3
pack-check.c
··· 58 58 { 59 59 off_t index_size = p->index_size; 60 60 const unsigned char *index_base = p->index_data; 61 - git_hash_ctx ctx; 61 + struct git_hash_ctx ctx; 62 62 unsigned char hash[GIT_MAX_RAWSZ], *pack_sig; 63 63 off_t offset = 0, pack_sig_ofs = 0; 64 64 uint32_t nr_objects, i; ··· 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",
+10 -9
pack-write.c
··· 395 395 off_t partial_pack_offset) 396 396 { 397 397 int aligned_sz, buf_sz = 8 * 1024; 398 - git_hash_ctx old_hash_ctx, new_hash_ctx; 398 + struct git_hash_ctx old_hash_ctx, new_hash_ctx; 399 399 struct pack_header hdr; 400 400 char *buf; 401 401 ssize_t read_result; ··· 413 413 pack_name); 414 414 if (lseek(pack_fd, 0, SEEK_SET) != 0) 415 415 die_errno("Failed seeking to start of '%s'", pack_name); 416 - hash_algo->update_fn(&old_hash_ctx, &hdr, sizeof(hdr)); 416 + git_hash_update(&old_hash_ctx, &hdr, sizeof(hdr)); 417 417 hdr.hdr_entries = htonl(object_count); 418 - hash_algo->update_fn(&new_hash_ctx, &hdr, sizeof(hdr)); 418 + git_hash_update(&new_hash_ctx, &hdr, sizeof(hdr)); 419 419 write_or_die(pack_fd, &hdr, sizeof(hdr)); 420 420 partial_pack_offset -= sizeof(hdr); 421 421 ··· 430 430 break; 431 431 if (n < 0) 432 432 die_errno("Failed to checksum '%s'", pack_name); 433 - hash_algo->update_fn(&new_hash_ctx, buf, n); 433 + git_hash_update(&new_hash_ctx, buf, n); 434 434 435 435 aligned_sz -= n; 436 436 if (!aligned_sz) ··· 439 439 if (!partial_pack_hash) 440 440 continue; 441 441 442 - hash_algo->update_fn(&old_hash_ctx, buf, n); 442 + git_hash_update(&old_hash_ctx, buf, n); 443 443 partial_pack_offset -= n; 444 444 if (partial_pack_offset == 0) { 445 445 unsigned char hash[GIT_MAX_RAWSZ]; 446 - hash_algo->final_fn(hash, &old_hash_ctx); 447 - if (!hasheq(hash, partial_pack_hash, hash_algo)) 446 + git_hash_final(hash, &old_hash_ctx); 447 + if (!hasheq(hash, partial_pack_hash, 448 + hash_algo)) 448 449 die("Unexpected checksum for %s " 449 450 "(disk corruption?)", pack_name); 450 451 /* ··· 460 461 free(buf); 461 462 462 463 if (partial_pack_hash) 463 - hash_algo->final_fn(partial_pack_hash, &old_hash_ctx); 464 - hash_algo->final_fn(new_pack_hash, &new_hash_ctx); 464 + git_hash_final(partial_pack_hash, &old_hash_ctx); 465 + git_hash_final(new_pack_hash, &new_hash_ctx); 465 466 write_or_die(pack_fd, new_pack_hash, hash_algo->rawsz); 466 467 fsync_component_or_die(FSYNC_COMPONENT_PACK, pack_fd, pack_name); 467 468 }
+13 -13
read-cache.c
··· 1717 1717 1718 1718 static int verify_hdr(const struct cache_header *hdr, unsigned long size) 1719 1719 { 1720 - git_hash_ctx c; 1720 + struct git_hash_ctx c; 1721 1721 unsigned char hash[GIT_MAX_RAWSZ]; 1722 1722 int hdr_version; 1723 1723 unsigned char *start, *end; ··· 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; ··· 2002 2002 static void write_ieot_extension(struct strbuf *sb, struct index_entry_offset_table *ieot); 2003 2003 2004 2004 static size_t read_eoie_extension(const char *mmap, size_t mmap_size); 2005 - static void write_eoie_extension(struct strbuf *sb, git_hash_ctx *eoie_context, size_t offset); 2005 + static void write_eoie_extension(struct strbuf *sb, struct git_hash_ctx *eoie_context, size_t offset); 2006 2006 2007 2007 struct load_index_extensions 2008 2008 { ··· 2566 2566 } 2567 2567 2568 2568 static int write_index_ext_header(struct hashfile *f, 2569 - git_hash_ctx *eoie_f, 2569 + struct git_hash_ctx *eoie_f, 2570 2570 unsigned int ext, 2571 2571 unsigned int sz) 2572 2572 { ··· 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 } ··· 2831 2831 { 2832 2832 uint64_t start = getnanotime(); 2833 2833 struct hashfile *f; 2834 - git_hash_ctx *eoie_c = NULL; 2834 + struct git_hash_ctx *eoie_c = NULL; 2835 2835 struct cache_header hdr; 2836 2836 int i, err = 0, removed, extended, hdr_version; 2837 2837 struct cache_entry **cache = istate->cache; ··· 3579 3579 uint32_t extsize; 3580 3580 size_t offset, src_offset; 3581 3581 unsigned char hash[GIT_MAX_RAWSZ]; 3582 - git_hash_ctx c; 3582 + struct git_hash_ctx c; 3583 3583 3584 3584 /* ensure we have an index big enough to contain an EOIE extension */ 3585 3585 if (mmap_size < sizeof(struct cache_header) + EOIE_SIZE_WITH_HEADER + the_hash_algo->rawsz) ··· 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 ··· 3650 3650 return offset; 3651 3651 } 3652 3652 3653 - static void write_eoie_extension(struct strbuf *sb, git_hash_ctx *eoie_context, size_t offset) 3653 + static void write_eoie_extension(struct strbuf *sb, struct git_hash_ctx *eoie_context, size_t offset) 3654 3654 { 3655 3655 uint32_t buffer; 3656 3656 unsigned char hash[GIT_MAX_RAWSZ]; ··· 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
+9 -9
rerere.c
··· 358 358 } 359 359 360 360 static int handle_conflict(struct strbuf *out, struct rerere_io *io, 361 - int marker_size, git_hash_ctx *ctx) 361 + int marker_size, struct git_hash_ctx *ctx) 362 362 { 363 363 enum { 364 364 RR_SIDE_1 = 0, RR_SIDE_2, RR_ORIGINAL ··· 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) ··· 432 432 */ 433 433 static int handle_path(unsigned char *hash, struct rerere_io *io, int marker_size) 434 434 { 435 - git_hash_ctx ctx; 435 + struct git_hash_ctx ctx; 436 436 struct strbuf buf = STRBUF_INIT, out = STRBUF_INIT; 437 437 int has_conflicts = 0; 438 438 if (hash) ··· 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 }
+4 -4
t/helper/test-hash-speed.c
··· 3 3 4 4 #define NUM_SECONDS 3 5 5 6 - static inline void compute_hash(const struct git_hash_algo *algo, git_hash_ctx *ctx, uint8_t *final, const void *p, size_t len) 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) 14 14 { 15 - git_hash_ctx ctx; 15 + struct git_hash_ctx ctx; 16 16 unsigned char hash[GIT_MAX_RAWSZ]; 17 17 clock_t initial, start, end; 18 18 unsigned bufsizes[] = { 64, 256, 1024, 8192, 16384 };
+3 -3
t/helper/test-hash.c
··· 3 3 4 4 int cmd_hash_impl(int ac, const char **av, int algo, int unsafe) 5 5 { 6 - git_hash_ctx ctx; 6 + struct git_hash_ctx ctx; 7 7 unsigned char hash[GIT_MAX_HEXSZ]; 8 8 unsigned bufsz = 8192; 9 9 int binary = 0; ··· 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);
+3 -3
t/unit-tests/u-hash.c
··· 8 8 cl_assert(data != NULL); 9 9 10 10 for (size_t i = 1; i < ARRAY_SIZE(hash_algos); i++) { 11 - git_hash_ctx ctx; 11 + struct git_hash_ctx ctx; 12 12 unsigned char hash[GIT_MAX_HEXSZ]; 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 }
+3 -3
trace2/tr2_sid.c
··· 32 32 { 33 33 const struct git_hash_algo *algo = &hash_algos[GIT_HASH_SHA1]; 34 34 struct tr2_tbuf tb_now; 35 - git_hash_ctx ctx; 35 + struct git_hash_ctx ctx; 36 36 pid_t pid = getpid(); 37 37 unsigned char hash[GIT_MAX_RAWSZ + 1]; 38 38 char hex[GIT_MAX_HEXSZ + 1]; ··· 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);