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 /* ==================================================================== */
25 #include "svn_client.h"
27 #include "svn_error.h"
28 #include "svn_pools.h"
31 #include "svn_private_config.h"
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
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. */
61 svn_cl__checkout(apr_getopt_t
*os
,
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
;
68 apr_array_header_t
*targets
;
69 const char *local_dir
;
70 const char *repos_url
;
73 SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets
, os
,
78 return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS
, 0, NULL
);
80 /* Add a path if the user only specified URLs */
81 local_dir
= APR_ARRAY_IDX(targets
, targets
->nelts
- 1, const char *);
82 if (svn_path_is_url(local_dir
))
84 if (targets
->nelts
== 1)
86 svn_opt_revision_t pegrev
;
88 /* Discard the peg-revision, if one was provided. */
89 SVN_ERR(svn_opt_parse_path(&pegrev
, &local_dir
, local_dir
, pool
));
90 if (pegrev
.kind
!= svn_opt_revision_unspecified
)
91 local_dir
= svn_path_canonicalize(local_dir
, pool
);
93 local_dir
= svn_path_basename(local_dir
, pool
);
94 local_dir
= svn_path_uri_decode(local_dir
, pool
);
100 APR_ARRAY_PUSH(targets
, const char *) = local_dir
;
104 /* What? They gave us one target, and it wasn't a URL. */
105 if (targets
->nelts
== 1)
106 return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR
, 0, NULL
);
109 if (! opt_state
->quiet
)
110 svn_cl__get_notifier(&ctx
->notify_func2
, &ctx
->notify_baton2
, TRUE
, FALSE
,
113 subpool
= svn_pool_create(pool
);
114 for (i
= 0; i
< targets
->nelts
- 1; ++i
)
116 const char *target_dir
;
117 const char *true_url
;
118 svn_opt_revision_t revision
= opt_state
->start_revision
;
119 svn_opt_revision_t peg_revision
;
121 svn_pool_clear(subpool
);
123 SVN_ERR(svn_cl__check_cancel(ctx
->cancel_baton
));
125 /* Validate the REPOS_URL */
126 repos_url
= APR_ARRAY_IDX(targets
, i
, const char *);
127 if (! svn_path_is_url(repos_url
))
128 return svn_error_createf
129 (SVN_ERR_BAD_URL
, NULL
,
130 _("'%s' does not appear to be a URL"), repos_url
);
132 /* Get a possible peg revision. */
133 SVN_ERR(svn_opt_parse_path(&peg_revision
, &true_url
, repos_url
,
136 true_url
= svn_path_canonicalize(true_url
, subpool
);
138 /* Use sub-directory of destination if checking-out multiple URLs */
139 if (targets
->nelts
== 2)
141 target_dir
= local_dir
;
145 target_dir
= svn_path_basename(true_url
, subpool
);
146 target_dir
= svn_path_uri_decode(target_dir
, subpool
);
147 target_dir
= svn_path_join(local_dir
, target_dir
, subpool
);
150 /* Checkout doesn't accept an unspecified revision, so default to
151 the peg revision, or to HEAD if there wasn't a peg. */
152 if (revision
.kind
== svn_opt_revision_unspecified
)
154 if (peg_revision
.kind
!= svn_opt_revision_unspecified
)
155 revision
= peg_revision
;
157 revision
.kind
= svn_opt_revision_head
;
160 SVN_ERR(svn_client_checkout3
161 (NULL
, true_url
, target_dir
,
165 opt_state
->ignore_externals
,
169 svn_pool_destroy(subpool
);