mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 20:29:27 +00:00
Merge pull request #2163 from ethomson/nobackend_odb_write
ODB writing fails gracefully when unsupported
This commit is contained in:
commit
967d3f2e3e
18
src/odb.c
18
src/odb.c
@ -862,7 +862,7 @@ int git_odb_open_wstream(
|
|||||||
{
|
{
|
||||||
size_t i, writes = 0;
|
size_t i, writes = 0;
|
||||||
int error = GIT_ERROR;
|
int error = GIT_ERROR;
|
||||||
git_hash_ctx *ctx;
|
git_hash_ctx *ctx = NULL;
|
||||||
|
|
||||||
assert(stream && db);
|
assert(stream && db);
|
||||||
|
|
||||||
@ -883,22 +883,28 @@ int git_odb_open_wstream(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error == GIT_PASSTHROUGH)
|
if (error < 0) {
|
||||||
error = 0;
|
if (error == GIT_PASSTHROUGH)
|
||||||
if (error < 0 && !writes)
|
error = 0;
|
||||||
error = git_odb__error_unsupported_in_backend("write object");
|
else if (!writes)
|
||||||
|
error = git_odb__error_unsupported_in_backend("write object");
|
||||||
|
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
ctx = git__malloc(sizeof(git_hash_ctx));
|
ctx = git__malloc(sizeof(git_hash_ctx));
|
||||||
GITERR_CHECK_ALLOC(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);
|
hash_header(ctx, size, type);
|
||||||
(*stream)->hash_ctx = ctx;
|
(*stream)->hash_ctx = ctx;
|
||||||
|
|
||||||
(*stream)->declared_size = size;
|
(*stream)->declared_size = size;
|
||||||
(*stream)->received_bytes = 0;
|
(*stream)->received_bytes = 0;
|
||||||
|
|
||||||
|
done:
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
41
tests/odb/backend/nobackend.c
Normal file
41
tests/odb/backend/nobackend.c
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#include "clar_libgit2.h"
|
||||||
|
#include "repository.h"
|
||||||
|
#include "git2/sys/repository.h"
|
||||||
|
|
||||||
|
static git_repository *_repo;
|
||||||
|
|
||||||
|
void test_odb_backend_nobackend__initialize(void)
|
||||||
|
{
|
||||||
|
git_config *config;
|
||||||
|
git_odb *odb;
|
||||||
|
git_refdb *refdb;
|
||||||
|
|
||||||
|
cl_git_pass(git_repository_new(&_repo));
|
||||||
|
cl_git_pass(git_config_new(&config));
|
||||||
|
cl_git_pass(git_odb_new(&odb));
|
||||||
|
cl_git_pass(git_refdb_new(&refdb, _repo));
|
||||||
|
|
||||||
|
git_repository_set_config(_repo, config);
|
||||||
|
git_repository_set_odb(_repo, odb);
|
||||||
|
git_repository_set_refdb(_repo, refdb);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_odb_backend_nobackend__cleanup(void)
|
||||||
|
{
|
||||||
|
git_repository_free(_repo);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_odb_backend_nobackend__write_fails_gracefully(void)
|
||||||
|
{
|
||||||
|
git_oid id;
|
||||||
|
git_odb *odb;
|
||||||
|
const git_error *err;
|
||||||
|
|
||||||
|
git_repository_odb(&odb, _repo);
|
||||||
|
cl_git_fail(git_odb_write(&id, odb, "Hello world!\n", 13, GIT_OBJ_BLOB));
|
||||||
|
|
||||||
|
err = giterr_last();
|
||||||
|
cl_assert_equal_s(err->message, "Cannot write object - unsupported in the loaded odb backends");
|
||||||
|
|
||||||
|
git_odb_free(odb);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user