2 * copy-cmd.c -- Subversion copy command
4 * ====================================================================
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
21 * ====================================================================
24 /* ==================================================================== */
30 #include "svn_client.h"
32 #include "svn_error.h"
35 #include "svn_private_config.h"
40 /* This implements the `svn_opt_subcommand_t' interface. */
42 svn_cl__copy(apr_getopt_t *os,
46 svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
47 svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
48 apr_array_header_t *targets, *sources;
49 const char *src_path, *dst_path;
50 svn_boolean_t srcs_are_urls, dst_is_url;
54 SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
57 if (targets->nelts < 2)
58 return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);
60 /* Get the src list and associated peg revs */
61 sources = apr_array_make(pool, targets->nelts - 1,
62 sizeof(svn_client_copy_source_t *));
63 for (i = 0; i < (targets->nelts - 1); i++)
65 const char *target = APR_ARRAY_IDX(targets, i, const char *);
66 svn_client_copy_source_t *source = apr_palloc(pool, sizeof(*source));
68 svn_opt_revision_t *peg_revision = apr_palloc(pool,
69 sizeof(*peg_revision));
71 err = svn_opt_parse_path(peg_revision, &src, target, pool);
75 /* Issue #3606: 'svn cp .@HEAD target' gives
76 svn: '@HEAD' is just a peg revision. Maybe try '@HEAD@' instead?
78 This is caused by a first round of canonicalization in
79 svn_cl__args_to_target_array_print_reserved(). Undo that in an
80 attempt to fix this issue without revving many apis.
82 if (*target == '@' && err->apr_err == SVN_ERR_BAD_FILENAME)
86 err2 = svn_opt_parse_path(peg_revision, &src,
87 apr_pstrcat(pool, ".", target,
88 (const char *)NULL), pool);
92 /* Fix attempt failed; return original error */
93 svn_error_clear(err2);
97 /* Error resolved. Use path */
104 return svn_error_trace(err);
108 source->revision = &(opt_state->start_revision);
109 source->peg_revision = peg_revision;
111 APR_ARRAY_PUSH(sources, svn_client_copy_source_t *) = source;
114 /* Get DST_PATH (the target path or URL) and check that no peg revision is
115 * specified for it. */
117 const char *tgt = APR_ARRAY_IDX(targets, targets->nelts - 1, const char *);
118 svn_opt_revision_t peg;
120 SVN_ERR(svn_opt_parse_path(&peg, &dst_path, tgt, pool));
121 if (peg.kind != svn_opt_revision_unspecified)
122 return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
123 _("'%s': a peg revision is not allowed here"),
127 /* Figure out which type of notification to use.
128 (There is no need to check that the src paths are homogeneous;
129 svn_client_copy6() through its subroutine try_copy() will return an
130 error if they are not.) */
131 src_path = APR_ARRAY_IDX(targets, 0, const char *);
132 srcs_are_urls = svn_path_is_url(src_path);
133 dst_is_url = svn_path_is_url(dst_path);
135 if ((! srcs_are_urls) && (! dst_is_url))
139 else if ((! srcs_are_urls) && (dst_is_url))
141 /* WC->URL : Use notification. */
142 if (! opt_state->quiet)
143 SVN_ERR(svn_cl__notifier_mark_wc_to_repos_copy(ctx->notify_baton2));
145 else if ((srcs_are_urls) && (! dst_is_url))
147 /* URL->WC : Use checkout-style notification. */
148 if (! opt_state->quiet)
149 SVN_ERR(svn_cl__notifier_mark_checkout(ctx->notify_baton2));
158 ctx->log_msg_func3 = NULL;
159 if (opt_state->message || opt_state->filedata || opt_state->revprop_table)
160 return svn_error_create
161 (SVN_ERR_CL_UNNECESSARY_LOG_MESSAGE, NULL,
162 _("Local, non-commit operations do not take a log message "
163 "or revision properties"));
166 if (ctx->log_msg_func3)
167 SVN_ERR(svn_cl__make_log_msg_baton(&(ctx->log_msg_baton3), opt_state,
168 NULL, ctx->config, pool));
170 err = svn_client_copy7(sources, dst_path, TRUE,
171 opt_state->parents, opt_state->ignore_externals,
172 FALSE /* metadata_only */,
173 opt_state->pin_externals,
174 NULL, /* pin all externals */
175 opt_state->revprop_table,
176 (opt_state->quiet ? NULL : svn_cl__print_commit_info),
180 if (ctx->log_msg_func3)
181 SVN_ERR(svn_cl__cleanup_log_msg(ctx->log_msg_baton3, err, pool));
183 return svn_error_trace(err);