2 * proplist-cmd.c -- List properties of 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 /* ==================================================================== */
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"
34 #include "svn_private_config.h"
38 svn_cl__opt_state_t
*opt_state
;
45 /* This implements the svn_proplist_receiver_t interface, printing XML to
48 proplist_receiver_xml(void *baton
,
50 apr_hash_t
*prop_hash
,
53 svn_cl__opt_state_t
*opt_state
= ((proplist_baton_t
*)baton
)->opt_state
;
54 svn_boolean_t is_url
= ((proplist_baton_t
*)baton
)->is_url
;
55 svn_stringbuf_t
*sb
= NULL
;
56 const char *name_local
;
59 name_local
= svn_path_local_style(path
, pool
);
64 svn_xml_make_open_tag(&sb
, pool
, svn_xml_normal
, "target",
65 "path", name_local
, NULL
);
67 SVN_ERR(svn_cl__print_xml_prop_hash(&sb
, prop_hash
, (! opt_state
->verbose
),
71 svn_xml_make_close_tag(&sb
, pool
, "target");
73 SVN_ERR(svn_cl__error_checked_fputs(sb
->data
, stdout
));
79 /* This implements the svn_proplist_receiver_t interface. */
81 proplist_receiver(void *baton
,
83 apr_hash_t
*prop_hash
,
86 svn_cl__opt_state_t
*opt_state
= ((proplist_baton_t
*)baton
)->opt_state
;
87 svn_boolean_t is_url
= ((proplist_baton_t
*)baton
)->is_url
;
88 const char *name_local
;
91 name_local
= svn_path_local_style(path
, pool
);
95 if (!opt_state
->quiet
)
96 SVN_ERR(svn_cmdline_printf(pool
, _("Properties on '%s':\n"), name_local
));
97 SVN_ERR(svn_cl__print_prop_hash(prop_hash
, (! opt_state
->verbose
),
104 /* This implements the `svn_opt_subcommand_t' interface. */
106 svn_cl__proplist(apr_getopt_t
*os
,
110 svn_cl__opt_state_t
*opt_state
= ((svn_cl__cmd_baton_t
*) baton
)->opt_state
;
111 svn_client_ctx_t
*ctx
= ((svn_cl__cmd_baton_t
*) baton
)->ctx
;
112 apr_array_header_t
*targets
;
115 SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets
, os
,
119 /* Add "." if user passed 0 file arguments */
120 svn_opt_push_implicit_dot_target(targets
, pool
);
122 if (opt_state
->revprop
) /* operate on revprops */
126 apr_hash_t
*proplist
;
129 SVN_ERR(svn_cl__revprop_prepare(&opt_state
->start_revision
, targets
,
132 /* Let libsvn_client do the real work. */
133 SVN_ERR(svn_client_revprop_list(&proplist
,
134 URL
, &(opt_state
->start_revision
),
139 svn_stringbuf_t
*sb
= NULL
;
140 char *revstr
= apr_psprintf(pool
, "%ld", rev
);
142 SVN_ERR(svn_cl__xml_print_header("properties", pool
));
144 svn_xml_make_open_tag(&sb
, pool
, svn_xml_normal
,
146 "rev", revstr
, NULL
);
147 SVN_ERR(svn_cl__print_xml_prop_hash
148 (&sb
, proplist
, (! opt_state
->verbose
), pool
));
149 svn_xml_make_close_tag(&sb
, pool
, "revprops");
151 SVN_ERR(svn_cl__error_checked_fputs(sb
->data
, stdout
));
152 SVN_ERR(svn_cl__xml_print_footer("properties", pool
));
157 (svn_cmdline_printf(pool
,
158 _("Unversioned properties on revision %ld:\n"),
161 SVN_ERR(svn_cl__print_prop_hash
162 (proplist
, (! opt_state
->verbose
), pool
));
165 else /* operate on normal, versioned properties (not revprops) */
167 apr_pool_t
*subpool
= svn_pool_create(pool
);
168 svn_proplist_receiver_t pl_receiver
;
172 SVN_ERR(svn_cl__xml_print_header("properties", pool
));
173 pl_receiver
= proplist_receiver_xml
;
177 pl_receiver
= proplist_receiver
;
180 if (opt_state
->depth
== svn_depth_unknown
)
181 opt_state
->depth
= svn_depth_empty
;
183 for (i
= 0; i
< targets
->nelts
; i
++)
185 const char *target
= APR_ARRAY_IDX(targets
, i
, const char *);
186 proplist_baton_t pl_baton
;
187 const char *truepath
;
188 svn_opt_revision_t peg_revision
;
190 svn_pool_clear(subpool
);
191 SVN_ERR(svn_cl__check_cancel(ctx
->cancel_baton
));
193 pl_baton
.is_url
= svn_path_is_url(target
);
194 pl_baton
.opt_state
= opt_state
;
196 /* Check for a peg revision. */
197 SVN_ERR(svn_opt_parse_path(&peg_revision
, &truepath
, target
,
201 (svn_client_proplist3(truepath
, &peg_revision
,
202 &(opt_state
->start_revision
),
204 opt_state
->changelists
,
205 pl_receiver
, &pl_baton
,
207 NULL
, opt_state
->quiet
,
208 SVN_ERR_UNVERSIONED_RESOURCE
,
209 SVN_ERR_ENTRY_NOT_FOUND
,
214 SVN_ERR(svn_cl__xml_print_footer("properties", pool
));
216 svn_pool_destroy(subpool
);