2
* switch-cmd.c -- Bring work tree in sync with a different URL
4
* ====================================================================
5
* Copyright (c) 2000-2004 CollabNet. All rights reserved.
7
* This software is licensed as described in the file COPYING, which
8
* you should have received as part of this distribution. The terms
9
* are also available at http://subversion.tigris.org/license-1.html.
10
* If newer versions of this license are posted there, you may use a
11
* newer version instead, at your option.
13
* This software consists of voluntary contributions made by many
14
* individuals. For exact contribution history, see the revision
15
* history and logs, available at http://subversion.tigris.org/.
16
* ====================================================================
19
/* ==================================================================== */
26
#include "svn_client.h"
28
#include "svn_error.h"
29
#include "svn_pools.h"
32
#include "svn_private_config.h"
37
rewrite_urls(apr_array_header_t *targets,
38
svn_boolean_t recurse,
39
svn_client_ctx_t *ctx,
47
if (targets->nelts < 2)
48
return svn_error_create (SVN_ERR_CL_ARG_PARSING_ERROR, 0, NULL);
50
from = ((const char **) (targets->elts))[0];
51
to = ((const char **) (targets->elts))[1];
53
/* "--relocate http https" and "--relocate http://foo svn://bar" are OK,
54
but things like "--relocate http://foo svn" are not */
55
if (svn_path_is_url (from) != svn_path_is_url (to))
56
return svn_error_createf
57
(SVN_ERR_INCORRECT_PARAMS, NULL,
58
_("'%s' to '%s' is not a valid relocation"), from, to);
60
subpool = svn_pool_create (pool);
62
if (targets->nelts == 2)
64
SVN_ERR(svn_client_relocate ("", from, to, recurse, ctx, pool));
68
for (i = 2; i < targets->nelts; i++)
70
const char *target = ((const char **) (targets->elts))[i];
71
svn_pool_clear (subpool);
72
SVN_ERR (svn_client_relocate (target, from, to, recurse,
77
svn_pool_destroy (subpool);
82
/* This implements the `svn_opt_subcommand_t' interface. */
84
svn_cl__switch (apr_getopt_t *os,
88
svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
89
svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
90
apr_array_header_t *targets;
91
const char *target = NULL, *switch_url = NULL;
92
svn_wc_adm_access_t *adm_access;
93
const svn_wc_entry_t *entry;
94
const char *parent_dir, *base_tgt;
96
/* This command should discover (or derive) exactly two cmdline
97
arguments: a local path to update ("target"), and a new url to
98
switch to ("switch_url"). */
99
SVN_ERR (svn_opt_args_to_target_array2 (&targets, os,
100
opt_state->targets, pool));
102
/* handle only-rewrite case specially */
103
if (opt_state->relocate)
104
return rewrite_urls (targets, !opt_state->nonrecursive, ctx, pool);
106
if ((targets->nelts < 1) || (targets->nelts > 2))
107
return svn_error_create (SVN_ERR_CL_ARG_PARSING_ERROR, 0, NULL);
109
/* Get the required SWITCH_URL and the optional TARGET arguments. */
110
if (targets->nelts == 1)
112
switch_url = ((const char **) (targets->elts))[0];
117
switch_url = ((const char **) (targets->elts))[0];
118
target = ((const char **) (targets->elts))[1];
121
/* Validate the switch_url */
122
if (! svn_path_is_url (switch_url))
123
return svn_error_createf
124
(SVN_ERR_BAD_URL, NULL,
125
_("'%s' does not appear to be a URL"), switch_url);
127
/* Canonicalize the URL. */
128
switch_url = svn_path_canonicalize (switch_url, pool);
130
/* Validate the target */
131
SVN_ERR (svn_wc_adm_probe_open3 (&adm_access, NULL, target, FALSE, 0,
132
ctx->cancel_func, ctx->cancel_baton,
134
SVN_ERR (svn_wc_entry (&entry, target, adm_access, FALSE, pool));
136
return svn_error_createf
137
(SVN_ERR_ENTRY_NOT_FOUND, NULL,
138
_("'%s' does not appear to be a working copy path"), target);
140
/* We want the switch to print the same letters as a regular update. */
141
if (entry->kind == svn_node_file)
142
SVN_ERR (svn_wc_get_actual_target (target, &parent_dir, &base_tgt, pool));
143
else if (entry->kind == svn_node_dir)
146
if (! opt_state->quiet)
147
svn_cl__get_notifier (&ctx->notify_func2, &ctx->notify_baton2, FALSE,
150
/* Do the 'switch' update. */
151
SVN_ERR (svn_client_switch (NULL, target, switch_url,
152
&(opt_state->start_revision),
153
opt_state->nonrecursive ? FALSE : TRUE,