summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2017-03-09 12:26:23 +0000
committerEdward Thomson <ethomson@github.com>2017-03-09 12:26:23 +0000
commit11c8e756ac05e09adc3092f58f68cb1118c5167b (patch)
tree11135a518838f78ed37d0adef3b8c60f6da75b4b
parentb31b2360044f5960d52b7b12d1c9e48cd647a3fb (diff)
downloadlibgit2-ethomson/readbuffer_dont_hash.tar.gz
git_futils_readbuffer: don't compute sha-1ethomson/readbuffer_dont_hash
Don't compute the sha-1 in `git_futils_readbuffer_updated` unless the checksum was requested. This means that `git_futils_readbuffer` will not calculate the checksum unnecessarily.
-rw-r--r--src/fileops.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/fileops.c b/src/fileops.c
index 57dea8fce..acb3b87e3 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -196,28 +196,29 @@ int git_futils_readbuffer_updated(
p_close(fd);
- if ((error = git_hash_buf(&checksum_new, buf.ptr, buf.size)) < 0) {
- git_buf_free(&buf);
- return error;
- }
+ if (checksum) {
+ if ((error = git_hash_buf(&checksum_new, buf.ptr, buf.size)) < 0) {
+ git_buf_free(&buf);
+ return error;
+ }
- /*
- * If we were given a checksum, we only want to use it if it's different
- */
- if (checksum && !git_oid__cmp(checksum, &checksum_new)) {
- git_buf_free(&buf);
- if (updated)
- *updated = 0;
+ /*
+ * If we were given a checksum, we only want to use it if it's different
+ */
+ if (!git_oid__cmp(checksum, &checksum_new)) {
+ git_buf_free(&buf);
+ if (updated)
+ *updated = 0;
- return 0;
+ return 0;
+ }
+
+ git_oid_cpy(checksum, &checksum_new);
}
/*
* If we're here, the file did change, or the user didn't have an old version
*/
- if (checksum)
- git_oid_cpy(checksum, &checksum_new);
-
if (updated != NULL)
*updated = 1;