export-cmd.c revision 299742
150472Speter/* 24974Sache * export-cmd.c -- Subversion export command 3203920Suqs * 4203920Suqs * ==================================================================== 5203920Suqs * Licensed to the Apache Software Foundation (ASF) under one 6203920Suqs * or more contributor license agreements. See the NOTICE file 74974Sache * distributed with this work for additional information 84974Sache * 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 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 40/*** Code. ***/ 41 42/* This implements the `svn_opt_subcommand_t' interface. */ 43svn_error_t * 44svn_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 { 89 const char *peg; 90 91 SVN_ERR(svn_opt__split_arg_at_peg_revision(&to, &peg, to, pool)); 92 if (peg[0] && peg[1]) 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 *)); 96 } 97 } 98 99 SVN_ERR(svn_cl__check_target_is_local_path(to)); 100 101 if (! opt_state->quiet) 102 SVN_ERR(svn_cl__notifier_mark_export(ctx->notify_baton2)); 103 104 if (opt_state->depth == svn_depth_unknown) 105 opt_state->depth = svn_depth_infinity; 106 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; 112 113 /* Do the export. */ 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) 120 SVN_ERR_W(err, 121 _("Destination directory exists; please remove " 122 "the directory or use --force to overwrite")); 123 124 if (nwb.had_externals_error) 125 { 126 svn_error_t *externals_err; 127 128 externals_err = svn_error_create(SVN_ERR_CL_ERROR_PROCESSING_EXTERNALS, 129 NULL, 130 _("Failure occurred processing one or " 131 "more externals definitions")); 132 return svn_error_compose_create(externals_err, err); 133 } 134 135 return svn_error_trace(err); 136} 137