static ERL_NIF_TERM geef_object_exists(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { char path[MAXBUFLEN]; char sha[MAXBUFLEN]; (void)memset(&path, '\0', sizeof(path)); (void)memset(&sha, '\0', sizeof(sha)); if (enif_get_string(env, argv[0], path, sizeof(path), ERL_NIF_LATIN1) < 1) return enif_make_badarg(env); if (enif_get_string(env, argv[1], sha, sizeof(sha), ERL_NIF_LATIN1) < 1) return enif_make_badarg(env); git_odb *odb; git_odb_open(&odb, path); git_oid oid; git_oid_fromstr(&oid, sha); int exists = git_odb_exists(odb, &oid); if(exists == 1) { return enif_make_atom(env, "true"); } return enif_make_atom(env, "false"); }
int git_repository_open(git_repository **repo_out, const char *path) { git_repository *repo; int error = GIT_SUCCESS; assert(repo_out && path); repo = repository_alloc(); if (repo == NULL) return GIT_ENOMEM; error = guess_repository_DIRs(repo, path); if (error < GIT_SUCCESS) goto cleanup; error = git_odb_open(&repo->db, repo->path_odb); if (error < GIT_SUCCESS) goto cleanup; *repo_out = repo; return GIT_SUCCESS; cleanup: git_repository_free(repo); return error; }
int git_repository_open2(git_repository **repo_out, const char *git_dir, const char *git_object_directory, const char *git_index_file, const char *git_work_tree) { git_repository *repo; int error = GIT_SUCCESS; assert(repo_out); repo = repository_alloc(); if (repo == NULL) return GIT_ENOMEM; error = assign_repository_DIRs(repo, git_dir, git_object_directory, git_index_file, git_work_tree); if (error < GIT_SUCCESS) goto cleanup; error = git_odb_open(&repo->db, repo->path_odb); if (error < GIT_SUCCESS) goto cleanup; *repo_out = repo; return GIT_SUCCESS; cleanup: git_repository_free(repo); return error; }
int git_repository_odb__weakptr(git_odb **out, git_repository *repo) { int error = 0; assert(repo && out); if (repo->_odb == NULL) { git_buf odb_path = GIT_BUF_INIT; git_odb *odb; if ((error = git_buf_joinpath(&odb_path, repo->path_repository, GIT_OBJECTS_DIR)) < 0) return error; error = git_odb_open(&odb, odb_path.ptr); if (!error) { GIT_REFCOUNT_OWN(odb, repo); odb = (git_odb*) git__compare_and_swap(&repo->_odb, NULL, odb); if (odb != NULL) { GIT_REFCOUNT_OWN(odb, NULL); git_odb_free(odb); } } git_buf_free(&odb_path); } *out = repo->_odb; return error; }
static void test_read_object(object_data *data) { git_oid id; git_odb_object *obj; git_odb *odb; write_object_files(data); cl_git_pass(git_odb_open(&odb, "test-objects")); cl_git_pass(git_oid_fromstr(&id, data->id)); cl_git_pass(git_odb_read(&obj, odb, &id)); cmp_objects((git_rawobj *)&obj->raw, data); git_odb_object_free(obj); git_odb_free(odb); }
static void test_read_header(object_data *data) { git_oid id; git_odb *odb; size_t len; git_object_t type; write_object_files(data); cl_git_pass(git_odb_open(&odb, "test-objects")); cl_git_pass(git_oid_fromstr(&id, data->id)); cl_git_pass(git_odb_read_header(&len, &type, odb, &id)); cl_assert_equal_sz(data->dlen, len); cl_assert_equal_i(git_object_string2type(data->type), type); git_odb_free(odb); }
void test_odb_loose__exists(void) { git_oid id, id2; git_odb *odb; write_object_files(&one); cl_git_pass(git_odb_open(&odb, "test-objects")); cl_git_pass(git_oid_fromstr(&id, one.id)); cl_assert(git_odb_exists(odb, &id)); /* Test for a non-existant object */ cl_git_pass(git_oid_fromstr(&id2, "8b137891791fe96927ad78e64b0aad7bded08baa")); cl_assert(!git_odb_exists(odb, &id2)); git_odb_free(odb); }
static ERL_NIF_TERM geef_object_read(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { char path[MAXBUFLEN]; char sha[MAXBUFLEN]; (void)memset(&path, '\0', sizeof(path)); (void)memset(&sha, '\0', sizeof(sha)); if (enif_get_string(env, argv[0], path, sizeof(path), ERL_NIF_LATIN1) < 1) return enif_make_badarg(env); if (enif_get_string(env, argv[1], sha, sizeof(sha), ERL_NIF_LATIN1) < 1) return enif_make_badarg(env); git_odb *odb; git_odb_open(&odb, path); git_oid oid; git_oid_fromstr(&oid, sha); int error; git_odb_object *obj; error = git_odb_read(&obj, odb, &oid); if (error) { git_odb_free(odb); return enif_make_tuple2(env, enif_make_atom(env, "error"), enif_make_string(env, "object does not exist", ERL_NIF_LATIN1)); } size_t len; len = git_odb_object_size(obj); ErlNifBinary ibin; enif_alloc_binary(len, &ibin); memcpy(ibin.data, git_odb_object_data(obj), len); git_odb_free(odb); return enif_make_binary(env, &ibin); }
void test_repo_setters__setting_a_new_odb_on_a_repo_which_already_loaded_one_properly_honors_the_refcount(void) { git_odb *new_odb; cl_git_pass(git_odb_open(&new_odb, "./testrepo.git/objects")); cl_assert(((git_refcount *)new_odb)->refcount.val == 1); git_repository_set_odb(repo, new_odb); cl_assert(((git_refcount *)new_odb)->refcount.val == 2); git_repository_free(repo); cl_assert(((git_refcount *)new_odb)->refcount.val == 1); git_odb_free(new_odb); /* * Ensure the cleanup method won't try to free the repo as it's already been taken care of */ repo = NULL; }
static void test_read_object(object_data *data) { git_oid id; git_odb_object *obj; git_odb *odb; git_rawobj tmp; write_object_files(data); cl_git_pass(git_odb_open(&odb, "test-objects")); cl_git_pass(git_oid_fromstr(&id, data->id)); cl_git_pass(git_odb_read(&obj, odb, &id)); tmp.data = obj->buffer; tmp.len = obj->cached.size; tmp.type = obj->cached.type; cmp_objects(&tmp, data); git_odb_object_free(obj); git_odb_free(odb); }
int git_repository_odb__weakptr(git_odb **out, git_repository *repo) { assert(repo && out); if (repo->_odb == NULL) { git_buf odb_path = GIT_BUF_INIT; int res; if (git_buf_joinpath(&odb_path, repo->path_repository, GIT_OBJECTS_DIR) < 0) return -1; res = git_odb_open(&repo->_odb, odb_path.ptr); git_buf_free(&odb_path); /* done with path */ if (res < 0) return -1; GIT_REFCOUNT_OWN(repo->_odb, repo); } *out = repo->_odb; return 0; }
static void test_readstream_object(object_data *data, size_t blocksize) { git_oid id; git_odb *odb; git_odb_stream *stream; git_rawobj tmp; char buf[2048], *ptr = buf; size_t remain; int ret; write_object_files(data); cl_git_pass(git_odb_open(&odb, "test-objects")); cl_git_pass(git_oid_fromstr(&id, data->id)); cl_git_pass(git_odb_open_rstream(&stream, &tmp.len, &tmp.type, odb, &id)); remain = tmp.len; while (remain) { cl_assert((ret = git_odb_stream_read(stream, ptr, blocksize)) >= 0); if (ret == 0) break; cl_assert(remain >= (size_t)ret); remain -= ret; ptr += ret; } cl_assert(remain == 0); tmp.data = buf; cmp_objects(&tmp, data); git_odb_stream_free(stream); git_odb_free(odb); }
void test_odb_loose__exists(void) { git_oid id, id2; git_odb *odb; write_object_files(&one); cl_git_pass(git_odb_open(&odb, "test-objects")); cl_git_pass(git_oid_fromstr(&id, one.id)); cl_assert(git_odb_exists(odb, &id)); cl_git_pass(git_oid_fromstrp(&id, "8b137891")); cl_git_pass(git_odb_exists_prefix(&id2, odb, &id, 8)); cl_assert_equal_i(0, git_oid_streq(&id2, one.id)); /* Test for a missing object */ cl_git_pass(git_oid_fromstr(&id, "8b137891791fe96927ad78e64b0aad7bded08baa")); cl_assert(!git_odb_exists(odb, &id)); cl_git_pass(git_oid_fromstrp(&id, "8b13789a")); cl_assert_equal_i(GIT_ENOTFOUND, git_odb_exists_prefix(&id2, odb, &id, 8)); git_odb_free(odb); }
void test_odb_mixed__initialize(void) { cl_git_pass(git_odb_open(&_odb, cl_fixture("duplicate.git/objects"))); }
void test_odb_packed__initialize(void) { cl_git_pass(git_odb_open(&_odb, cl_fixture("testrepo.git/objects"))); }
static int init_odb(git_repository *repo) { return git_odb_open(&repo->db, repo->path_odb); }
"afadc73a392f8cc8e2cc77dd62a7433dd3bafa8c", "affd84ed8ec7ce67612fe3c12a80f8164b101f6a", "b0941f9c70ffe67f0387a827b338e64ecf3190f0", "b0a3077f9ef6e093f8d9869bdb0c07095bd722cb", "b0a8568a7614806378a54db5706ee3b06ae58693", "b0fb7372f242233d1d35ce7d8e74d3990cbc5841", "b10489944b9ead17427551759d180d10203e06ba", "b196a807b323f2748ffc6b1d42cd0812d04c9a40", "b1bb1d888f0c5e19278536d49fa77db035fac7ae" }; BEGIN_TEST(readpacked_test) unsigned int i; git_odb *db; must_pass(git_odb_open(&db, ODB_FOLDER)); for (i = 0; i < ARRAY_SIZE(packed_objects); ++i) { git_oid id; git_rawobj obj; must_pass(git_oid_mkstr(&id, packed_objects[i])); must_be_true(git_odb_exists(db, &id) == 1); must_pass(git_odb_read(&obj, db, &id)); git_rawobj_close(&obj); } git_odb_close(db); END_TEST
sizeof(some_bytes), "fd8430bc864cfcd5f10e5590f8a447e01b942bfe", "blob", "test-objects/fd", "test-objects/fd/8430bc864cfcd5f10e5590f8a447e01b942bfe", some_data, sizeof(some_data), }; BEGIN_TEST(read_loose_commit) git_odb *db; git_oid id; git_obj obj; must_pass(write_object_files(odb_dir, &commit)); must_pass(git_odb_open(&db, odb_dir)); must_pass(git_oid_mkstr(&id, commit.id)); must_pass(git_odb__read_loose(&obj, db, &id)); must_pass(cmp_objects(&obj, &commit)); git_obj_close(&obj); git_odb_close(db); must_pass(remove_object_files(odb_dir, &commit)); END_TEST BEGIN_TEST(read_loose_tree) git_odb *db; git_oid id; git_obj obj;