]> git.ipfire.org Git - thirdparty/git.git/commitdiff
global: adapt callers to use generic hash context helpers
authorPatrick Steinhardt <ps@pks.im>
Fri, 31 Jan 2025 12:55:31 +0000 (13:55 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 31 Jan 2025 18:06:11 +0000 (10:06 -0800)
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>
19 files changed:
builtin/fast-import.c
builtin/index-pack.c
builtin/patch-id.c
builtin/receive-pack.c
builtin/unpack-objects.c
bulk-checkin.c
csum-file.c
diff.c
http-push.c
http.c
object-file.c
pack-check.c
pack-write.c
read-cache.c
rerere.c
t/helper/test-hash-speed.c
t/helper/test-hash.c
t/unit-tests/u-hash.c
trace2/tr2_sid.c

index 9862704c6252d1f373958cd3f60d89ee7e7e6eb7..91f88c467f9414b872dbb1282fa189ee7a822c42 100644 (file)
@@ -959,9 +959,9 @@ static int store_object(
        hdrlen = format_object_header((char *)hdr, sizeof(hdr), type,
                                      dat->len);
        the_hash_algo->init_fn(&c);
-       the_hash_algo->update_fn(&c, hdr, hdrlen);
-       the_hash_algo->update_fn(&c, dat->buf, dat->len);
-       the_hash_algo->final_oid_fn(&oid, &c);
+       git_hash_update(&c, hdr, hdrlen);
+       git_hash_update(&c, dat->buf, dat->len);
+       git_hash_final_oid(&oid, &c);
        if (oidout)
                oidcpy(oidout, &oid);
 
@@ -1113,7 +1113,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
        hdrlen = format_object_header((char *)out_buf, out_sz, OBJ_BLOB, len);
 
        the_hash_algo->init_fn(&c);
-       the_hash_algo->update_fn(&c, out_buf, hdrlen);
+       git_hash_update(&c, out_buf, hdrlen);
 
        crc32_begin(pack_file);
 
@@ -1131,7 +1131,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
                        if (!n && feof(stdin))
                                die("EOF in data (%" PRIuMAX " bytes remaining)", len);
 
-                       the_hash_algo->update_fn(&c, in_buf, n);
+                       git_hash_update(&c, in_buf, n);
                        s.next_in = in_buf;
                        s.avail_in = n;
                        len -= n;
@@ -1157,7 +1157,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
                }
        }
        git_deflate_end(&s);
-       the_hash_algo->final_oid_fn(&oid, &c);
+       git_hash_final_oid(&oid, &c);
 
        if (oidout)
                oidcpy(oidout, &oid);
index 40e49868b18866dc8ecb507acb491ac752418a7f..5ee13661a1e03b678d9d2fe2cac9510d4c1e4fd1 100644 (file)
@@ -301,7 +301,7 @@ static void flush(void)
        if (input_offset) {
                if (output_fd >= 0)
                        write_or_die(output_fd, input_buffer, input_offset);
-               the_hash_algo->update_fn(&input_ctx, input_buffer, input_offset);
+               git_hash_update(&input_ctx, input_buffer, input_offset);
                memmove(input_buffer, input_buffer + input_offset, input_len);
                input_offset = 0;
        }
@@ -482,7 +482,7 @@ static void *unpack_entry_data(off_t offset, unsigned long size,
        if (!is_delta_type(type)) {
                hdrlen = format_object_header(hdr, sizeof(hdr), type, size);
                the_hash_algo->init_fn(&c);
-               the_hash_algo->update_fn(&c, hdr, hdrlen);
+               git_hash_update(&c, hdr, hdrlen);
        } else
                oid = NULL;
        if (type == OBJ_BLOB && size > big_file_threshold)
@@ -502,7 +502,7 @@ static void *unpack_entry_data(off_t offset, unsigned long size,
                status = git_inflate(&stream, 0);
                use(input_len - stream.avail_in);
                if (oid)
-                       the_hash_algo->update_fn(&c, last_out, stream.next_out - last_out);
+                       git_hash_update(&c, last_out, stream.next_out - last_out);
                if (buf == fixed_buf) {
                        stream.next_out = buf;
                        stream.avail_out = sizeof(fixed_buf);
@@ -512,7 +512,7 @@ static void *unpack_entry_data(off_t offset, unsigned long size,
                bad_object(offset, _("inflate returned %d"), status);
        git_inflate_end(&stream);
        if (oid)
-               the_hash_algo->final_oid_fn(oid, &c);
+               git_hash_final_oid(oid, &c);
        return buf == fixed_buf ? NULL : buf;
 }
 
@@ -1286,9 +1286,8 @@ static void parse_pack_objects(unsigned char *hash)
 
        /* Check pack integrity */
        flush();
-       the_hash_algo->init_fn(&tmp_ctx);
-       the_hash_algo->clone_fn(&tmp_ctx, &input_ctx);
-       the_hash_algo->final_fn(hash, &tmp_ctx);
+       git_hash_clone(&tmp_ctx, &input_ctx);
+       git_hash_final(hash, &tmp_ctx);
        if (!hasheq(fill(the_hash_algo->rawsz), hash, the_repository->hash_algo))
                die(_("pack is corrupted (SHA1 mismatch)"));
        use(the_hash_algo->rawsz);
index 923ff2bb77d11f4d0998eff82e2040abb1432e89..cdef2ec10abcd595fc4c2425c4883a5188f526b5 100644 (file)
@@ -85,7 +85,7 @@ static size_t get_one_patchid(struct object_id *next_oid, struct object_id *resu
                    !skip_prefix(line, "From ", &p) &&
                    starts_with(line, "\\ ") && 12 < strlen(line)) {
                        if (verbatim)
-                               the_hash_algo->update_fn(&ctx, line, strlen(line));
+                               git_hash_update(&ctx, line, strlen(line));
                        continue;
                }
 
@@ -104,10 +104,10 @@ static size_t get_one_patchid(struct object_id *next_oid, struct object_id *resu
                            starts_with(line, "Binary files")) {
                                diff_is_binary = 1;
                                before = 0;
-                               the_hash_algo->update_fn(&ctx, pre_oid_str,
-                                                        strlen(pre_oid_str));
-                               the_hash_algo->update_fn(&ctx, post_oid_str,
-                                                        strlen(post_oid_str));
+                               git_hash_update(&ctx, pre_oid_str,
+                                               strlen(pre_oid_str));
+                               git_hash_update(&ctx, post_oid_str,
+                                               strlen(post_oid_str));
                                if (stable)
                                        flush_one_hunk(result, &ctx);
                                continue;
@@ -165,7 +165,7 @@ static size_t get_one_patchid(struct object_id *next_oid, struct object_id *resu
                /* Add line to hash algo (possibly removing whitespace) */
                len = verbatim ? strlen(line) : remove_space(line);
                patchlen += len;
-               the_hash_algo->update_fn(&ctx, line, len);
+               git_hash_update(&ctx, line, len);
        }
 
        if (!found_next)
index d2360c453cdcd0225df04ded4a1d00eee04adbbc..cc358600cacdd025393368de490acb227e8c2f9f 100644 (file)
@@ -572,8 +572,8 @@ static void hmac_hash(unsigned char *out,
        memset(key, '\0', GIT_MAX_BLKSZ);
        if (the_hash_algo->blksz < key_len) {
                the_hash_algo->init_fn(&ctx);
-               the_hash_algo->update_fn(&ctx, key_in, key_len);
-               the_hash_algo->final_fn(key, &ctx);
+               git_hash_update(&ctx, key_in, key_len);
+               git_hash_final(key, &ctx);
        } else {
                memcpy(key, key_in, key_len);
        }
@@ -586,15 +586,15 @@ static void hmac_hash(unsigned char *out,
 
        /* RFC 2104 2. (3) & (4) */
        the_hash_algo->init_fn(&ctx);
-       the_hash_algo->update_fn(&ctx, k_ipad, sizeof(k_ipad));
-       the_hash_algo->update_fn(&ctx, text, text_len);
-       the_hash_algo->final_fn(out, &ctx);
+       git_hash_update(&ctx, k_ipad, sizeof(k_ipad));
+       git_hash_update(&ctx, text, text_len);
+       git_hash_final(out, &ctx);
 
        /* RFC 2104 2. (6) & (7) */
        the_hash_algo->init_fn(&ctx);
-       the_hash_algo->update_fn(&ctx, k_opad, sizeof(k_opad));
-       the_hash_algo->update_fn(&ctx, out, the_hash_algo->rawsz);
-       the_hash_algo->final_fn(out, &ctx);
+       git_hash_update(&ctx, k_opad, sizeof(k_opad));
+       git_hash_update(&ctx, out, the_hash_algo->rawsz);
+       git_hash_final(out, &ctx);
 }
 
 static char *prepare_push_cert_nonce(const char *path, timestamp_t stamp)
index d72885510c3445e4f7c40a9ebe859a064f0dafb8..8383bcf404957d7e7641ffacc09b9679e6be2dbb 100644 (file)
@@ -70,7 +70,7 @@ static void *fill(int min)
        if (min > sizeof(buffer))
                die("cannot fill %d bytes", min);
        if (offset) {
-               the_hash_algo->update_fn(&ctx, buffer, offset);
+               git_hash_update(&ctx, buffer, offset);
                memmove(buffer, buffer + offset, len);
                offset = 0;
        }
@@ -667,10 +667,9 @@ int cmd_unpack_objects(int argc,
        }
        the_hash_algo->init_fn(&ctx);
        unpack_all();
-       the_hash_algo->update_fn(&ctx, buffer, offset);
-       the_hash_algo->init_fn(&tmp_ctx);
-       the_hash_algo->clone_fn(&tmp_ctx, &ctx);
-       the_hash_algo->final_oid_fn(&oid, &tmp_ctx);
+       git_hash_update(&ctx, buffer, offset);
+       git_hash_clone(&tmp_ctx, &ctx);
+       git_hash_final_oid(&oid, &tmp_ctx);
        if (strict) {
                write_rest();
                if (fsck_finish(&fsck_options))
index db1958b52590dd4ef83a13f7b6aedee6c075cd56..0f40c5dac9089b3ac4d0559c8d243ff327fd0c2f 100644 (file)
@@ -194,7 +194,7 @@ static int stream_blob_to_pack(struct bulk_checkin_packfile *state,
                                if (rsize < hsize)
                                        hsize = rsize;
                                if (hsize)
-                                       the_hash_algo->update_fn(ctx, ibuf, hsize);
+                                       git_hash_update(ctx, ibuf, hsize);
                                *already_hashed_to = offset;
                        }
                        s.next_in = ibuf;
@@ -271,7 +271,7 @@ static int deflate_blob_to_pack(struct bulk_checkin_packfile *state,
        header_len = format_object_header((char *)obuf, sizeof(obuf),
                                          OBJ_BLOB, size);
        the_hash_algo->init_fn(&ctx);
-       the_hash_algo->update_fn(&ctx, obuf, header_len);
+       git_hash_update(&ctx, obuf, header_len);
 
        /* Note: idx is non-NULL when we are writing */
        if ((flags & HASH_WRITE_OBJECT) != 0) {
@@ -306,7 +306,7 @@ static int deflate_blob_to_pack(struct bulk_checkin_packfile *state,
                if (lseek(fd, seekback, SEEK_SET) == (off_t) -1)
                        return error("cannot seek back");
        }
-       the_hash_algo->final_oid_fn(result_oid, &ctx);
+       git_hash_final_oid(result_oid, &ctx);
        if (!idx)
                return 0;
 
index 338351566995534884a5fa8e7e22c37665979e82..5c54b3a0b9db513ff1f036cda47f6b90f4d4c04c 100644 (file)
@@ -50,7 +50,7 @@ void hashflush(struct hashfile *f)
 
        if (offset) {
                if (!f->skip_hash)
-                       f->algop->update_fn(&f->ctx, f->buffer, offset);
+                       git_hash_update(&f->ctx, f->buffer, offset);
                flush(f, f->buffer, offset);
                f->offset = 0;
        }
@@ -73,7 +73,7 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result,
        if (f->skip_hash)
                hashclr(f->buffer, f->algop);
        else
-               f->algop->final_fn(f->buffer, &f->ctx);
+               git_hash_final(f->buffer, &f->ctx);
 
        if (result)
                hashcpy(result, f->buffer, f->algop);
@@ -128,7 +128,7 @@ void hashwrite(struct hashfile *f, const void *buf, unsigned int count)
                         * f->offset is necessarily zero.
                         */
                        if (!f->skip_hash)
-                               f->algop->update_fn(&f->ctx, buf, nr);
+                               git_hash_update(&f->ctx, buf, nr);
                        flush(f, buf, nr);
                } else {
                        /*
@@ -217,7 +217,7 @@ void hashfile_checkpoint(struct hashfile *f, struct hashfile_checkpoint *checkpo
 {
        hashflush(f);
        checkpoint->offset = f->total;
-       f->algop->clone_fn(&checkpoint->ctx, &f->ctx);
+       git_hash_clone(&checkpoint->ctx, &f->ctx);
 }
 
 int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint)
@@ -228,7 +228,7 @@ int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint
            lseek(f->fd, offset, SEEK_SET) != offset)
                return -1;
        f->total = offset;
-       f->algop->clone_fn(&f->ctx, &checkpoint->ctx);
+       git_hash_clone(&f->ctx, &checkpoint->ctx);
        f->offset = 0; /* hashflush() was called in checkpoint */
        return 0;
 }
@@ -256,8 +256,8 @@ int hashfile_checksum_valid(const unsigned char *data, size_t total_len)
                return 0; /* say "too short"? */
 
        algop->init_fn(&ctx);
-       algop->update_fn(&ctx, data, data_len);
-       algop->final_fn(got, &ctx);
+       git_hash_update(&ctx, data, data_len);
+       git_hash_final(got, &ctx);
 
        return hasheq(got, data + data_len, algop);
 }
diff --git a/diff.c b/diff.c
index 7f570ebdf95b5ee44fd282a22c1692e4bfae2494..019fb893a7e7517df26ea14bf015a49911dc46a4 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -6415,7 +6415,7 @@ void flush_one_hunk(struct object_id *result, struct git_hash_ctx *ctx)
        unsigned short carry = 0;
        int i;
 
-       the_hash_algo->final_fn(hash, ctx);
+       git_hash_final(hash, ctx);
        the_hash_algo->init_fn(ctx);
        /* 20-byte sum, with carry */
        for (i = 0; i < the_hash_algo->rawsz; ++i) {
@@ -6434,14 +6434,14 @@ static int patch_id_consume(void *priv, char *line, unsigned long len)
                return 0;
        new_len = remove_space(line, len);
 
-       the_hash_algo->update_fn(data->ctx, line, new_len);
+       git_hash_update(data->ctx, line, new_len);
        data->patchlen += new_len;
        return 0;
 }
 
 static void patch_id_add_string(struct git_hash_ctx *ctx, const char *str)
 {
-       the_hash_algo->update_fn(ctx, str, strlen(str));
+       git_hash_update(ctx, str, strlen(str));
 }
 
 static void patch_id_add_mode(struct git_hash_ctx *ctx, unsigned mode)
@@ -6449,7 +6449,7 @@ static void patch_id_add_mode(struct git_hash_ctx *ctx, unsigned mode)
        /* large enough for 2^32 in octal */
        char buf[12];
        int len = xsnprintf(buf, sizeof(buf), "%06o", mode);
-       the_hash_algo->update_fn(ctx, buf, len);
+       git_hash_update(ctx, buf, len);
 }
 
 /* returns 0 upon success, and writes result into oid */
@@ -6493,9 +6493,9 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
                len2 = remove_space(p->two->path, strlen(p->two->path));
                patch_id_add_string(&ctx, "diff--git");
                patch_id_add_string(&ctx, "a/");
-               the_hash_algo->update_fn(&ctx, p->one->path, len1);
+               git_hash_update(&ctx, p->one->path, len1);
                patch_id_add_string(&ctx, "b/");
-               the_hash_algo->update_fn(&ctx, p->two->path, len2);
+               git_hash_update(&ctx, p->two->path, len2);
 
                if (p->one->mode == 0) {
                        patch_id_add_string(&ctx, "newfilemode");
@@ -6514,24 +6514,24 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
                        /* don't do anything since we're only populating header info */
                } else if (diff_filespec_is_binary(options->repo, p->one) ||
                    diff_filespec_is_binary(options->repo, p->two)) {
-                       the_hash_algo->update_fn(&ctx, oid_to_hex(&p->one->oid),
+                       git_hash_update(&ctx, oid_to_hex(&p->one->oid),
                                        the_hash_algo->hexsz);
-                       the_hash_algo->update_fn(&ctx, oid_to_hex(&p->two->oid),
+                       git_hash_update(&ctx, oid_to_hex(&p->two->oid),
                                        the_hash_algo->hexsz);
                } else {
                        if (p->one->mode == 0) {
                                patch_id_add_string(&ctx, "---/dev/null");
                                patch_id_add_string(&ctx, "+++b/");
-                               the_hash_algo->update_fn(&ctx, p->two->path, len2);
+                               git_hash_update(&ctx, p->two->path, len2);
                        } else if (p->two->mode == 0) {
                                patch_id_add_string(&ctx, "---a/");
-                               the_hash_algo->update_fn(&ctx, p->one->path, len1);
+                               git_hash_update(&ctx, p->one->path, len1);
                                patch_id_add_string(&ctx, "+++/dev/null");
                        } else {
                                patch_id_add_string(&ctx, "---a/");
-                               the_hash_algo->update_fn(&ctx, p->one->path, len1);
+                               git_hash_update(&ctx, p->one->path, len1);
                                patch_id_add_string(&ctx, "+++b/");
-                               the_hash_algo->update_fn(&ctx, p->two->path, len2);
+                               git_hash_update(&ctx, p->two->path, len2);
                        }
 
                        if (fill_mmfile(options->repo, &mf1, p->one) < 0 ||
index 36867af2f88918bb7f1d7ac86c08537a99c4a6f1..1b030d96f48002f2e12e183c524db537112410b8 100644 (file)
@@ -774,8 +774,8 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
                        lock->token = xstrdup(ctx->cdata);
 
                        the_hash_algo->init_fn(&hash_ctx);
-                       the_hash_algo->update_fn(&hash_ctx, lock->token, strlen(lock->token));
-                       the_hash_algo->final_fn(lock_token_hash, &hash_ctx);
+                       git_hash_update(&hash_ctx, lock->token, strlen(lock->token));
+                       git_hash_final(lock_token_hash, &hash_ctx);
 
                        lock->tmpfile_suffix[0] = '_';
                        memcpy(lock->tmpfile_suffix + 1, hash_to_hex(lock_token_hash), the_hash_algo->hexsz);
diff --git a/http.c b/http.c
index f08b2ae47465332714494cd5ea054880d42702c1..f4504133e88869dadb3ebad0b38902498d3cb5a1 100644 (file)
--- a/http.c
+++ b/http.c
@@ -2597,8 +2597,8 @@ static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb,
                freq->stream.next_out = expn;
                freq->stream.avail_out = sizeof(expn);
                freq->zret = git_inflate(&freq->stream, Z_SYNC_FLUSH);
-               the_hash_algo->update_fn(&freq->c, expn,
-                                        sizeof(expn) - freq->stream.avail_out);
+               git_hash_update(&freq->c, expn,
+                               sizeof(expn) - freq->stream.avail_out);
        } while (freq->stream.avail_in && freq->zret == Z_OK);
        return nmemb;
 }
@@ -2763,7 +2763,7 @@ int finish_http_object_request(struct http_object_request *freq)
                return -1;
        }
 
-       the_hash_algo->final_oid_fn(&freq->real_oid, &freq->c);
+       git_hash_final_oid(&freq->real_oid, &freq->c);
        if (freq->zret != Z_STREAM_END) {
                unlink_or_warn(freq->tmpfile.buf);
                return -1;
index b7f2af515f45d22a4b808b8fa6ededcacb3ef840..00c3a4b910f84c9a300a0923190f83ff459ad015 100644 (file)
@@ -1199,7 +1199,7 @@ int stream_object_signature(struct repository *r, const struct object_id *oid)
 
        /* Sha1.. */
        r->hash_algo->init_fn(&c);
-       r->hash_algo->update_fn(&c, hdr, hdrlen);
+       git_hash_update(&c, hdr, hdrlen);
        for (;;) {
                char buf[1024 * 16];
                ssize_t readlen = read_istream(st, buf, sizeof(buf));
@@ -1210,9 +1210,9 @@ int stream_object_signature(struct repository *r, const struct object_id *oid)
                }
                if (!readlen)
                        break;
-               r->hash_algo->update_fn(&c, buf, readlen);
+               git_hash_update(&c, buf, readlen);
        }
-       r->hash_algo->final_oid_fn(&real_oid, &c);
+       git_hash_final_oid(&real_oid, &c);
        close_istream(st);
        return !oideq(oid, &real_oid) ? -1 : 0;
 }
@@ -1957,9 +1957,9 @@ static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_c
                             char *hdr, int *hdrlen)
 {
        algo->init_fn(c);
-       algo->update_fn(c, hdr, *hdrlen);
-       algo->update_fn(c, buf, len);
-       algo->final_oid_fn(oid, c);
+       git_hash_update(c, hdr, *hdrlen);
+       git_hash_update(c, buf, len);
+       git_hash_final_oid(oid, c);
 }
 
 static void write_object_file_prepare(const struct git_hash_algo *algo,
@@ -2246,9 +2246,9 @@ static int start_loose_object_common(struct strbuf *tmp_file,
        stream->avail_in = hdrlen;
        while (git_deflate(stream, 0) == Z_OK)
                ; /* nothing */
-       algo->update_fn(c, hdr, hdrlen);
+       git_hash_update(c, hdr, hdrlen);
        if (compat && compat_c)
-               compat->update_fn(compat_c, hdr, hdrlen);
+               git_hash_update(compat_c, hdr, hdrlen);
 
        return fd;
 }
@@ -2264,14 +2264,13 @@ static int write_loose_object_common(struct git_hash_ctx *c, struct git_hash_ctx
                                     const size_t compressed_len)
 {
        struct repository *repo = the_repository;
-       const struct git_hash_algo *algo = repo->hash_algo;
        const struct git_hash_algo *compat = repo->compat_hash_algo;
        int ret;
 
        ret = git_deflate(stream, flush ? Z_FINISH : 0);
-       algo->update_fn(c, in0, stream->next_in - in0);
+       git_hash_update(c, in0, stream->next_in - in0);
        if (compat && compat_c)
-               compat->update_fn(compat_c, in0, stream->next_in - in0);
+               git_hash_update(compat_c, in0, stream->next_in - in0);
        if (write_in_full(fd, compressed, stream->next_out - compressed) < 0)
                die_errno(_("unable to write loose object file"));
        stream->next_out = compressed;
@@ -2291,16 +2290,15 @@ static int end_loose_object_common(struct git_hash_ctx *c, struct git_hash_ctx *
                                   struct object_id *compat_oid)
 {
        struct repository *repo = the_repository;
-       const struct git_hash_algo *algo = repo->hash_algo;
        const struct git_hash_algo *compat = repo->compat_hash_algo;
        int ret;
 
        ret = git_deflate_end_gently(stream);
        if (ret != Z_OK)
                return ret;
-       algo->final_oid_fn(oid, c);
+       git_hash_final_oid(oid, c);
        if (compat && compat_c)
-               compat->final_oid_fn(compat_oid, compat_c);
+               git_hash_final_oid(compat_oid, compat_c);
 
        return Z_OK;
 }
@@ -3059,7 +3057,7 @@ static int check_stream_oid(git_zstream *stream,
        int status = Z_OK;
 
        the_hash_algo->init_fn(&c);
-       the_hash_algo->update_fn(&c, hdr, stream->total_out);
+       git_hash_update(&c, hdr, stream->total_out);
 
        /*
         * We already read some bytes into hdr, but the ones up to the NUL
@@ -3079,7 +3077,7 @@ static int check_stream_oid(git_zstream *stream,
                if (size - total_read < stream->avail_out)
                        stream->avail_out = size - total_read;
                status = git_inflate(stream, Z_FINISH);
-               the_hash_algo->update_fn(&c, buf, stream->next_out - buf);
+               git_hash_update(&c, buf, stream->next_out - buf);
                total_read += stream->next_out - buf;
        }
        git_inflate_end(stream);
@@ -3094,7 +3092,7 @@ static int check_stream_oid(git_zstream *stream,
                return -1;
        }
 
-       the_hash_algo->final_oid_fn(&real_oid, &c);
+       git_hash_final_oid(&real_oid, &c);
        if (!oideq(expected_oid, &real_oid)) {
                error(_("hash mismatch for %s (expected %s)"), path,
                      oid_to_hex(expected_oid));
index f20209fccb45c15f96fd1c7074febc61bc2265c8..d0aeb5ec41259bdafd9fdc567611416c20ca3728 100644 (file)
@@ -77,9 +77,9 @@ static int verify_packfile(struct repository *r,
                        pack_sig_ofs = p->pack_size - r->hash_algo->rawsz;
                if (offset > pack_sig_ofs)
                        remaining -= (unsigned int)(offset - pack_sig_ofs);
-               r->hash_algo->update_fn(&ctx, in, remaining);
+               git_hash_update(&ctx, in, remaining);
        } while (offset < pack_sig_ofs);
-       r->hash_algo->final_fn(hash, &ctx);
+       git_hash_final(hash, &ctx);
        pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);
        if (!hasheq(hash, pack_sig, the_repository->hash_algo))
                err = error("%s pack checksum mismatch",
index 9004d1d095790da7f13679ccba4d443906a7126c..cfcb7297b891418586aeeb3f4582ea52f9109203 100644 (file)
@@ -406,9 +406,9 @@ void fixup_pack_header_footer(int pack_fd,
                          pack_name);
        if (lseek(pack_fd, 0, SEEK_SET) != 0)
                die_errno("Failed seeking to start of '%s'", pack_name);
-       the_hash_algo->update_fn(&old_hash_ctx, &hdr, sizeof(hdr));
+       git_hash_update(&old_hash_ctx, &hdr, sizeof(hdr));
        hdr.hdr_entries = htonl(object_count);
-       the_hash_algo->update_fn(&new_hash_ctx, &hdr, sizeof(hdr));
+       git_hash_update(&new_hash_ctx, &hdr, sizeof(hdr));
        write_or_die(pack_fd, &hdr, sizeof(hdr));
        partial_pack_offset -= sizeof(hdr);
 
@@ -423,7 +423,7 @@ void fixup_pack_header_footer(int pack_fd,
                        break;
                if (n < 0)
                        die_errno("Failed to checksum '%s'", pack_name);
-               the_hash_algo->update_fn(&new_hash_ctx, buf, n);
+               git_hash_update(&new_hash_ctx, buf, n);
 
                aligned_sz -= n;
                if (!aligned_sz)
@@ -432,11 +432,11 @@ void fixup_pack_header_footer(int pack_fd,
                if (!partial_pack_hash)
                        continue;
 
-               the_hash_algo->update_fn(&old_hash_ctx, buf, n);
+               git_hash_update(&old_hash_ctx, buf, n);
                partial_pack_offset -= n;
                if (partial_pack_offset == 0) {
                        unsigned char hash[GIT_MAX_RAWSZ];
-                       the_hash_algo->final_fn(hash, &old_hash_ctx);
+                       git_hash_final(hash, &old_hash_ctx);
                        if (!hasheq(hash, partial_pack_hash,
                                    the_repository->hash_algo))
                                die("Unexpected checksum for %s "
@@ -454,8 +454,8 @@ void fixup_pack_header_footer(int pack_fd,
        free(buf);
 
        if (partial_pack_hash)
-               the_hash_algo->final_fn(partial_pack_hash, &old_hash_ctx);
-       the_hash_algo->final_fn(new_pack_hash, &new_hash_ctx);
+               git_hash_final(partial_pack_hash, &old_hash_ctx);
+       git_hash_final(new_pack_hash, &new_hash_ctx);
        write_or_die(pack_fd, new_pack_hash, the_hash_algo->rawsz);
        fsync_component_or_die(FSYNC_COMPONENT_PACK, pack_fd, pack_name);
 }
index 5e765d9af5ec3849c6a69d320af738cb486c1d86..7ef01c3806ea0cec8efa0918149c82627b43ff17 100644 (file)
@@ -1739,8 +1739,8 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size)
                return 0;
 
        the_hash_algo->init_fn(&c);
-       the_hash_algo->update_fn(&c, hdr, size - the_hash_algo->rawsz);
-       the_hash_algo->final_fn(hash, &c);
+       git_hash_update(&c, hdr, size - the_hash_algo->rawsz);
+       git_hash_final(hash, &c);
        if (!hasheq(hash, start, the_repository->hash_algo))
                return error(_("bad index file sha1 signature"));
        return 0;
@@ -2576,8 +2576,8 @@ static int write_index_ext_header(struct hashfile *f,
        if (eoie_f) {
                ext = htonl(ext);
                sz = htonl(sz);
-               the_hash_algo->update_fn(eoie_f, &ext, sizeof(ext));
-               the_hash_algo->update_fn(eoie_f, &sz, sizeof(sz));
+               git_hash_update(eoie_f, &ext, sizeof(ext));
+               git_hash_update(eoie_f, &sz, sizeof(sz));
        }
        return 0;
 }
@@ -3634,12 +3634,12 @@ static size_t read_eoie_extension(const char *mmap, size_t mmap_size)
                if (src_offset + 8 + extsize < src_offset)
                        return 0;
 
-               the_hash_algo->update_fn(&c, mmap + src_offset, 8);
+               git_hash_update(&c, mmap + src_offset, 8);
 
                src_offset += 8;
                src_offset += extsize;
        }
-       the_hash_algo->final_fn(hash, &c);
+       git_hash_final(hash, &c);
        if (!hasheq(hash, (const unsigned char *)index, the_repository->hash_algo))
                return 0;
 
@@ -3660,7 +3660,7 @@ static void write_eoie_extension(struct strbuf *sb, struct git_hash_ctx *eoie_co
        strbuf_add(sb, &buffer, sizeof(uint32_t));
 
        /* hash */
-       the_hash_algo->final_fn(hash, eoie_context);
+       git_hash_final(hash, eoie_context);
        strbuf_add(sb, hash, the_hash_algo->rawsz);
 }
 
index 5ff9624b57d8699662a706751300895a04486f63..c42cee618bfe65b71ac979edd3f33b20cbe2bd0e 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -396,12 +396,12 @@ static int handle_conflict(struct strbuf *out, struct rerere_io *io,
                        strbuf_addbuf(out, &two);
                        rerere_strbuf_putconflict(out, '>', marker_size);
                        if (ctx) {
-                               the_hash_algo->update_fn(ctx, one.buf ?
-                                                        one.buf : "",
-                                                        one.len + 1);
-                               the_hash_algo->update_fn(ctx, two.buf ?
-                                                        two.buf : "",
-                                                        two.len + 1);
+                               git_hash_update(ctx, one.buf ?
+                                               one.buf : "",
+                                               one.len + 1);
+                               git_hash_update(ctx, two.buf ?
+                                               two.buf : "",
+                                               two.len + 1);
                        }
                        break;
                } else if (hunk == RR_SIDE_1)
@@ -453,7 +453,7 @@ static int handle_path(unsigned char *hash, struct rerere_io *io, int marker_siz
        strbuf_release(&out);
 
        if (hash)
-               the_hash_algo->final_fn(hash, &ctx);
+               git_hash_final(hash, &ctx);
 
        return has_conflicts;
 }
index 803f41c89de7bbbbfad39522ae2a770c7e639c03..fbf67fe6bd548fc7c823dfaf387e52e3558a1964 100644 (file)
@@ -6,8 +6,8 @@
 static inline void compute_hash(const struct git_hash_algo *algo, struct git_hash_ctx *ctx, uint8_t *final, const void *p, size_t len)
 {
        algo->init_fn(ctx);
-       algo->update_fn(ctx, p, len);
-       algo->final_fn(final, ctx);
+       git_hash_update(ctx, p, len);
+       git_hash_final(final, ctx);
 }
 
 int cmd__hash_speed(int ac, const char **av)
index f9a3db487a97eb71946d9b92373aab6769d8c16f..f0ee61c8b47a65abd0e6762faae7aef75ea54cb3 100644 (file)
@@ -48,9 +48,9 @@ int cmd_hash_impl(int ac, const char **av, int algo, int unsafe)
                }
                if (this_sz == 0)
                        break;
-               algop->update_fn(&ctx, buffer, this_sz);
+               git_hash_update(&ctx, buffer, this_sz);
        }
-       algop->final_fn(hash, &ctx);
+       git_hash_final(hash, &ctx);
 
        if (binary)
                fwrite(hash, 1, algop->rawsz, stdout);
index 05204e7b6c8fd90d4a98f42d824b0f9ec71e1c3e..bd4ac6a6e1f05f0bfb754c8fbcfdade230826cf7 100644 (file)
@@ -13,8 +13,8 @@ static void check_hash_data(const void *data, size_t data_length,
                const struct git_hash_algo *algop = &hash_algos[i];
 
                algop->init_fn(&ctx);
-               algop->update_fn(&ctx, data, data_length);
-               algop->final_fn(hash, &ctx);
+               git_hash_update(&ctx, data, data_length);
+               git_hash_final(hash, &ctx);
 
                cl_assert_equal_s(hash_to_hex_algop(hash,algop), expected_hashes[i - 1]);
        }
index c42696ef526703fb59968bb9d40af57d3e25f924..1c1d27b0eee9355a884e97df98ffd0c663cd97d5 100644 (file)
@@ -46,8 +46,8 @@ static void tr2_sid_append_my_sid_component(void)
                strbuf_add(&tr2sid_buf, "Localhost", 9);
        else {
                algo->init_fn(&ctx);
-               algo->update_fn(&ctx, hostname, strlen(hostname));
-               algo->final_fn(hash, &ctx);
+               git_hash_update(&ctx, hostname, strlen(hostname));
+               git_hash_final(hash, &ctx);
                hash_to_hex_algop_r(hex, hash, algo);
                strbuf_addch(&tr2sid_buf, 'H');
                strbuf_add(&tr2sid_buf, hex, 8);