2 * proplist-cmd.c -- List properties of files/dirs
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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
21 * ====================================================================
24 /* ==================================================================== */
30 #include "svn_cmdline.h"
31 #include "svn_pools.h"
32 #include "svn_client.h"
33 #include "svn_error_codes.h"
34 #include "svn_error.h"
35 #include "svn_dirent_uri.h"
38 #include "svn_props.h"
41 #include "private/svn_cmdline_private.h"
43 #include "svn_private_config.h"
45 typedef struct proplist_baton_t
47 svn_cl__opt_state_t *opt_state;
54 /* This implements the svn_proplist_receiver2_t interface, printing XML to
57 proplist_receiver_xml(void *baton,
59 apr_hash_t *prop_hash,
60 apr_array_header_t *inherited_props,
63 svn_cl__opt_state_t *opt_state = ((proplist_baton_t *)baton)->opt_state;
64 svn_boolean_t is_url = ((proplist_baton_t *)baton)->is_url;
66 const char *name_local;
68 if (inherited_props && inherited_props->nelts)
71 apr_pool_t *iterpool = svn_pool_create(pool);
73 for (i = 0; i < inherited_props->nelts; i++)
75 svn_prop_inherited_item_t *iprop =
76 APR_ARRAY_IDX(inherited_props, i, svn_prop_inherited_item_t *);
80 if (svn_path_is_url(iprop->path_or_url))
81 name_local = iprop->path_or_url;
83 name_local = svn_dirent_local_style(iprop->path_or_url, iterpool);
85 svn_xml_make_open_tag(&sb, iterpool, svn_xml_normal, "target",
86 "path", name_local, SVN_VA_NULL);
87 SVN_ERR(svn_cmdline__print_xml_prop_hash(&sb, iprop->prop_hash,
88 (! opt_state->verbose),
90 svn_xml_make_close_tag(&sb, iterpool, "target");
91 SVN_ERR(svn_cl__error_checked_fputs(sb->data, stdout));
93 svn_pool_destroy(iterpool);
97 name_local = svn_dirent_local_style(path, pool);
107 svn_xml_make_open_tag(&sb, pool, svn_xml_normal, "target",
108 "path", name_local, SVN_VA_NULL);
110 SVN_ERR(svn_cmdline__print_xml_prop_hash(&sb, prop_hash,
111 (! opt_state->verbose),
115 svn_xml_make_close_tag(&sb, pool, "target");
116 SVN_ERR(svn_cl__error_checked_fputs(sb->data, stdout));
123 /* This implements the svn_proplist_receiver2_t interface. */
125 proplist_receiver(void *baton,
127 apr_hash_t *prop_hash,
128 apr_array_header_t *inherited_props,
131 svn_cl__opt_state_t *opt_state = ((proplist_baton_t *)baton)->opt_state;
132 svn_boolean_t is_url = ((proplist_baton_t *)baton)->is_url;
133 const char *name_local;
136 name_local = svn_dirent_local_style(path, pool);
143 apr_pool_t *iterpool = svn_pool_create(pool);
145 for (i = 0; i < inherited_props->nelts; i++)
147 svn_prop_inherited_item_t *iprop =
148 APR_ARRAY_IDX(inherited_props, i, svn_prop_inherited_item_t *);
150 svn_pool_clear(iterpool);
152 if (!opt_state->quiet)
154 if (svn_path_is_url(iprop->path_or_url))
155 SVN_ERR(svn_cmdline_printf(
156 iterpool, _("Inherited properties on '%s',\nfrom '%s':\n"),
157 name_local, iprop->path_or_url));
159 SVN_ERR(svn_cmdline_printf(
160 iterpool, _("Inherited properties on '%s',\nfrom '%s':\n"),
161 name_local, svn_dirent_local_style(iprop->path_or_url,
165 SVN_ERR(svn_cmdline__print_prop_hash(NULL, iprop->prop_hash,
166 (! opt_state->verbose),
169 svn_pool_destroy(iterpool);
172 if (prop_hash && apr_hash_count(prop_hash))
174 if (!opt_state->quiet)
175 SVN_ERR(svn_cmdline_printf(pool, _("Properties on '%s':\n"),
177 SVN_ERR(svn_cmdline__print_prop_hash(NULL, prop_hash,
178 (! opt_state->verbose), pool));
185 /* This implements the `svn_opt_subcommand_t' interface. */
187 svn_cl__proplist(apr_getopt_t *os,
189 apr_pool_t *scratch_pool)
191 svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
192 svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
193 apr_array_header_t *targets;
194 apr_array_header_t *errors = apr_array_make(scratch_pool, 0,
195 sizeof(apr_status_t));
197 SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
202 /* Add "." if user passed 0 file arguments */
203 svn_opt_push_implicit_dot_target(targets, scratch_pool);
205 if (opt_state->revprop) /* operate on revprops */
209 apr_hash_t *proplist;
211 if (opt_state->show_inherited_props)
212 return svn_error_create(
213 SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
214 _("--show-inherited-props can't be used with --revprop"));
216 SVN_ERR(svn_cl__revprop_prepare(&opt_state->start_revision, targets,
217 &URL, ctx, scratch_pool));
219 /* Let libsvn_client do the real work. */
220 SVN_ERR(svn_client_revprop_list(&proplist,
221 URL, &(opt_state->start_revision),
222 &rev, ctx, scratch_pool));
226 svn_stringbuf_t *sb = NULL;
227 char *revstr = apr_psprintf(scratch_pool, "%ld", rev);
229 SVN_ERR(svn_cl__xml_print_header("properties", scratch_pool));
231 svn_xml_make_open_tag(&sb, scratch_pool, svn_xml_normal,
233 "rev", revstr, SVN_VA_NULL);
234 SVN_ERR(svn_cmdline__print_xml_prop_hash(&sb, proplist,
235 (! opt_state->verbose),
236 FALSE, scratch_pool));
237 svn_xml_make_close_tag(&sb, scratch_pool, "revprops");
239 SVN_ERR(svn_cl__error_checked_fputs(sb->data, stdout));
240 SVN_ERR(svn_cl__xml_print_footer("properties", scratch_pool));
245 (svn_cmdline_printf(scratch_pool,
246 _("Unversioned properties on revision %ld:\n"),
249 SVN_ERR(svn_cmdline__print_prop_hash(NULL, proplist,
250 (! opt_state->verbose),
254 else /* operate on normal, versioned properties (not revprops) */
257 apr_pool_t *iterpool;
258 svn_proplist_receiver2_t pl_receiver;
262 SVN_ERR(svn_cl__xml_print_header("properties", scratch_pool));
263 pl_receiver = proplist_receiver_xml;
267 pl_receiver = proplist_receiver;
270 if (opt_state->depth == svn_depth_unknown)
271 opt_state->depth = svn_depth_empty;
273 iterpool = svn_pool_create(scratch_pool);
274 for (i = 0; i < targets->nelts; i++)
276 const char *target = APR_ARRAY_IDX(targets, i, const char *);
277 proplist_baton_t pl_baton;
278 const char *truepath;
279 svn_opt_revision_t peg_revision;
281 svn_pool_clear(iterpool);
282 SVN_ERR(svn_cl__check_cancel(ctx->cancel_baton));
284 pl_baton.is_url = svn_path_is_url(target);
285 pl_baton.opt_state = opt_state;
287 /* Check for a peg revision. */
288 SVN_ERR(svn_opt_parse_path(&peg_revision, &truepath, target,
292 svn_client_proplist4(truepath, &peg_revision,
293 &(opt_state->start_revision),
295 opt_state->changelists,
296 opt_state->show_inherited_props,
297 pl_receiver, &pl_baton,
299 errors, opt_state->quiet,
300 SVN_ERR_UNVERSIONED_RESOURCE,
301 SVN_ERR_ENTRY_NOT_FOUND,
304 svn_pool_destroy(iterpool);
307 SVN_ERR(svn_cl__xml_print_footer("properties", scratch_pool));
309 /* Error out *after* we closed the XML element */
310 if (errors->nelts > 0)
314 err = svn_error_create(SVN_ERR_ILLEGAL_TARGET, NULL, NULL);
315 for (i = 0; i < errors->nelts; i++)
317 apr_status_t status = APR_ARRAY_IDX(errors, i, apr_status_t);
319 if (status == SVN_ERR_ENTRY_NOT_FOUND)
320 err = svn_error_quick_wrap(err,
321 _("Could not display properties "
322 "of all targets because some "
323 "targets don't exist"));
324 else if (status == SVN_ERR_UNVERSIONED_RESOURCE)
325 err = svn_error_quick_wrap(err,
326 _("Could not display properties "
327 "of all targets because some "
328 "targets are not versioned"));
331 return svn_error_trace(err);