int git_odb_open(git_odb **out, const char *objects_dir) { git_odb *db; int error; assert(out && objects_dir); *out = NULL; if ((error = git_odb_new(&db)) < 0) return error; if ((error = add_default_backends(db, objects_dir, 0)) < GIT_SUCCESS) goto cleanup; if ((error = load_alternates(db, objects_dir)) < GIT_SUCCESS) goto cleanup; *out = db; return GIT_SUCCESS; cleanup: git_odb_close(db); return error; }
void test_write_object_permission( mode_t dir_mode, mode_t file_mode, mode_t expected_dir_mode, mode_t expected_file_mode) { git_odb *odb; git_odb_backend *backend; git_oid oid; struct stat statbuf; mode_t mask, os_mask; /* Windows does not return group/user bits from stat, * files are never executable. */ #ifdef GIT_WIN32 os_mask = 0600; #else os_mask = 0777; #endif mask = p_umask(0); p_umask(mask); cl_git_pass(git_odb_new(&odb)); cl_git_pass(git_odb_backend_loose(&backend, "test-objects", -1, 0, dir_mode, file_mode)); cl_git_pass(git_odb_add_backend(odb, backend, 1)); cl_git_pass(git_odb_write(&oid, odb, "Test data\n", 10, GIT_OBJECT_BLOB)); cl_git_pass(p_stat("test-objects/67", &statbuf)); cl_assert_equal_i(statbuf.st_mode & os_mask, (expected_dir_mode & ~mask) & os_mask); cl_git_pass(p_stat("test-objects/67/b808feb36201507a77f85e6d898f0a2836e4a5", &statbuf)); cl_assert_equal_i(statbuf.st_mode & os_mask, (expected_file_mode & ~mask) & os_mask); git_odb_free(odb); }
static void write_object_to_loose_odb(int fsync) { git_odb *odb; git_odb_backend *backend; git_oid oid; cl_git_pass(git_odb_new(&odb)); cl_git_pass(git_odb_backend_loose(&backend, "test-objects", -1, fsync, 0777, 0666)); cl_git_pass(git_odb_add_backend(odb, backend, 1)); cl_git_pass(git_odb_write(&oid, odb, "Test data\n", 10, GIT_OBJECT_BLOB)); git_odb_free(odb); }
void test_odb_foreach__one_pack(void) { git_odb_backend *backend = NULL; cl_git_pass(git_odb_new(&_odb)); cl_git_pass(git_odb_backend_one_pack(&backend, cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"))); cl_git_pass(git_odb_add_backend(_odb, backend, 1)); _repo = NULL; nobj = 0; cl_git_pass(git_odb_foreach(_odb, foreach_cb, NULL)); cl_assert(nobj == 1628); }
static git_odb *open_sqlite_odb(void) { git_odb *odb; git_odb_backend *sqlite; if (git_odb_new(&odb) < GIT_SUCCESS) return NULL; if (git_odb_backend_sqlite(&sqlite, ":memory") < GIT_SUCCESS) return NULL; if (git_odb_add_backend(odb, sqlite, 0) < GIT_SUCCESS) return NULL; return odb; }
static VALUE backend_initialize(VALUE rb_obj, VALUE mysql_host, VALUE mysql_user, VALUE mysql_passwd, VALUE mysql_db, VALUE mysql_table_name, VALUE mysql_storage_engine, VALUE mysql_port, VALUE mysql_unix_socket, VALUE mysql_client_flag) { git_odb *odb; git_odb_backend *backend; int error; char *error_msg; if (!FIXNUM_P(mysql_port)) { rb_raise(rb_eArgError, "MySQL port must be a Fixnum"); } if (!FIXNUM_P(mysql_client_flag)) { rb_raise(rb_eArgError, "MySQL client flag must be a Fixnum"); } error = git_odb_backend_mysql( &backend, StringValuePtr(mysql_host), StringValuePtr(mysql_user), StringValuePtr(mysql_passwd), StringValuePtr(mysql_db), StringValuePtr(mysql_table_name), StringValuePtr(mysql_storage_engine), FIX2INT(mysql_port), StringValuePtr(mysql_unix_socket), NUM2ULONG(mysql_client_flag), &error_msg); if (error != 0) { if (*error_msg == 0) { rb_raise(rb_eRuntimeError, "An error occurred when trying to connect to the database"); } else { rb_raise(rb_eRuntimeError, "%s", error_msg); } } git_odb_new(&odb); git_odb_add_backend(odb, backend, 10); DATA_PTR(rb_obj) = odb; return rb_obj; }
int git_odb_open(git_odb **out, const char *objects_dir) { git_odb *db; assert(out && objects_dir); *out = NULL; if (git_odb_new(&db) < 0) return -1; if (add_default_backends(db, objects_dir, 0, 0) < 0) { git_odb_free(db); return -1; } *out = db; return 0; }
static git_odb *open_sqlite_odb(void) { #ifdef GIT2_SQLITE_BACKEND git_odb *odb; git_odb_backend *sqlite; if (git_odb_new(&odb) < GIT_SUCCESS) return NULL; if (git_odb_backend_sqlite(&sqlite, ":memory") < GIT_SUCCESS) return NULL; if (git_odb_add_backend(odb, sqlite, 0) < GIT_SUCCESS) return NULL; return odb; #else return NULL; #endif }
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); /* The set increases the refcount and we don't want them anymore */ git_config_free(config); git_odb_free(odb); git_refdb_free(refdb); }
void test_odb_sorting__initialize(void) { cl_git_pass(git_odb_new(&_odb)); }