Fix compiler warning due to missing function prototype.
[svn.git] / subversion / svn / proplist-cmd.c
blobe3c8bac27af6a863a831f149a6a2fd43b5ba67c1
1 /*
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 /* ==================================================================== */
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_path.h"
31 #include "svn_xml.h"
32 #include "cl.h"
34 #include "svn_private_config.h"
36 typedef struct
38 svn_cl__opt_state_t *opt_state;
39 svn_boolean_t is_url;
40 } proplist_baton_t;
43 /*** Code. ***/
45 /* This implements the svn_proplist_receiver_t interface, printing XML to
46 stdout. */
47 static svn_error_t *
48 proplist_receiver_xml(void *baton,
49 const char *path,
50 apr_hash_t *prop_hash,
51 apr_pool_t *pool)
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;
58 if (! is_url)
59 name_local = svn_path_local_style(path, pool);
60 else
61 name_local = path;
63 /* "<target ...>" */
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),
68 pool));
70 /* "</target>" */
71 svn_xml_make_close_tag(&sb, pool, "target");
73 SVN_ERR(svn_cl__error_checked_fputs(sb->data, stdout));
75 return SVN_NO_ERROR;
79 /* This implements the svn_proplist_receiver_t interface. */
80 static svn_error_t *
81 proplist_receiver(void *baton,
82 const char *path,
83 apr_hash_t *prop_hash,
84 apr_pool_t *pool)
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;
90 if (! is_url)
91 name_local = svn_path_local_style(path, pool);
92 else
93 name_local = path;
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),
98 pool));
100 return SVN_NO_ERROR;
104 /* This implements the `svn_opt_subcommand_t' interface. */
105 svn_error_t *
106 svn_cl__proplist(apr_getopt_t *os,
107 void *baton,
108 apr_pool_t *pool)
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;
113 int i;
115 SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
116 opt_state->targets,
117 ctx, pool));
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 */
124 svn_revnum_t rev;
125 const char *URL;
126 apr_hash_t *proplist;
129 SVN_ERR(svn_cl__revprop_prepare(&opt_state->start_revision, targets,
130 &URL, pool));
132 /* Let libsvn_client do the real work. */
133 SVN_ERR(svn_client_revprop_list(&proplist,
134 URL, &(opt_state->start_revision),
135 &rev, ctx, pool));
137 if (opt_state->xml)
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,
145 "revprops",
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));
154 else
156 SVN_ERR
157 (svn_cmdline_printf(pool,
158 _("Unversioned properties on revision %ld:\n"),
159 rev));
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;
170 if (opt_state->xml)
172 SVN_ERR(svn_cl__xml_print_header("properties", pool));
173 pl_receiver = proplist_receiver_xml;
175 else
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,
198 subpool));
200 SVN_ERR(svn_cl__try
201 (svn_client_proplist3(truepath, &peg_revision,
202 &(opt_state->start_revision),
203 opt_state->depth,
204 opt_state->changelists,
205 pl_receiver, &pl_baton,
206 ctx, subpool),
207 NULL, opt_state->quiet,
208 SVN_ERR_UNVERSIONED_RESOURCE,
209 SVN_ERR_ENTRY_NOT_FOUND,
210 SVN_NO_ERROR));
213 if (opt_state->xml)
214 SVN_ERR(svn_cl__xml_print_footer("properties", pool));
216 svn_pool_destroy(subpool);
219 return SVN_NO_ERROR;