2
* propset-cmd.c -- Set property values on files/dirs
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
/* ==================================================================== */
25
#include "svn_cmdline.h"
26
#include "svn_pools.h"
27
#include "svn_client.h"
28
#include "svn_string.h"
29
#include "svn_error.h"
31
#include "svn_subst.h"
33
#include "svn_props.h"
36
#include "svn_private_config.h"
41
/* This implements the `svn_opt_subcommand_t' interface. */
43
svn_cl__propset (apr_getopt_t *os,
47
svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
48
svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
49
const char *pname, *pname_utf8;
50
svn_string_t *propval = NULL;
51
svn_boolean_t propval_came_from_cmdline;
52
apr_array_header_t *args, *targets;
55
/* PNAME and PROPVAL expected as first 2 arguments if filedata was
56
NULL, else PNAME alone will precede the targets. Get a UTF-8
57
version of the name, too. */
58
SVN_ERR (svn_opt_parse_num_args (&args, os,
59
opt_state->filedata ? 1 : 2, pool));
60
pname = ((const char **) (args->elts))[0];
61
SVN_ERR (svn_utf_cstring_to_utf8 (&pname_utf8, pname, pool));
63
/* Get the PROPVAL from either an external file, or from the command
65
if (opt_state->filedata)
67
propval = svn_string_create_from_buf (opt_state->filedata, pool);
68
propval_came_from_cmdline = FALSE;
72
propval = svn_string_create (((const char **) (args->elts))[1], pool);
73
propval_came_from_cmdline = TRUE;
76
/* We only want special Subversion property values to be in UTF-8
77
and LF line endings. All other propvals are taken literally. */
78
if (svn_prop_needs_translation (pname_utf8))
79
SVN_ERR (svn_subst_translate_string (&propval, propval,
80
opt_state->encoding, pool));
82
if (opt_state->encoding)
83
return svn_error_create
84
(SVN_ERR_UNSUPPORTED_FEATURE, NULL,
85
_("Bad encoding option: prop value not stored as UTF8"));
87
/* Suck up all the remaining arguments into a targets array */
88
SVN_ERR (svn_opt_args_to_target_array2 (&targets, os,
89
opt_state->targets, pool));
91
if (opt_state->revprop) /* operate on a revprop */
96
/* Implicit "." is okay for revision properties; it just helps
97
us find the right repository. */
98
svn_opt_push_implicit_dot_target (targets, pool);
100
SVN_ERR (svn_cl__revprop_prepare (&opt_state->start_revision, targets,
103
/* Let libsvn_client do the real work. */
104
SVN_ERR (svn_client_revprop_set (pname_utf8, propval,
105
URL, &(opt_state->start_revision),
106
&rev, opt_state->force, ctx, pool));
107
if (! opt_state->quiet)
111
(pool, _("property '%s' set on repository revision %ld\n"),
115
else if (opt_state->start_revision.kind != svn_opt_revision_unspecified)
117
return svn_error_createf
118
(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
119
_("Cannot specify revision for setting versioned property '%s'"),
122
else /* operate on a normal, versioned property (not a revprop) */
124
apr_pool_t *subpool = svn_pool_create (pool);
126
/* The customary implicit dot rule has been prone to user error
127
* here. People would do intuitive things like
129
* $ svn propset svn:executable script
131
* and then be surprised to get an error like:
133
* svn: Illegal target for the requested operation
134
* svn: Cannot set svn:executable on a directory ()
136
* So we don't do the implicit dot thing anymore. A * target
137
* must always be explicitly provided when setting a versioned
140
* http://subversion.tigris.org/issues/show_bug.cgi?id=924
145
if (targets->nelts == 0)
147
if (propval_came_from_cmdline)
149
return svn_error_createf
150
(SVN_ERR_CL_INSUFFICIENT_ARGS, NULL,
151
_("Explicit target required ('%s' interpreted as prop value)"),
156
return svn_error_create
157
(SVN_ERR_CL_INSUFFICIENT_ARGS, NULL,
158
_("Explicit target argument required"));
162
for (i = 0; i < targets->nelts; i++)
164
const char *target = ((const char **) (targets->elts))[i];
165
svn_boolean_t success;
167
svn_pool_clear (subpool);
168
SVN_ERR (svn_cl__check_cancel (ctx->cancel_baton));
169
SVN_ERR (svn_cl__try (svn_client_propset2 (pname_utf8,
171
opt_state->recursive,
174
&success, opt_state->quiet,
175
SVN_ERR_UNVERSIONED_RESOURCE,
176
SVN_ERR_ENTRY_NOT_FOUND,
179
if (success && (! opt_state->quiet))
183
(pool, opt_state->recursive
184
? _("property '%s' set (recursively) on '%s'\n")
185
: _("property '%s' set on '%s'\n"),
186
pname, svn_path_local_style (target, pool)));
189
svn_pool_destroy (subpool);