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);
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);
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;
}
}
git_deflate_end(&s);
- the_hash_algo->final_oid_fn(&oid, &c);
+ git_hash_final_oid(&oid, &c);
if (oidout)
oidcpy(oidout, &oid);
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;
}
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)
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);
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;
}
/* 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);
!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;
}
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;
/* 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)
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);
}
/* 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)
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;
}
}
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))
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;
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) {
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;
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;
}
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);
* 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 {
/*
{
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)
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;
}
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);
}
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) {
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)
/* 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 */
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");
/* 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 ||
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);
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;
}
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;
/* 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));
}
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;
}
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,
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;
}
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;
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;
}
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
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);
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));
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",
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);
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)
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 "
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);
}
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;
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;
}
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;
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);
}
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)
strbuf_release(&out);
if (hash)
- the_hash_algo->final_fn(hash, &ctx);
+ git_hash_final(hash, &ctx);
return has_conflicts;
}
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)
}
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);
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]);
}
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);