2 * relocate-cmd.c -- Update working tree administrative data to
3 * account for repository change-of-address.
5 * ====================================================================
6 * Licensed to the Apache Software Foundation (ASF) under one
7 * or more contributor license agreements. See the NOTICE file
8 * distributed with this work for additional information
9 * regarding copyright ownership. The ASF licenses this file
10 * to you under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance
12 * with the License. You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 * KIND, either express or implied. See the License for the
20 * specific language governing permissions and limitations
22 * ====================================================================
25 /* ==================================================================== */
32 #include "svn_client.h"
33 #include "svn_dirent_uri.h"
35 #include "svn_error.h"
36 #include "svn_pools.h"
39 #include "svn_private_config.h"
43 /* This implements the `svn_opt_subcommand_t' interface. */
45 svn_cl__relocate(apr_getopt_t *os,
47 apr_pool_t *scratch_pool)
49 svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
50 svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
51 svn_boolean_t ignore_externals = opt_state->ignore_externals;
52 apr_array_header_t *targets;
53 const char *from, *to, *path;
55 /* We've got two different syntaxes to support:
57 1. relocate FROM-PREFIX TO-PREFIX [PATH ...]
58 2. relocate TO-URL [PATH]
60 SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
64 if (targets->nelts < 1)
65 return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);
67 /* If we have a single target, we're in form #2. If we have two
68 targets and the first is a URL and the second is not, we're also
70 if ((targets->nelts == 1) ||
71 ((targets->nelts == 2)
72 && (svn_path_is_url(APR_ARRAY_IDX(targets, 0, const char *)))
73 && (! svn_path_is_url(APR_ARRAY_IDX(targets, 1, const char *)))))
76 to = APR_ARRAY_IDX(targets, 0, const char *);
77 path = (targets->nelts == 2) ? APR_ARRAY_IDX(targets, 1, const char *)
80 SVN_ERR(svn_client_url_from_path2(&from, path, ctx,
81 scratch_pool, scratch_pool));
82 SVN_ERR(svn_client_relocate2(path, from, to, ignore_externals,
85 /* ... Everything else is form #1. */
88 from = APR_ARRAY_IDX(targets, 0, const char *);
89 to = APR_ARRAY_IDX(targets, 1, const char *);
91 if (targets->nelts == 2)
93 SVN_ERR(svn_client_relocate2("", from, to, ignore_externals,
98 apr_pool_t *subpool = svn_pool_create(scratch_pool);
101 /* Target working copy root dir must be local. */
102 for (i = 2; i < targets->nelts; i++)
104 path = APR_ARRAY_IDX(targets, i, const char *);
105 SVN_ERR(svn_cl__check_target_is_local_path(path));
108 for (i = 2; i < targets->nelts; i++)
110 svn_pool_clear(subpool);
111 path = APR_ARRAY_IDX(targets, i, const char *);
112 SVN_ERR(svn_client_relocate2(path, from, to, ignore_externals,
115 svn_pool_destroy(subpool);