summaryrefslogtreecommitdiff
path: root/src/odb.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2014-03-05 11:35:47 -0800
committerEdward Thomson <ethomson@microsoft.com>2014-03-05 11:35:47 -0800
commit7bd2f401540e1e9c92183fd61aa9e2a4ef0ed051 (patch)
tree9f3388edb63b9ff34f3d92b72e2a87e6028eb2f0 /src/odb.c
parentfb52ba19ff0a620b4fd9482132206ccb4daee8e0 (diff)
downloadlibgit2-7bd2f401540e1e9c92183fd61aa9e2a4ef0ed051.tar.gz
ODB writing fails gracefully when unsupported
If no ODB backends support writing, we should fail gracefully.
Diffstat (limited to 'src/odb.c')
-rw-r--r--src/odb.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/odb.c b/src/odb.c
index b413f83b4..139949e31 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -862,7 +862,7 @@ int git_odb_open_wstream(
{
size_t i, writes = 0;
int error = GIT_ERROR;
- git_hash_ctx *ctx;
+ git_hash_ctx *ctx = NULL;
assert(stream && db);
@@ -883,22 +883,28 @@ int git_odb_open_wstream(
}
}
- if (error == GIT_PASSTHROUGH)
- error = 0;
- if (error < 0 && !writes)
- error = git_odb__error_unsupported_in_backend("write object");
+ if (error < 0) {
+ if (error == GIT_PASSTHROUGH)
+ error = 0;
+ else if (!writes)
+ error = git_odb__error_unsupported_in_backend("write object");
+
+ goto done;
+ }
ctx = git__malloc(sizeof(git_hash_ctx));
GITERR_CHECK_ALLOC(ctx);
+ if ((error = git_hash_ctx_init(ctx)) < 0)
+ goto done;
- git_hash_ctx_init(ctx);
hash_header(ctx, size, type);
(*stream)->hash_ctx = ctx;
(*stream)->declared_size = size;
(*stream)->received_bytes = 0;
+done:
return error;
}