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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
diff --git a/src/futils.c b/src/futils.c
index 138fc2c..d28b231 100644
--- a/src/futils.c
+++ b/src/futils.c
@@ -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);
}
/*
diff --git a/src/futils.h b/src/futils.h
index 5893612..373cc30 100644
--- a/src/futils.h
+++ b/src/futils.h
@@ -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