2 * export-cmd.c -- Subversion export 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_error.h"
32 #include "svn_dirent_uri.h"
36 #include "svn_private_config.h"
37 #include "private/svn_opt_private.h"
42 /* This implements the `svn_opt_subcommand_t' interface. */
44 svn_cl__export(apr_getopt_t *os,
48 svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
49 svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
50 const char *from, *to;
51 apr_array_header_t *targets;
53 svn_opt_revision_t peg_revision;
55 struct svn_cl__check_externals_failed_notify_baton nwb;
57 SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
61 /* We want exactly 1 or 2 targets for this subcommand. */
62 if (targets->nelts < 1)
63 return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);
64 if (targets->nelts > 2)
65 return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, 0, NULL);
67 /* The first target is the `from' path. */
68 from = APR_ARRAY_IDX(targets, 0, const char *);
70 /* Get the peg revision if present. */
71 SVN_ERR(svn_opt_parse_path(&peg_revision, &truefrom, from, pool));
73 /* If only one target was given, split off the basename to use as
74 the `to' path. Else, a `to' path was supplied. */
75 if (targets->nelts == 1)
77 if (svn_path_is_url(truefrom))
78 to = svn_uri_basename(truefrom, pool);
80 to = svn_dirent_basename(truefrom, pool);
84 to = APR_ARRAY_IDX(targets, 1, const char *);
86 if (strcmp("", to) != 0)
87 /* svn_cl__eat_peg_revisions() but only on one target */
91 SVN_ERR(svn_opt__split_arg_at_peg_revision(&to, &peg, to, pool));
93 return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
94 _("'%s': a peg revision is not allowed here"),
95 APR_ARRAY_IDX(targets, 1, const char *));
99 SVN_ERR(svn_cl__check_target_is_local_path(to));
101 if (! opt_state->quiet)
102 SVN_ERR(svn_cl__notifier_mark_export(ctx->notify_baton2));
104 if (opt_state->depth == svn_depth_unknown)
105 opt_state->depth = svn_depth_infinity;
107 nwb.wrapped_func = ctx->notify_func2;
108 nwb.wrapped_baton = ctx->notify_baton2;
109 nwb.had_externals_error = FALSE;
110 ctx->notify_func2 = svn_cl__check_externals_failed_notify_wrapper;
111 ctx->notify_baton2 = &nwb;
114 err = svn_client_export5(NULL, truefrom, to, &peg_revision,
115 &(opt_state->start_revision),
116 opt_state->force, opt_state->ignore_externals,
117 opt_state->ignore_keywords, opt_state->depth,
118 opt_state->native_eol, ctx, pool);
119 if (err && err->apr_err == SVN_ERR_WC_OBSTRUCTED_UPDATE && !opt_state->force)
121 _("Destination directory exists; please remove "
122 "the directory or use --force to overwrite"));
124 if (nwb.had_externals_error)
126 svn_error_t *externals_err;
128 externals_err = svn_error_create(SVN_ERR_CL_ERROR_PROCESSING_EXTERNALS,
130 _("Failure occurred processing one or "
131 "more externals definitions"));
132 return svn_error_compose_create(externals_err, err);
135 return svn_error_trace(err);