diff options
author | Edward Thomson <ethomson@microsoft.com> | 2014-03-05 11:35:47 -0800 |
---|---|---|
committer | Edward Thomson <ethomson@microsoft.com> | 2014-03-05 11:35:47 -0800 |
commit | 7bd2f401540e1e9c92183fd61aa9e2a4ef0ed051 (patch) | |
tree | 9f3388edb63b9ff34f3d92b72e2a87e6028eb2f0 /src | |
parent | fb52ba19ff0a620b4fd9482132206ccb4daee8e0 (diff) | |
download | libgit2-7bd2f401540e1e9c92183fd61aa9e2a4ef0ed051.tar.gz |
ODB writing fails gracefully when unsupported
If no ODB backends support writing, we should fail gracefully.
Diffstat (limited to 'src')
-rw-r--r-- | src/odb.c | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -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; } |