futils: use a particular hash not a git_oid

In `git_futils_readbuffer_updated`, always take a particular hash
instead of a `git_oid`.  This lets us change the checksum algorithm
independently of `git_oid` usage.
This commit is contained in:
Edward Thomson
2021-09-30 08:40:29 -04:00
parent 31ecaca2d3
commit 923364c58e
2 changed files with 13 additions and 7 deletions

View File

@@ -177,13 +177,16 @@ int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
}
int git_futils_readbuffer_updated(
git_buf *out, const char *path, git_oid *checksum, int *updated)
git_buf *out,
const char *path,
unsigned char checksum[GIT_HASH_SHA1_SIZE],
int *updated)
{
int error;
git_file fd;
struct stat st;
git_buf buf = GIT_BUF_INIT;
git_oid checksum_new;
unsigned char checksum_new[GIT_HASH_SHA1_SIZE];
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(path && *path);
@@ -216,7 +219,7 @@ int git_futils_readbuffer_updated(
p_close(fd);
if (checksum) {
if ((error = git_hash_buf(checksum_new.id, buf.ptr, buf.size, GIT_HASH_ALGORITHM_SHA1)) < 0) {
if ((error = git_hash_buf(checksum_new, buf.ptr, buf.size, GIT_HASH_ALGORITHM_SHA1)) < 0) {
git_buf_dispose(&buf);
return error;
}
@@ -224,7 +227,7 @@ int git_futils_readbuffer_updated(
/*
* If we were given a checksum, we only want to use it if it's different
*/
if (!git_oid__cmp(checksum, &checksum_new)) {
if (!memcmp(checksum, checksum_new, GIT_HASH_SHA1_SIZE)) {
git_buf_dispose(&buf);
if (updated)
*updated = 0;
@@ -232,7 +235,7 @@ int git_futils_readbuffer_updated(
return 0;
}
git_oid_cpy(checksum, &checksum_new);
memcpy(checksum, checksum_new, GIT_HASH_SHA1_SIZE);
}
/*

View File

@@ -14,7 +14,7 @@
#include "path.h"
#include "pool.h"
#include "strmap.h"
#include "oid.h"
#include "hash.h"
/**
* Filebuffer methods
@@ -23,7 +23,10 @@
*/
extern int git_futils_readbuffer(git_buf *obj, const char *path);
extern int git_futils_readbuffer_updated(
git_buf *obj, const char *path, git_oid *checksum, int *updated);
git_buf *obj,
const char *path,
unsigned char checksum[GIT_HASH_SHA1_SIZE],
int *updated);
extern int git_futils_readbuffer_fd(git_buf *obj, git_file fd, size_t len);
/* Additional constants for `git_futils_writebuffer`'s `open_flags`. We