diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2021-09-30 08:40:29 -0400 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2021-10-02 16:34:47 -0400 |
commit | 923364c58eaca0c54f09def3292dff848975906c (patch) | |
tree | 28d35f643e6d6b0c72a8fd3707c9ffc58094e091 | |
parent | 31ecaca2d3e87d20782a54cb319f5c19e6c6e62f (diff) | |
download | libgit2-923364c58eaca0c54f09def3292dff848975906c.tar.gz |
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.
-rw-r--r-- | src/futils.c | 13 | ||||
-rw-r--r-- | src/futils.h | 7 |
2 files changed, 13 insertions, 7 deletions
diff --git a/src/futils.c b/src/futils.c index 138fc2c82..d28b231ce 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 58936125a..373cc3042 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 |