In the command-line client, forbid
[svn.git] / subversion / svn / checkout-cmd.c
blob64767fffc9d4069a68449880eeed30d9ac5e4046
1 /*
2 * checkout-cmd.c -- Subversion checkout command
4 * ====================================================================
5 * Copyright (c) 2000-2007 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 /* ==================================================================== */
23 /*** Includes. ***/
25 #include "svn_client.h"
26 #include "svn_path.h"
27 #include "svn_error.h"
28 #include "svn_pools.h"
29 #include "cl.h"
31 #include "svn_private_config.h"
34 /*** Code. ***/
37 This is what it does
39 - case 1: one URL
40 $ svn co http://host/repos/module
41 checkout into ./module/
43 - case 2: one URL and explicit path
44 $ svn co http://host/repos/module path
45 checkout into ./path/
47 - case 3: multiple URLs
48 $ svn co http://host1/repos1/module1 http://host2/repos2/module2
49 checkout into ./module1/ and ./module2/
51 - case 4: multiple URLs and explicit path
52 $ svn co http://host1/repos1/module1 http://host2/repos2/module2 path
53 checkout into ./path/module1/ and ./path/module2/
55 Is this the same as CVS? Does it matter if it is not?
59 /* This implements the `svn_opt_subcommand_t' interface. */
60 svn_error_t *
61 svn_cl__checkout(apr_getopt_t *os,
62 void *baton,
63 apr_pool_t *pool)
65 svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
66 svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
67 apr_pool_t *subpool;
68 apr_array_header_t *targets;
69 const char *local_dir;
70 const char *repos_url;
71 int i;
73 SVN_ERR(svn_opt_args_to_target_array2(&targets, os,
74 opt_state->targets, pool));
76 if (! targets->nelts)
77 return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);
79 /* Add a path if the user only specified URLs */
80 local_dir = APR_ARRAY_IDX(targets, targets->nelts - 1, const char *);
81 if (svn_path_is_url(local_dir))
83 if (targets->nelts == 1)
85 svn_opt_revision_t pegrev;
87 /* Discard the peg-revision, if one was provided. */
88 SVN_ERR(svn_opt_parse_path(&pegrev, &local_dir, local_dir, pool));
89 if (pegrev.kind != svn_opt_revision_unspecified)
90 local_dir = svn_path_canonicalize(local_dir, pool);
92 local_dir = svn_path_basename(local_dir, pool);
93 local_dir = svn_path_uri_decode(local_dir, pool);
95 else
97 local_dir = "";
99 APR_ARRAY_PUSH(targets, const char *) = local_dir;
101 else
103 /* What? They gave us one target, and it wasn't a URL. */
104 if (targets->nelts == 1)
105 return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, 0, NULL);
108 if (! opt_state->quiet)
109 svn_cl__get_notifier(&ctx->notify_func2, &ctx->notify_baton2, TRUE, FALSE,
110 FALSE, pool);
112 subpool = svn_pool_create(pool);
113 for (i = 0; i < targets->nelts - 1; ++i)
115 const char *target_dir;
116 const char *true_url;
117 svn_opt_revision_t revision = opt_state->start_revision;
118 svn_opt_revision_t peg_revision;
120 svn_pool_clear(subpool);
122 SVN_ERR(svn_cl__check_cancel(ctx->cancel_baton));
124 /* Validate the REPOS_URL */
125 repos_url = APR_ARRAY_IDX(targets, i, const char *);
126 if (! svn_path_is_url(repos_url))
127 return svn_error_createf
128 (SVN_ERR_BAD_URL, NULL,
129 _("'%s' does not appear to be a URL"), repos_url);
131 /* Get a possible peg revision. */
132 SVN_ERR(svn_opt_parse_path(&peg_revision, &true_url, repos_url,
133 subpool));
135 true_url = svn_path_canonicalize(true_url, subpool);
137 /* Use sub-directory of destination if checking-out multiple URLs */
138 if (targets->nelts == 2)
140 target_dir = local_dir;
142 else
144 target_dir = svn_path_basename(true_url, subpool);
145 target_dir = svn_path_uri_decode(target_dir, subpool);
146 target_dir = svn_path_join(local_dir, target_dir, subpool);
149 /* Checkout doesn't accept an unspecified revision, so default to
150 the peg revision, or to HEAD if there wasn't a peg. */
151 if (revision.kind == svn_opt_revision_unspecified)
153 if (peg_revision.kind != svn_opt_revision_unspecified)
154 revision = peg_revision;
155 else
156 revision.kind = svn_opt_revision_head;
159 SVN_ERR(svn_client_checkout3
160 (NULL, true_url, target_dir,
161 &peg_revision,
162 &revision,
163 opt_state->depth,
164 opt_state->ignore_externals,
165 opt_state->force,
166 ctx, subpool));
168 svn_pool_destroy(subpool);
170 return SVN_NO_ERROR;