#include "svn_wc.h"
#include "svn_client.h"
#include "svn_dirent_uri.h"
#include "svn_path.h"
#include "svn_error.h"
#include "svn_pools.h"
#include "cl.h"
#include "svn_private_config.h"
svn_error_t *
svn_cl__relocate(apr_getopt_t *os,
void *baton,
apr_pool_t *scratch_pool)
{
svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
svn_boolean_t ignore_externals = opt_state->ignore_externals;
apr_array_header_t *targets;
const char *from = NULL, *to = NULL, *path;
SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
opt_state->targets,
ctx, FALSE,
scratch_pool));
if (targets->nelts < 1)
return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);
if ((targets->nelts == 1) ||
((targets->nelts == 2)
&& (svn_path_is_url(APR_ARRAY_IDX(targets, 0, const char *)))
&& (! svn_path_is_url(APR_ARRAY_IDX(targets, 1, const char *)))))
{
to = APR_ARRAY_IDX(targets, 0, const char *);
path = (targets->nelts == 2) ? APR_ARRAY_IDX(targets, 1, const char *)
: "";
SVN_ERR(svn_client_url_from_path2(&from, path, ctx,
scratch_pool, scratch_pool));
SVN_ERR(svn_client_relocate2(path, from, to, ignore_externals,
ctx, scratch_pool));
}
else
{
from = APR_ARRAY_IDX(targets, 0, const char *);
to = APR_ARRAY_IDX(targets, 1, const char *);
if (targets->nelts == 2)
{
SVN_ERR(svn_client_relocate2("", from, to, ignore_externals,
ctx, scratch_pool));
}
else
{
apr_pool_t *subpool = svn_pool_create(scratch_pool);
int i;
for (i = 2; i < targets->nelts; i++)
{
path = APR_ARRAY_IDX(targets, i, const char *);
SVN_ERR(svn_cl__check_target_is_local_path(path));
}
for (i = 2; i < targets->nelts; i++)
{
svn_pool_clear(subpool);
path = APR_ARRAY_IDX(targets, i, const char *);
SVN_ERR(svn_client_relocate2(path, from, to, ignore_externals,
ctx, subpool));
}
svn_pool_destroy(subpool);
}
}
return SVN_NO_ERROR;
}