2 * checkout-cmd.c -- Subversion checkout 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"
31 #include "svn_dirent_uri.h"
33 #include "svn_error.h"
34 #include "svn_pools.h"
37 #include "svn_private_config.h"
46 $ svn co http://host/repos/module
47 checkout into ./module/
49 - case 2: one URL and explicit path
50 $ svn co http://host/repos/module path
53 - case 3: multiple URLs
54 $ svn co http://host1/repos1/module1 http://host2/repos2/module2
55 checkout into ./module1/ and ./module2/
57 - case 4: multiple URLs and explicit path
58 $ svn co http://host1/repos1/module1 http://host2/repos2/module2 path
59 checkout into ./path/module1/ and ./path/module2/
61 Is this the same as CVS? Does it matter if it is not?
65 /* This implements the `svn_opt_subcommand_t' interface. */
67 svn_cl__checkout(apr_getopt_t *os,
71 svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
72 svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
74 apr_array_header_t *targets;
75 struct svn_cl__check_externals_failed_notify_baton nwb;
76 const char *last_target, *local_dir;
79 SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
84 return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, NULL, NULL);
86 /* Determine LOCAL_DIR (case 1: URL basename; 2,4: specified; 3: "")
87 * and leave TARGETS holding just the source URLs. */
88 last_target = APR_ARRAY_IDX(targets, targets->nelts - 1, const char *);
89 if (svn_path_is_url(last_target))
91 if (targets->nelts == 1)
93 svn_opt_revision_t pegrev;
95 /* Use the URL basename, discarding any peg revision. */
96 SVN_ERR(svn_opt_parse_path(&pegrev, &local_dir, last_target, pool));
97 local_dir = svn_uri_basename(local_dir, pool);
106 if (targets->nelts == 1)
107 /* What? They gave us one target, and it wasn't a URL. */
108 return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL, NULL);
110 apr_array_pop(targets);
111 local_dir = last_target;
114 if (! opt_state->quiet)
115 SVN_ERR(svn_cl__notifier_mark_checkout(ctx->notify_baton2));
117 nwb.wrapped_func = ctx->notify_func2;
118 nwb.wrapped_baton = ctx->notify_baton2;
119 nwb.had_externals_error = FALSE;
120 ctx->notify_func2 = svn_cl__check_externals_failed_notify_wrapper;
121 ctx->notify_baton2 = &nwb;
123 subpool = svn_pool_create(pool);
124 for (i = 0; i < targets->nelts; ++i)
126 const char *repos_url = APR_ARRAY_IDX(targets, i, const char *);
127 const char *target_dir;
128 const char *true_url;
129 svn_opt_revision_t revision = opt_state->start_revision;
130 svn_opt_revision_t peg_revision;
132 svn_pool_clear(subpool);
134 SVN_ERR(svn_cl__check_cancel(ctx->cancel_baton));
136 /* Validate the REPOS_URL */
137 if (! svn_path_is_url(repos_url))
138 return svn_error_createf
139 (SVN_ERR_BAD_URL, NULL,
140 _("'%s' does not appear to be a URL"), repos_url);
142 /* Get a possible peg revision. */
143 SVN_ERR(svn_opt_parse_path(&peg_revision, &true_url, repos_url,
146 /* Use sub-directory of destination if checking-out multiple URLs */
147 if (targets->nelts == 1)
149 target_dir = local_dir;
153 target_dir = svn_dirent_join(local_dir,
154 svn_uri_basename(true_url, subpool),
158 /* Checkout doesn't accept an unspecified revision, so default to
159 the peg revision, or to HEAD if there wasn't a peg. */
160 if (revision.kind == svn_opt_revision_unspecified)
162 if (peg_revision.kind != svn_opt_revision_unspecified)
163 revision = peg_revision;
165 revision.kind = svn_opt_revision_head;
168 SVN_ERR(svn_client_checkout3
169 (NULL, true_url, target_dir,
173 opt_state->ignore_externals,
177 svn_pool_destroy(subpool);
179 if (nwb.had_externals_error)
180 return svn_error_create(SVN_ERR_CL_ERROR_PROCESSING_EXTERNALS, NULL,
181 _("Failure occurred processing one or "
182 "more externals definitions"));