summaryrefslogtreecommitdiff
path: root/src/odb.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2012-11-05 12:37:15 -0600
committerEdward Thomson <ethomson@edwardthomson.com>2012-11-13 10:23:05 -0600
commitd6fb09240913c9756de5f4a2462062008ebac252 (patch)
treec4a99509abd1dffdcd52353d551089f257b54c1e /src/odb.c
parente45423dd2c5ef8262f70605b81c6da0751d000a3 (diff)
downloadlibgit2-d6fb09240913c9756de5f4a2462062008ebac252.tar.gz
Win32 CryptoAPI and CNG support for SHA1
Diffstat (limited to 'src/odb.c')
-rw-r--r--src/odb.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/odb.c b/src/odb.c
index d6b1de946..027aeddaa 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -119,21 +119,25 @@ int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_otype type)
char hdr[64], buffer[2048];
git_hash_ctx *ctx;
ssize_t read_len = 0;
+ int error = 0;
if (!git_object_typeisloose(type)) {
giterr_set(GITERR_INVALID, "Invalid object type for hash");
return -1;
}
- hdr_len = format_object_header(hdr, sizeof(hdr), size, type);
-
- ctx = git_hash_new_ctx();
+ ctx = git_hash_ctx_new();
GITERR_CHECK_ALLOC(ctx);
- git_hash_update(ctx, hdr, hdr_len);
+ hdr_len = format_object_header(hdr, sizeof(hdr), size, type);
+
+ if ((error = git_hash_update(ctx, hdr, hdr_len)) < 0)
+ goto done;
while (size > 0 && (read_len = p_read(fd, buffer, sizeof(buffer))) > 0) {
- git_hash_update(ctx, buffer, read_len);
+ if ((error = git_hash_update(ctx, buffer, read_len)) < 0)
+ goto done;
+
size -= read_len;
}
@@ -141,15 +145,18 @@ int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_otype type)
* If size is not zero, the file was truncated after we originally
* stat'd it, so we consider this a read failure too */
if (read_len < 0 || size > 0) {
- git_hash_free_ctx(ctx);
giterr_set(GITERR_OS, "Error reading file for hashing");
+ error = -1;
+
+ goto done;
return -1;
}
- git_hash_final(out, ctx);
- git_hash_free_ctx(ctx);
+ error = git_hash_final(out, ctx);
- return 0;
+done:
+ git_hash_ctx_free(ctx);
+ return error;
}
int git_odb__hashfd_filtered(