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>
Patrick Steinhardt committed
Jan 31, 2025 at 13:55 UTC
0578f1e66aa381356bfe2f53decf3864d88d23d3
19 files changed
+103
-107
builtin/fast-import.c
+6
-6
@@ -959,9 +959,9 @@ static int store_object(
959
hdrlen = format_object_header((char *)hdr, sizeof(hdr), type,
960
dat->len);
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
if (oidout)
966
oidcpy(oidout, &oid);
967
@@ -1113,7 +1113,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
1113
hdrlen = format_object_header((char *)out_buf, out_sz, OBJ_BLOB, len);
1114
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
1118
crc32_begin(pack_file);
1119
@@ -1131,7 +1131,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
1131
if (!n && feof(stdin))
1132
die("EOF in data (%" PRIuMAX " bytes remaining)", len);
1133
1134
- the_hash_algo->update_fn(&c, in_buf, n);
1134
+ git_hash_update(&c, in_buf, n);
1135
s.next_in = in_buf;
1136
s.avail_in = n;
1137
len -= n;
@@ -1157,7 +1157,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
1157
}
1158
}
1159
git_deflate_end(&s);
1160
- the_hash_algo->final_oid_fn(&oid, &c);
1160
+ git_hash_final_oid(&oid, &c);
1161
1162
if (oidout)
1163
oidcpy(oidout, &oid);
builtin/index-pack.c
+6
-7
@@ -301,7 +301,7 @@ static void flush(void)
301
if (input_offset) {
302
if (output_fd >= 0)
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
memmove(input_buffer, input_buffer + input_offset, input_len);
306
input_offset = 0;
307
}
@@ -482,7 +482,7 @@ static void *unpack_entry_data(off_t offset, unsigned long size,
482
if (!is_delta_type(type)) {
483
hdrlen = format_object_header(hdr, sizeof(hdr), type, size);
484
the_hash_algo->init_fn(&c);
485
- the_hash_algo->update_fn(&c, hdr, hdrlen);
485
+ git_hash_update(&c, hdr, hdrlen);
486
} else
487
oid = NULL;
488
if (type == OBJ_BLOB && size > big_file_threshold)
@@ -502,7 +502,7 @@ static void *unpack_entry_data(off_t offset, unsigned long size,
502
status = git_inflate(&stream, 0);
503
use(input_len - stream.avail_in);
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
if (buf == fixed_buf) {
507
stream.next_out = buf;
508
stream.avail_out = sizeof(fixed_buf);
@@ -512,7 +512,7 @@ static void *unpack_entry_data(off_t offset, unsigned long size,
512
bad_object(offset, _("inflate returned %d"), status);
513
git_inflate_end(&stream);
514
if (oid)
515
- the_hash_algo->final_oid_fn(oid, &c);
515
+ git_hash_final_oid(oid, &c);
516
return buf == fixed_buf ? NULL : buf;
517
}
518
@@ -1286,9 +1286,8 @@ static void parse_pack_objects(unsigned char *hash)
1286
1287
/* Check pack integrity */
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);
1291
if (!hasheq(fill(the_hash_algo->rawsz), hash, the_repository->hash_algo))
1292
die(_("pack is corrupted (SHA1 mismatch)"));
1293
use(the_hash_algo->rawsz);
builtin/patch-id.c
+6
-6
@@ -85,7 +85,7 @@ static size_t get_one_patchid(struct object_id *next_oid, struct object_id *resu
85
!skip_prefix(line, "From ", &p) &&
86
starts_with(line, "\\ ") && 12 < strlen(line)) {
87
if (verbatim)
88
- the_hash_algo->update_fn(&ctx, line, strlen(line));
88
+ git_hash_update(&ctx, line, strlen(line));
89
continue;
90
}
91
@@ -104,10 +104,10 @@ static size_t get_one_patchid(struct object_id *next_oid, struct object_id *resu
104
starts_with(line, "Binary files")) {
105
diff_is_binary = 1;
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
if (stable)
112
flush_one_hunk(result, &ctx);
113
continue;
@@ -165,7 +165,7 @@ static size_t get_one_patchid(struct object_id *next_oid, struct object_id *resu
165
/* Add line to hash algo (possibly removing whitespace) */
166
len = verbatim ? strlen(line) : remove_space(line);
167
patchlen += len;
168
- the_hash_algo->update_fn(&ctx, line, len);
168
+ git_hash_update(&ctx, line, len);
169
}
170
171
if (!found_next)
builtin/receive-pack.c
+8
-8
@@ -572,8 +572,8 @@ static void hmac_hash(unsigned char *out,
572
memset(key, '\0', GIT_MAX_BLKSZ);
573
if (the_hash_algo->blksz < key_len) {
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
} else {
578
memcpy(key, key_in, key_len);
579
}
@@ -586,15 +586,15 @@ static void hmac_hash(unsigned char *out,
586
587
/* RFC 2104 2. (3) & (4) */
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
593
/* RFC 2104 2. (6) & (7) */
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
}
599
600
static char *prepare_push_cert_nonce(const char *path, timestamp_t stamp)
builtin/unpack-objects.c
+4
-5
@@ -70,7 +70,7 @@ static void *fill(int min)
70
if (min > sizeof(buffer))
71
die("cannot fill %d bytes", min);
72
if (offset) {
73
- the_hash_algo->update_fn(&ctx, buffer, offset);
73
+ git_hash_update(&ctx, buffer, offset);
74
memmove(buffer, buffer + offset, len);
75
offset = 0;
76
}
@@ -667,10 +667,9 @@ int cmd_unpack_objects(int argc,
667
}
668
the_hash_algo->init_fn(&ctx);
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);
673
if (strict) {
674
write_rest();
675
if (fsck_finish(&fsck_options))
bulk-checkin.c
+3
-3
@@ -194,7 +194,7 @@ static int stream_blob_to_pack(struct bulk_checkin_packfile *state,
194
if (rsize < hsize)
195
hsize = rsize;
196
if (hsize)
197
- the_hash_algo->update_fn(ctx, ibuf, hsize);
197
+ git_hash_update(ctx, ibuf, hsize);
198
*already_hashed_to = offset;
199
}
200
s.next_in = ibuf;
@@ -271,7 +271,7 @@ static int deflate_blob_to_pack(struct bulk_checkin_packfile *state,
271
header_len = format_object_header((char *)obuf, sizeof(obuf),
272
OBJ_BLOB, size);
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
276
/* Note: idx is non-NULL when we are writing */
277
if ((flags & HASH_WRITE_OBJECT) != 0) {
@@ -306,7 +306,7 @@ static int deflate_blob_to_pack(struct bulk_checkin_packfile *state,
306
if (lseek(fd, seekback, SEEK_SET) == (off_t) -1)
307
return error("cannot seek back");
308
}
309
- the_hash_algo->final_oid_fn(result_oid, &ctx);
309
+ git_hash_final_oid(result_oid, &ctx);
310
if (!idx)
311
return 0;
312
csum-file.c
+7
-7
@@ -50,7 +50,7 @@ void hashflush(struct hashfile *f)
50
51
if (offset) {
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
flush(f, f->buffer, offset);
55
f->offset = 0;
56
}
@@ -73,7 +73,7 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result,
73
if (f->skip_hash)
74
hashclr(f->buffer, f->algop);
75
else
76
- f->algop->final_fn(f->buffer, &f->ctx);
76
+ git_hash_final(f->buffer, &f->ctx);
77
78
if (result)
79
hashcpy(result, f->buffer, f->algop);
@@ -128,7 +128,7 @@ void hashwrite(struct hashfile *f, const void *buf, unsigned int count)
128
* f->offset is necessarily zero.
129
*/
130
if (!f->skip_hash)
131
- f->algop->update_fn(&f->ctx, buf, nr);
131
+ git_hash_update(&f->ctx, buf, nr);
132
flush(f, buf, nr);
133
} else {
134
/*
@@ -217,7 +217,7 @@ void hashfile_checkpoint(struct hashfile *f, struct hashfile_checkpoint *checkpo
217
{
218
hashflush(f);
219
checkpoint->offset = f->total;
220
- f->algop->clone_fn(&checkpoint->ctx, &f->ctx);
220
+ git_hash_clone(&checkpoint->ctx, &f->ctx);
221
}
222
223
int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint)
@@ -228,7 +228,7 @@ int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint
228
lseek(f->fd, offset, SEEK_SET) != offset)
229
return -1;
230
f->total = offset;
231
- f->algop->clone_fn(&f->ctx, &checkpoint->ctx);
231
+ git_hash_clone(&f->ctx, &checkpoint->ctx);
232
f->offset = 0; /* hashflush() was called in checkpoint */
233
return 0;
234
}
@@ -256,8 +256,8 @@ int hashfile_checksum_valid(const unsigned char *data, size_t total_len)
256
return 0; /* say "too short"? */
257
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
262
return hasheq(got, data + data_len, algop);
263
}
diff.c
+12
-12
@@ -6415,7 +6415,7 @@ void flush_one_hunk(struct object_id *result, struct git_hash_ctx *ctx)
6415
unsigned short carry = 0;
6416
int i;
6417
6418
- the_hash_algo->final_fn(hash, ctx);
6418
+ git_hash_final(hash, ctx);
6419
the_hash_algo->init_fn(ctx);
6420
/* 20-byte sum, with carry */
6421
for (i = 0; i < the_hash_algo->rawsz; ++i) {
@@ -6434,14 +6434,14 @@ static int patch_id_consume(void *priv, char *line, unsigned long len)
6434
return 0;
6435
new_len = remove_space(line, len);
6436
6437
- the_hash_algo->update_fn(data->ctx, line, new_len);
6437
+ git_hash_update(data->ctx, line, new_len);
6438
data->patchlen += new_len;
6439
return 0;
6440
}
6441
6442
static void patch_id_add_string(struct git_hash_ctx *ctx, const char *str)
6443
{
6444
- the_hash_algo->update_fn(ctx, str, strlen(str));
6444
+ git_hash_update(ctx, str, strlen(str));
6445
}
6446
6447
static void patch_id_add_mode(struct git_hash_ctx *ctx, unsigned mode)
@@ -6449,7 +6449,7 @@ static void patch_id_add_mode(struct git_hash_ctx *ctx, unsigned mode)
6449
/* large enough for 2^32 in octal */
6450
char buf[12];
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
}
6454
6455
/* returns 0 upon success, and writes result into oid */
@@ -6493,9 +6493,9 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
6493
len2 = remove_space(p->two->path, strlen(p->two->path));
6494
patch_id_add_string(&ctx, "diff--git");
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
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
6500
if (p->one->mode == 0) {
6501
patch_id_add_string(&ctx, "newfilemode");
@@ -6514,24 +6514,24 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
6514
/* don't do anything since we're only populating header info */
6515
} else if (diff_filespec_is_binary(options->repo, p->one) ||
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
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
the_hash_algo->hexsz);
6521
} else {
6522
if (p->one->mode == 0) {
6523
patch_id_add_string(&ctx, "---/dev/null");
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
} else if (p->two->mode == 0) {
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
patch_id_add_string(&ctx, "+++/dev/null");
6530
} else {
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
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
}
6536
6537
if (fill_mmfile(options->repo, &mf1, p->one) < 0 ||
http-push.c
+2
-2
@@ -774,8 +774,8 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
774
lock->token = xstrdup(ctx->cdata);
775
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
780
lock->tmpfile_suffix[0] = '_';
781
memcpy(lock->tmpfile_suffix + 1, hash_to_hex(lock_token_hash), the_hash_algo->hexsz);
http.c
+3
-3
@@ -2597,8 +2597,8 @@ static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb,
2597
freq->stream.next_out = expn;
2598
freq->stream.avail_out = sizeof(expn);
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
} while (freq->stream.avail_in && freq->zret == Z_OK);
2603
return nmemb;
2604
}
@@ -2763,7 +2763,7 @@ int finish_http_object_request(struct http_object_request *freq)
2763
return -1;
2764
}
2765
2766
- the_hash_algo->final_oid_fn(&freq->real_oid, &freq->c);
2766
+ git_hash_final_oid(&freq->real_oid, &freq->c);
2767
if (freq->zret != Z_STREAM_END) {
2768
unlink_or_warn(freq->tmpfile.buf);
2769
return -1;
object-file.c
+15
-17
@@ -1199,7 +1199,7 @@ int stream_object_signature(struct repository *r, const struct object_id *oid)
1199
1200
/* Sha1.. */
1201
r->hash_algo->init_fn(&c);
1202
- r->hash_algo->update_fn(&c, hdr, hdrlen);
1202
+ git_hash_update(&c, hdr, hdrlen);
1203
for (;;) {
1204
char buf[1024 * 16];
1205
ssize_t readlen = read_istream(st, buf, sizeof(buf));
@@ -1210,9 +1210,9 @@ int stream_object_signature(struct repository *r, const struct object_id *oid)
1210
}
1211
if (!readlen)
1212
break;
1213
- r->hash_algo->update_fn(&c, buf, readlen);
1213
+ git_hash_update(&c, buf, readlen);
1214
}
1215
- r->hash_algo->final_oid_fn(&real_oid, &c);
1215
+ git_hash_final_oid(&real_oid, &c);
1216
close_istream(st);
1217
return !oideq(oid, &real_oid) ? -1 : 0;
1218
}
@@ -1957,9 +1957,9 @@ static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_c
1957
char *hdr, int *hdrlen)
1958
{
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
}
1964
1965
static void write_object_file_prepare(const struct git_hash_algo *algo,
@@ -2246,9 +2246,9 @@ static int start_loose_object_common(struct strbuf *tmp_file,
2246
stream->avail_in = hdrlen;
2247
while (git_deflate(stream, 0) == Z_OK)
2248
; /* nothing */
2249
- algo->update_fn(c, hdr, hdrlen);
2249
+ git_hash_update(c, hdr, hdrlen);
2250
if (compat && compat_c)
2251
- compat->update_fn(compat_c, hdr, hdrlen);
2251
+ git_hash_update(compat_c, hdr, hdrlen);
2252
2253
return fd;
2254
}
@@ -2264,14 +2264,13 @@ static int write_loose_object_common(struct git_hash_ctx *c, struct git_hash_ctx
2264
const size_t compressed_len)
2265
{
2266
struct repository *repo = the_repository;
2267
- const struct git_hash_algo *algo = repo->hash_algo;
2267
const struct git_hash_algo *compat = repo->compat_hash_algo;
2268
int ret;
2269
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);
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);
2274
if (write_in_full(fd, compressed, stream->next_out - compressed) < 0)
2275
die_errno(_("unable to write loose object file"));
2276
stream->next_out = compressed;
@@ -2291,16 +2290,15 @@ static int end_loose_object_common(struct git_hash_ctx *c, struct git_hash_ctx *
2290
struct object_id *compat_oid)
2291
{
2292
struct repository *repo = the_repository;
2294
- const struct git_hash_algo *algo = repo->hash_algo;
2293
const struct git_hash_algo *compat = repo->compat_hash_algo;
2294
int ret;
2295
2296
ret = git_deflate_end_gently(stream);
2297
if (ret != Z_OK)
2298
return ret;
2301
- algo->final_oid_fn(oid, c);
2299
+ git_hash_final_oid(oid, c);
2300
if (compat && compat_c)
2303
- compat->final_oid_fn(compat_oid, compat_c);
2301
+ git_hash_final_oid(compat_oid, compat_c);
2302
2303
return Z_OK;
2304
}
@@ -3059,7 +3057,7 @@ static int check_stream_oid(git_zstream *stream,
3057
int status = Z_OK;
3058
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);
3061
3062
/*
3063
* We already read some bytes into hdr, but the ones up to the NUL
@@ -3079,7 +3077,7 @@ static int check_stream_oid(git_zstream *stream,
3077
if (size - total_read < stream->avail_out)
3078
stream->avail_out = size - total_read;
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);
3081
total_read += stream->next_out - buf;
3082
}
3083
git_inflate_end(stream);
@@ -3094,7 +3092,7 @@ static int check_stream_oid(git_zstream *stream,
3092
return -1;
3093
}
3094
3097
- the_hash_algo->final_oid_fn(&real_oid, &c);
3095
+ git_hash_final_oid(&real_oid, &c);
3096
if (!oideq(expected_oid, &real_oid)) {
3097
error(_("hash mismatch for %s (expected %s)"), path,
3098
oid_to_hex(expected_oid));
pack-check.c
+2
-2
@@ -77,9 +77,9 @@ static int verify_packfile(struct repository *r,
77
pack_sig_ofs = p->pack_size - r->hash_algo->rawsz;
78
if (offset > pack_sig_ofs)
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
} while (offset < pack_sig_ofs);
82
- r->hash_algo->final_fn(hash, &ctx);
82
+ git_hash_final(hash, &ctx);
83
pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);
84
if (!hasheq(hash, pack_sig, the_repository->hash_algo))
85
err = error("%s pack checksum mismatch",
pack-write.c
+7
-7
@@ -406,9 +406,9 @@ void fixup_pack_header_footer(int pack_fd,
406
pack_name);
407
if (lseek(pack_fd, 0, SEEK_SET) != 0)
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
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
write_or_die(pack_fd, &hdr, sizeof(hdr));
413
partial_pack_offset -= sizeof(hdr);
414
@@ -423,7 +423,7 @@ void fixup_pack_header_footer(int pack_fd,
423
break;
424
if (n < 0)
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
428
aligned_sz -= n;
429
if (!aligned_sz)
@@ -432,11 +432,11 @@ void fixup_pack_header_footer(int pack_fd,
432
if (!partial_pack_hash)
433
continue;
434
435
- the_hash_algo->update_fn(&old_hash_ctx, buf, n);
435
+ git_hash_update(&old_hash_ctx, buf, n);
436
partial_pack_offset -= n;
437
if (partial_pack_offset == 0) {
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
if (!hasheq(hash, partial_pack_hash,
441
the_repository->hash_algo))
442
die("Unexpected checksum for %s "
@@ -454,8 +454,8 @@ void fixup_pack_header_footer(int pack_fd,
454
free(buf);
455
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
write_or_die(pack_fd, new_pack_hash, the_hash_algo->rawsz);
460
fsync_component_or_die(FSYNC_COMPONENT_PACK, pack_fd, pack_name);
461
}
read-cache.c
+7
-7
@@ -1739,8 +1739,8 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size)
1739
return 0;
1740
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
if (!hasheq(hash, start, the_repository->hash_algo))
1745
return error(_("bad index file sha1 signature"));
1746
return 0;
@@ -2576,8 +2576,8 @@ static int write_index_ext_header(struct hashfile *f,
2576
if (eoie_f) {
2577
ext = htonl(ext);
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
}
2582
return 0;
2583
}
@@ -3634,12 +3634,12 @@ static size_t read_eoie_extension(const char *mmap, size_t mmap_size)
3634
if (src_offset + 8 + extsize < src_offset)
3635
return 0;
3636
3637
- the_hash_algo->update_fn(&c, mmap + src_offset, 8);
3637
+ git_hash_update(&c, mmap + src_offset, 8);
3638
3639
src_offset += 8;
3640
src_offset += extsize;
3641
}
3642
- the_hash_algo->final_fn(hash, &c);
3642
+ git_hash_final(hash, &c);
3643
if (!hasheq(hash, (const unsigned char *)index, the_repository->hash_algo))
3644
return 0;
3645
@@ -3660,7 +3660,7 @@ static void write_eoie_extension(struct strbuf *sb, struct git_hash_ctx *eoie_co
3660
strbuf_add(sb, &buffer, sizeof(uint32_t));
3661
3662
/* hash */
3663
- the_hash_algo->final_fn(hash, eoie_context);
3663
+ git_hash_final(hash, eoie_context);
3664
strbuf_add(sb, hash, the_hash_algo->rawsz);
3665
}
3666
rerere.c
+7
-7
@@ -396,12 +396,12 @@ static int handle_conflict(struct strbuf *out, struct rerere_io *io,
396
strbuf_addbuf(out, &two);
397
rerere_strbuf_putconflict(out, '>', marker_size);
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
}
406
break;
407
} else if (hunk == RR_SIDE_1)
@@ -453,7 +453,7 @@ static int handle_path(unsigned char *hash, struct rerere_io *io, int marker_siz
453
strbuf_release(&out);
454
455
if (hash)
456
- the_hash_algo->final_fn(hash, &ctx);
456
+ git_hash_final(hash, &ctx);
457
458
return has_conflicts;
459
}
t/helper/test-hash-speed.c
+2
-2
@@ -6,8 +6,8 @@
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
{
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
}
12
13
int cmd__hash_speed(int ac, const char **av)
t/helper/test-hash.c
+2
-2
@@ -48,9 +48,9 @@ int cmd_hash_impl(int ac, const char **av, int algo, int unsafe)
48
}
49
if (this_sz == 0)
50
break;
51
- algop->update_fn(&ctx, buffer, this_sz);
51
+ git_hash_update(&ctx, buffer, this_sz);
52
}
53
- algop->final_fn(hash, &ctx);
53
+ git_hash_final(hash, &ctx);
54
55
if (binary)
56
fwrite(hash, 1, algop->rawsz, stdout);
t/unit-tests/u-hash.c
+2
-2
@@ -13,8 +13,8 @@ static void check_hash_data(const void *data, size_t data_length,
13
const struct git_hash_algo *algop = &hash_algos[i];
14
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
19
cl_assert_equal_s(hash_to_hex_algop(hash,algop), expected_hashes[i - 1]);
20
}
trace2/tr2_sid.c
+2
-2
@@ -46,8 +46,8 @@ static void tr2_sid_append_my_sid_component(void)
46
strbuf_add(&tr2sid_buf, "Localhost", 9);
47
else {
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
hash_to_hex_algop_r(hex, hash, algo);
52
strbuf_addch(&tr2sid_buf, 'H');
53
strbuf_add(&tr2sid_buf, hex, 8);