void test_object_blob_fromchunks__doesnot_overwrite_an_already_existing_object(void) { git_buf path = GIT_BUF_INIT; git_buf content = GIT_BUF_INIT; git_oid expected_oid, oid; int howmany = 7; cl_git_pass(git_oid_fromstr(&expected_oid, "321cbdf08803c744082332332838df6bd160f8f9")); cl_git_pass(git_blob_create_fromchunks(&oid, repo, NULL, text_chunked_source_cb, &howmany)); /* Let's replace the content of the blob file storage with something else... */ cl_git_pass(git_buf_joinpath(&path, git_repository_path(repo), "objects/32/1cbdf08803c744082332332838df6bd160f8f9")); cl_git_pass(p_unlink(git_buf_cstr(&path))); cl_git_mkfile(git_buf_cstr(&path), "boom"); /* ...request a creation of the same blob... */ howmany = 7; cl_git_pass(git_blob_create_fromchunks(&oid, repo, NULL, text_chunked_source_cb, &howmany)); /* ...and ensure the content of the faked blob file hasn't been altered */ cl_git_pass(git_futils_readbuffer(&content, git_buf_cstr(&path))); cl_assert(!git__strcmp("boom", git_buf_cstr(&content))); git_buf_free(&path); git_buf_free(&content); }
/* * call-seq: * Blob.from_chunks(repository, io [, hint_path]) -> oid * * Write a loose blob to the +repository+ from a provider * of chunks of data. * * The repository can be bare or not. * * The data provider +io+ should respond to a <code>read(size)</code> * method. Generally any instance of a class based on Ruby's +IO+ class * should work(ex. +File+). On each +read+ call it should * return a +String+ with maximum size of +size+. * * *NOTE:* If an exception is raised in the +io+ object's * +read+ method, a blob will be created with the data up to that point * and the exception will be rescued. * It's recommended to compare the +blob.size+ with the expected data size * to check if all the data was written. * * Provided the +hint_path+ parameter is given, its value * will help to determine what git filters should be applied * to the object before it can be placed to the object database. * * File.open('/path/to/file') do |file| * Blob.from_chunks(repo, file, 'hint/blob.h') #=> '42cab3c0cde61e2b5a2392e1eadbeffa20ffa171' * end */ static VALUE rb_git_blob_from_chunks(int argc, VALUE *argv, VALUE klass) { VALUE rb_repo, rb_io, rb_hint_path; const char * hint_path = NULL; int error; git_oid oid; git_repository *repo; rb_scan_args(argc, argv, "21", &rb_repo, &rb_io, &rb_hint_path); rugged_check_repo(rb_repo); Data_Get_Struct(rb_repo, git_repository, repo); if (!NIL_P(rb_hint_path)) { Check_Type(rb_hint_path, T_STRING); hint_path = StringValueCStr(rb_hint_path); } error = git_blob_create_fromchunks( &oid, repo, hint_path, cb_blob__get__chunk, (void *)rb_io); rugged_exception_check(error); return rugged_create_oid(&oid); }
int _go_git_blob_create_fromchunks(git_oid *id, git_repository *repo, const char *hintpath, void *payload) { return git_blob_create_fromchunks(id, repo, hintpath, _go_blob_chunk_cb, payload); }
static void assert_named_chunked_blob(const char *expected_sha, const char *fake_name) { git_oid expected_oid, oid; int howmany = 7; cl_git_pass(git_oid_fromstr(&expected_oid, expected_sha)); cl_git_pass(git_blob_create_fromchunks(&oid, repo, fake_name, text_chunked_source_cb, &howmany)); cl_assert(git_oid_cmp(&expected_oid, &oid) == 0); }
void test_object_blob_fromchunks__can_create_a_blob_from_a_in_memory_chunk_provider(void) { git_oid expected_oid, oid; git_object *blob; int howmany = 7; cl_git_pass(git_oid_fromstr(&expected_oid, "321cbdf08803c744082332332838df6bd160f8f9")); cl_git_fail(git_object_lookup(&blob, repo, &expected_oid, GIT_OBJ_ANY)); cl_git_pass(git_blob_create_fromchunks(&oid, repo, NULL, text_chunked_source_cb, &howmany)); cl_git_pass(git_object_lookup(&blob, repo, &expected_oid, GIT_OBJ_ANY)); git_object_free(blob); }
void test_object_blob_fromchunks__can_stop_with_error(void) { git_oid expected_oid, oid; git_object *blob; int howmany = 7; cl_git_pass(git_oid_fromstr( &expected_oid, "321cbdf08803c744082332332838df6bd160f8f9")); cl_git_fail_with( git_object_lookup(&blob, repo, &expected_oid, GIT_OBJ_ANY), GIT_ENOTFOUND); cl_git_fail_with(git_blob_create_fromchunks( &oid, repo, NULL, failing_chunked_source_cb, &howmany), -1234); cl_git_fail_with( git_object_lookup(&blob, repo, &expected_oid, GIT_OBJ_ANY), GIT_ENOTFOUND); }