#include "svn_error.h"
#include "svn_client.h"
#include "svn_pools.h"
#include "utils.h"
#include "../svn_test_fs.h"
#include "../../libsvn_wc/wc.h"
#include "../../libsvn_wc/wc-queries.h"
#define SVN_WC__I_AM_WC_DB
#include "../../libsvn_wc/wc_db_private.h"
static svn_error_t *
create_repos_and_wc(const char **repos_url,
const char **wc_abspath,
const char *test_name,
const svn_test_opts_t *opts,
apr_pool_t *pool)
{
const char *repos_path = svn_relpath_join(REPOSITORIES_WORK_DIR, test_name,
pool);
const char *wc_path = svn_relpath_join(WCS_WORK_DIR, test_name, pool);
SVN_ERR(svn_io_remove_dir2(repos_path, TRUE, NULL, NULL, pool));
SVN_ERR(svn_io_remove_dir2(wc_path, TRUE, NULL, NULL, pool));
SVN_ERR(svn_io_make_dir_recursively(REPOSITORIES_WORK_DIR, pool));
SVN_ERR(svn_io_make_dir_recursively(WCS_WORK_DIR, pool));
{
svn_repos_t *repos;
apr_pool_t *subpool = svn_pool_create(pool);
SVN_ERR(svn_test__create_repos(&repos, repos_path, opts, subpool));
SVN_ERR(svn_uri_get_file_url_from_dirent(repos_url, repos_path, pool));
svn_pool_destroy(subpool);
}
{
svn_client_ctx_t *ctx;
svn_opt_revision_t head_rev = { svn_opt_revision_head, {0} };
SVN_ERR(svn_client_create_context(&ctx, pool));
SVN_ERR(svn_dirent_get_absolute(wc_abspath, wc_path, pool));
SVN_ERR(svn_client_checkout3(NULL, *repos_url, *wc_abspath,
&head_rev, &head_rev, svn_depth_infinity,
FALSE ,
FALSE ,
ctx, pool));
}
svn_test_add_dir_cleanup(*wc_abspath);
return SVN_NO_ERROR;
}
WC_QUERIES_SQL_DECLARE_STATEMENTS(statements);
svn_error_t *
svn_test__create_fake_wc(const char *wc_abspath,
const char *extra_statements,
apr_pool_t *result_pool,
apr_pool_t *scratch_pool)
{
const char *dotsvn_abspath = svn_dirent_join(wc_abspath, ".svn",
scratch_pool);
const char *db_abspath = svn_dirent_join(dotsvn_abspath, "wc.db",
scratch_pool);
svn_sqlite__db_t *sdb;
const char **my_statements;
int i;
my_statements = apr_palloc(result_pool, 6 * sizeof(const char *));
my_statements[0] = statements[STMT_CREATE_SCHEMA];
my_statements[1] = statements[STMT_CREATE_NODES];
my_statements[2] = statements[STMT_CREATE_NODES_TRIGGERS];
my_statements[3] = statements[STMT_CREATE_EXTERNALS];
my_statements[4] = extra_statements;
my_statements[5] = NULL;
SVN_ERR(svn_io_make_dir_recursively(dotsvn_abspath, scratch_pool));
svn_error_clear(svn_io_remove_file2(db_abspath, FALSE, scratch_pool));
SVN_ERR(svn_wc__db_util_open_db(&sdb, wc_abspath, "wc.db",
svn_sqlite__mode_rwcreate, my_statements,
result_pool, scratch_pool));
for (i = 0; my_statements[i] != NULL; i++)
SVN_ERR(svn_sqlite__exec_statements(sdb, i));
return SVN_NO_ERROR;
}
svn_error_t *
svn_test__sandbox_create(svn_test__sandbox_t *sandbox,
const char *test_name,
const svn_test_opts_t *opts,
apr_pool_t *pool)
{
sandbox->pool = pool;
SVN_ERR(create_repos_and_wc(&sandbox->repos_url, &sandbox->wc_abspath,
test_name, opts, pool));
SVN_ERR(svn_wc_context_create(&sandbox->wc_ctx, NULL, pool, pool));
return SVN_NO_ERROR;
}