]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/subversion/subversion/svn/export-cmd.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / subversion / subversion / svn / export-cmd.c
1 /*
2  * export-cmd.c -- Subversion export command
3  *
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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
20  *    under the License.
21  * ====================================================================
22  */
23
24 /* ==================================================================== */
25
26
27 \f
28 /*** Includes. ***/
29
30 #include "svn_client.h"
31 #include "svn_error.h"
32 #include "svn_dirent_uri.h"
33 #include "svn_path.h"
34 #include "cl.h"
35
36 #include "svn_private_config.h"
37 #include "private/svn_opt_private.h"
38
39 \f
40 /*** Code. ***/
41
42 /* This implements the `svn_opt_subcommand_t' interface. */
43 svn_error_t *
44 svn_cl__export(apr_getopt_t *os,
45                void *baton,
46                apr_pool_t *pool)
47 {
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;
52   svn_error_t *err;
53   svn_opt_revision_t peg_revision;
54   const char *truefrom;
55   struct svn_cl__check_externals_failed_notify_baton nwb;
56
57   SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
58                                                       opt_state->targets,
59                                                       ctx, FALSE, pool));
60
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);
66
67   /* The first target is the `from' path. */
68   from = APR_ARRAY_IDX(targets, 0, const char *);
69
70   /* Get the peg revision if present. */
71   SVN_ERR(svn_opt_parse_path(&peg_revision, &truefrom, from, pool));
72
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)
76     {
77       if (svn_path_is_url(truefrom))
78         to = svn_uri_basename(truefrom, pool);
79       else
80         to = svn_dirent_basename(truefrom, pool);
81     }
82   else
83     {
84       to = APR_ARRAY_IDX(targets, 1, const char *);
85
86       if (strcmp("", to) != 0)
87         /* svn_cl__eat_peg_revisions() but only on one target */
88         SVN_ERR(svn_opt__split_arg_at_peg_revision(&to, NULL, to, pool));
89     }
90
91   SVN_ERR(svn_cl__check_target_is_local_path(to));
92
93   if (! opt_state->quiet)
94     SVN_ERR(svn_cl__notifier_mark_export(ctx->notify_baton2));
95
96   if (opt_state->depth == svn_depth_unknown)
97     opt_state->depth = svn_depth_infinity;
98
99   nwb.wrapped_func = ctx->notify_func2;
100   nwb.wrapped_baton = ctx->notify_baton2;
101   nwb.had_externals_error = FALSE;
102   ctx->notify_func2 = svn_cl__check_externals_failed_notify_wrapper;
103   ctx->notify_baton2 = &nwb;
104
105   /* Do the export. */
106   err = svn_client_export5(NULL, truefrom, to, &peg_revision,
107                            &(opt_state->start_revision),
108                            opt_state->force, opt_state->ignore_externals,
109                            opt_state->ignore_keywords, opt_state->depth,
110                            opt_state->native_eol, ctx, pool);
111   if (err && err->apr_err == SVN_ERR_WC_OBSTRUCTED_UPDATE && !opt_state->force)
112     SVN_ERR_W(err,
113               _("Destination directory exists; please remove "
114                 "the directory or use --force to overwrite"));
115
116   if (nwb.had_externals_error)
117     {
118       svn_error_t *externals_err;
119
120       externals_err = svn_error_create(SVN_ERR_CL_ERROR_PROCESSING_EXTERNALS,
121                                        NULL,
122                                        _("Failure occurred processing one or "
123                                          "more externals definitions"));
124       return svn_error_compose_create(externals_err, err);
125     }
126
127   return svn_error_trace(err);
128 }