Ejemplo n.º 1
0
void test_odb_sorting__basic_backends_sorting(void)
{
	cl_git_pass(git_odb_add_backend(_odb, new_backend(0), 5));
	cl_git_pass(git_odb_add_backend(_odb, new_backend(2), 3));
	cl_git_pass(git_odb_add_backend(_odb, new_backend(1), 4));
	cl_git_pass(git_odb_add_backend(_odb, new_backend(3), 1));

	check_backend_sorting(_odb);
}
Ejemplo n.º 2
0
void test_odb_sorting__alternate_backends_sorting(void)
{
	cl_git_pass(git_odb_add_backend(_odb, new_backend(0), 5));
	cl_git_pass(git_odb_add_backend(_odb, new_backend(2), 3));
	cl_git_pass(git_odb_add_backend(_odb, new_backend(1), 4));
	cl_git_pass(git_odb_add_backend(_odb, new_backend(3), 1));
	cl_git_pass(git_odb_add_alternate(_odb, new_backend(4), 5));
	cl_git_pass(git_odb_add_alternate(_odb, new_backend(6), 3));
	cl_git_pass(git_odb_add_alternate(_odb, new_backend(5), 4));
	cl_git_pass(git_odb_add_alternate(_odb, new_backend(7), 1));

	check_backend_sorting(_odb);
}
Ejemplo n.º 3
0
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);
}
Ejemplo n.º 4
0
static void setup_backend(const fake_object *objs)
{
	git_odb_backend *backend;

	cl_git_pass(build_fake_backend(&backend, objs));

	cl_git_pass(git_repository_odb__weakptr(&_odb, _repo));
	cl_git_pass(git_odb_add_backend(_odb, backend, 10));
}
Ejemplo n.º 5
0
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);
}
Ejemplo n.º 6
0
int repository_create_memory_cb(git_repository **out, const char *path, int bare, void *payload) {
    git_odb *odb = NULL;
    git_odb_backend *odb_mem = NULL;
    int error;
    if (    (error = git_repository_init(out, path, bare)) ||
            (error = git_repository_odb(&odb, *out)) ||
            (error = git_odb_backend_memory(&odb_mem)) ||
            (error = git_odb_add_backend(odb, odb_mem, 999))) {
        // TODO: free?
        return error;
    }
    return GIT_OK;
}
Ejemplo n.º 7
0
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);
}
Ejemplo n.º 8
0
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;
}
Ejemplo n.º 9
0
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;
}
Ejemplo n.º 10
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
}
Ejemplo n.º 11
0
		fake_backend *internal = *((fake_backend **)git_vector_get(&odb->backends, i));

		if (internal == NULL)
			return GIT_ERROR;

		if (internal->position != (int)i)
			return GIT_ERROR;
	}

	return GIT_SUCCESS;
}

BEGIN_TEST(odb0, "assure that ODB backends are properly sorted")
	git_odb *odb;
	must_pass(git_odb_new(&odb));
	must_pass(git_odb_add_backend(odb, new_backend(0), 5));
	must_pass(git_odb_add_backend(odb, new_backend(2), 3));
	must_pass(git_odb_add_backend(odb, new_backend(1), 4));
	must_pass(git_odb_add_backend(odb, new_backend(3), 1));
	must_pass(test_backend_sorting(odb));
	git_odb_close(odb);
END_TEST

BEGIN_TEST(odb1, "assure that alternate backends are properly sorted")
	git_odb *odb;
	must_pass(git_odb_new(&odb));
	must_pass(git_odb_add_backend(odb, new_backend(0), 5));
	must_pass(git_odb_add_backend(odb, new_backend(2), 3));
	must_pass(git_odb_add_backend(odb, new_backend(1), 4));
	must_pass(git_odb_add_backend(odb, new_backend(3), 1));
	must_pass(git_odb_add_alternate(odb, new_backend(4), 5));