Followup to r29625: fix getopt tests.
[svn.git] / subversion / svn / export-cmd.c
blob1a6c1c682ec21acae37cf5ef463e99e93be0fde5
1 /*
2 * export-cmd.c -- Subversion export command
4 * ====================================================================
5 * Copyright (c) 2000-2004 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_error.h"
27 #include "svn_path.h"
28 #include "cl.h"
30 #include "svn_private_config.h"
33 /*** Code. ***/
35 /* This implements the `svn_opt_subcommand_t' interface. */
36 svn_error_t *
37 svn_cl__export(apr_getopt_t *os,
38 void *baton,
39 apr_pool_t *pool)
41 svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
42 svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
43 const char *from, *to;
44 apr_array_header_t *targets;
45 svn_error_t *err;
46 svn_opt_revision_t peg_revision;
47 const char *truefrom;
49 SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
50 opt_state->targets,
51 pool));
53 /* We want exactly 1 or 2 targets for this subcommand. */
54 if (targets->nelts < 1)
55 return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);
56 if (targets->nelts > 2)
57 return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, 0, NULL);
59 /* The first target is the `from' path. */
60 from = APR_ARRAY_IDX(targets, 0, const char *);
62 /* Get the peg revision if present. */
63 SVN_ERR(svn_opt_parse_path(&peg_revision, &truefrom, from, pool));
65 /* If only one target was given, split off the basename to use as
66 the `to' path. Else, a `to' path was supplied. */
67 if (targets->nelts == 1)
68 to = svn_path_uri_decode(svn_path_basename(truefrom, pool), pool);
69 else
70 to = APR_ARRAY_IDX(targets, 1, const char *);
72 if (! opt_state->quiet)
73 svn_cl__get_notifier(&ctx->notify_func2, &ctx->notify_baton2, FALSE, TRUE,
74 FALSE, pool);
76 if (opt_state->depth == svn_depth_unknown)
77 opt_state->depth = svn_depth_infinity;
79 /* Do the export. */
80 err = svn_client_export4(NULL, truefrom, to, &peg_revision,
81 &(opt_state->start_revision),
82 opt_state->force, opt_state->ignore_externals,
83 opt_state->depth,
84 opt_state->native_eol, ctx,
85 pool);
86 if (err && err->apr_err == SVN_ERR_WC_OBSTRUCTED_UPDATE && !opt_state->force)
87 SVN_ERR_W(err,
88 _("Destination directory exists; please remove "
89 "the directory or use --force to overwrite"));
90 else
91 SVN_ERR(err);
93 return SVN_NO_ERROR;