Skip to content

Commit 0b3623a

Browse files
authored
Merge pull request libgit2#4156 from libgit2/ethomson/readbuffer_dont_hash
git_futils_readbuffer: don't compute sha-1
2 parents ffd4df6 + 11c8e75 commit 0b3623a

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/fileops.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -196,28 +196,29 @@ int git_futils_readbuffer_updated(
196196

197197
p_close(fd);
198198

199-
if ((error = git_hash_buf(&checksum_new, buf.ptr, buf.size)) < 0) {
200-
git_buf_free(&buf);
201-
return error;
202-
}
199+
if (checksum) {
200+
if ((error = git_hash_buf(&checksum_new, buf.ptr, buf.size)) < 0) {
201+
git_buf_free(&buf);
202+
return error;
203+
}
203204

204-
/*
205-
* If we were given a checksum, we only want to use it if it's different
206-
*/
207-
if (checksum && !git_oid__cmp(checksum, &checksum_new)) {
208-
git_buf_free(&buf);
209-
if (updated)
210-
*updated = 0;
205+
/*
206+
* If we were given a checksum, we only want to use it if it's different
207+
*/
208+
if (!git_oid__cmp(checksum, &checksum_new)) {
209+
git_buf_free(&buf);
210+
if (updated)
211+
*updated = 0;
211212

212-
return 0;
213+
return 0;
214+
}
215+
216+
git_oid_cpy(checksum, &checksum_new);
213217
}
214218

215219
/*
216220
* If we're here, the file did change, or the user didn't have an old version
217221
*/
218-
if (checksum)
219-
git_oid_cpy(checksum, &checksum_new);
220-
221222
if (updated != NULL)
222223
*updated = 1;
223224

0 commit comments

Comments
 (0)