In the command-line client, forbid
[svn.git] / subversion / svn / propdel-cmd.c
blobfe9bdf47cebbbe4184f4b21b99020e928e4c8743
1 /*
2 * propdel-cmd.c -- Remove property from files/dirs
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 /* ==================================================================== */
23 /*** Includes. ***/
25 #include "svn_cmdline.h"
26 #include "svn_pools.h"
27 #include "svn_client.h"
28 #include "svn_error_codes.h"
29 #include "svn_error.h"
30 #include "svn_utf.h"
31 #include "svn_path.h"
32 #include "cl.h"
34 #include "svn_private_config.h"
37 /*** Code. ***/
39 /* This implements the `svn_opt_subcommand_t' interface. */
40 svn_error_t *
41 svn_cl__propdel(apr_getopt_t *os,
42 void *baton,
43 apr_pool_t *pool)
45 svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
46 svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
47 const char *pname, *pname_utf8;
48 apr_array_header_t *args, *targets;
49 apr_array_header_t *changelist_targets = NULL, *combined_targets = NULL;
50 int i;
52 /* Get the property's name (and a UTF-8 version of that name). */
53 SVN_ERR(svn_opt_parse_num_args(&args, os, 1, pool));
54 pname = APR_ARRAY_IDX(args, 0, const char *);
55 SVN_ERR(svn_utf_cstring_to_utf8(&pname_utf8, pname, pool));
56 /* No need to check svn_prop_name_is_valid for *deleting*
57 properties, and it may even be useful to allow, in case invalid
58 properties sneaked through somehow. */
60 /* Before allowing svn_opt_args_to_target_array2() to canonicalize
61 all the targets, we need to build a list of targets made of both
62 ones the user typed, as well as any specified by --changelist. */
63 if (opt_state->changelist)
65 SVN_ERR(svn_client_get_changelist(&changelist_targets,
66 opt_state->changelist,
67 "",
68 ctx,
69 pool));
70 if (apr_is_empty_array(changelist_targets))
71 return svn_error_createf(SVN_ERR_UNKNOWN_CHANGELIST, NULL,
72 _("Unknown changelist '%s'"),
73 opt_state->changelist);
76 if (opt_state->targets && changelist_targets)
77 combined_targets = apr_array_append(pool, opt_state->targets,
78 changelist_targets);
79 else if (opt_state->targets)
80 combined_targets = opt_state->targets;
81 else if (changelist_targets)
82 combined_targets = changelist_targets;
84 SVN_ERR(svn_opt_args_to_target_array2(&targets, os,
85 combined_targets, pool));
87 /* Add "." if user passed 0 file arguments */
88 svn_opt_push_implicit_dot_target(targets, pool);
90 if (opt_state->revprop) /* operate on a revprop */
92 svn_revnum_t rev;
93 const char *URL;
95 SVN_ERR(svn_cl__revprop_prepare(&opt_state->start_revision, targets,
96 &URL, pool));
98 /* Let libsvn_client do the real work. */
99 SVN_ERR(svn_client_revprop_set(pname_utf8, NULL,
100 URL, &(opt_state->start_revision),
101 &rev, FALSE, ctx, pool));
102 if (! opt_state->quiet)
104 SVN_ERR(svn_cmdline_printf(pool,
105 _("property '%s' deleted from"
106 " repository revision %ld\n"),
107 pname_utf8, rev));
110 else if (opt_state->start_revision.kind != svn_opt_revision_unspecified)
112 return svn_error_createf
113 (SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
114 _("Cannot specify revision for deleting versioned property '%s'"),
115 pname);
117 else /* operate on a normal, versioned property (not a revprop) */
119 apr_pool_t *subpool = svn_pool_create(pool);
121 if (opt_state->depth == svn_depth_unknown)
122 opt_state->depth = svn_depth_empty;
124 /* For each target, remove the property PNAME. */
125 for (i = 0; i < targets->nelts; i++)
127 const char *target = APR_ARRAY_IDX(targets, i, const char *);
128 svn_commit_info_t *commit_info;
129 svn_boolean_t success;
131 svn_pool_clear(subpool);
132 SVN_ERR(svn_cl__check_cancel(ctx->cancel_baton));
134 /* Pass FALSE for 'skip_checks' because it doesn't matter here,
135 and opt_state->force doesn't apply to this command anyway. */
136 SVN_ERR(svn_cl__try(svn_client_propset3
137 (&commit_info, pname_utf8,
138 NULL, target,
139 opt_state->depth,
140 FALSE, SVN_INVALID_REVNUM,
141 ctx, subpool),
142 &success, opt_state->quiet,
143 SVN_ERR_UNVERSIONED_RESOURCE,
144 SVN_ERR_ENTRY_NOT_FOUND,
145 SVN_NO_ERROR));
147 if (success && (! opt_state->quiet))
149 SVN_ERR(svn_cmdline_printf
150 (subpool,
151 SVN_DEPTH_IS_RECURSIVE(opt_state->depth)
152 ? _("property '%s' deleted (recursively) from '%s'.\n")
153 : _("property '%s' deleted from '%s'.\n"),
154 pname_utf8, svn_path_local_style(target, subpool)));
157 svn_pool_destroy(subpool);
160 return SVN_NO_ERROR;