source: valtobtest/subversion-1.6.2/subversion/svn/proplist-cmd.c @ 3

Last change on this file since 3 was 3, checked in by valtob, 15 years ago

subversion source 1.6.2 as test

File size: 6.7 KB
Line 
1/*
2 * proplist-cmd.c -- List properties of files/dirs
3 *
4 * ====================================================================
5 * Copyright (c) 2000-2007 CollabNet.  All rights reserved.
6 *
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.
12 *
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 * ====================================================================
17 */
18
19/* ==================================================================== */
20
21
22
23/*** Includes. ***/
24
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"
33
34#include "svn_private_config.h"
35
36typedef struct
37{
38  svn_cl__opt_state_t *opt_state;
39  svn_boolean_t is_url;
40} proplist_baton_t;
41
42
43/*** Code. ***/
44
45/* This implements the svn_proplist_receiver_t interface, printing XML to
46   stdout. */
47static svn_error_t *
48proplist_receiver_xml(void *baton,
49                      const char *path,
50                      apr_hash_t *prop_hash,
51                      apr_pool_t *pool)
52{
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;
57
58  if (! is_url)
59    name_local = svn_path_local_style(path, pool);
60  else
61    name_local = path;
62
63  /* "<target ...>" */
64  svn_xml_make_open_tag(&sb, pool, svn_xml_normal, "target",
65                        "path", name_local, NULL);
66
67  SVN_ERR(svn_cl__print_xml_prop_hash(&sb, prop_hash, (! opt_state->verbose),
68                                      pool));
69
70  /* "</target>" */
71  svn_xml_make_close_tag(&sb, pool, "target");
72
73  return svn_cl__error_checked_fputs(sb->data, stdout);
74}
75
76
77/* This implements the svn_proplist_receiver_t interface. */
78static svn_error_t *
79proplist_receiver(void *baton,
80                  const char *path,
81                  apr_hash_t *prop_hash,
82                  apr_pool_t *pool)
83{
84  svn_cl__opt_state_t *opt_state = ((proplist_baton_t *)baton)->opt_state;
85  svn_boolean_t is_url = ((proplist_baton_t *)baton)->is_url;
86  const char *name_local;
87
88  if (! is_url)
89    name_local = svn_path_local_style(path, pool);
90  else
91    name_local = path;
92
93  if (!opt_state->quiet)
94    SVN_ERR(svn_cmdline_printf(pool, _("Properties on '%s':\n"), name_local));
95  return svn_cl__print_prop_hash(prop_hash, (! opt_state->verbose), pool);
96}
97
98
99/* This implements the `svn_opt_subcommand_t' interface. */
100svn_error_t *
101svn_cl__proplist(apr_getopt_t *os,
102                 void *baton,
103                 apr_pool_t *pool)
104{
105  svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
106  svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
107  apr_array_header_t *targets;
108  int i;
109
110  SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
111                                                      opt_state->targets,
112                                                      ctx, pool));
113
114  /* Add "." if user passed 0 file arguments */
115  svn_opt_push_implicit_dot_target(targets, pool);
116
117  if (opt_state->revprop)  /* operate on revprops */
118    {
119      svn_revnum_t rev;
120      const char *URL;
121      apr_hash_t *proplist;
122
123
124      SVN_ERR(svn_cl__revprop_prepare(&opt_state->start_revision, targets,
125                                      &URL, pool));
126
127      /* Let libsvn_client do the real work. */
128      SVN_ERR(svn_client_revprop_list(&proplist,
129                                      URL, &(opt_state->start_revision),
130                                      &rev, ctx, pool));
131
132      if (opt_state->xml)
133        {
134          svn_stringbuf_t *sb = NULL;
135          char *revstr = apr_psprintf(pool, "%ld", rev);
136
137          SVN_ERR(svn_cl__xml_print_header("properties", pool));
138
139          svn_xml_make_open_tag(&sb, pool, svn_xml_normal,
140                                "revprops",
141                                "rev", revstr, NULL);
142          SVN_ERR(svn_cl__print_xml_prop_hash
143                  (&sb, proplist, (! opt_state->verbose), pool));
144          svn_xml_make_close_tag(&sb, pool, "revprops");
145
146          SVN_ERR(svn_cl__error_checked_fputs(sb->data, stdout));
147          SVN_ERR(svn_cl__xml_print_footer("properties", pool));
148        }
149      else
150        {
151          SVN_ERR
152            (svn_cmdline_printf(pool,
153                                _("Unversioned properties on revision %ld:\n"),
154                                rev));
155
156          SVN_ERR(svn_cl__print_prop_hash
157                  (proplist, (! opt_state->verbose), pool));
158        }
159    }
160  else  /* operate on normal, versioned properties (not revprops) */
161    {
162      apr_pool_t *subpool = svn_pool_create(pool);
163      svn_proplist_receiver_t pl_receiver;
164
165      if (opt_state->xml)
166        {
167          SVN_ERR(svn_cl__xml_print_header("properties", pool));
168          pl_receiver = proplist_receiver_xml;
169        }
170      else
171        {
172          pl_receiver = proplist_receiver;
173        }
174
175      if (opt_state->depth == svn_depth_unknown)
176        opt_state->depth = svn_depth_empty;
177
178      for (i = 0; i < targets->nelts; i++)
179        {
180          const char *target = APR_ARRAY_IDX(targets, i, const char *);
181          proplist_baton_t pl_baton;
182          const char *truepath;
183          svn_opt_revision_t peg_revision;
184
185          svn_pool_clear(subpool);
186          SVN_ERR(svn_cl__check_cancel(ctx->cancel_baton));
187
188          pl_baton.is_url = svn_path_is_url(target);
189          pl_baton.opt_state = opt_state;
190
191          /* Check for a peg revision. */
192          SVN_ERR(svn_opt_parse_path(&peg_revision, &truepath, target,
193                                     subpool));
194
195          SVN_ERR(svn_cl__try
196                  (svn_client_proplist3(truepath, &peg_revision,
197                                        &(opt_state->start_revision),
198                                        opt_state->depth,
199                                        opt_state->changelists,
200                                        pl_receiver, &pl_baton,
201                                        ctx, subpool),
202                   NULL, opt_state->quiet,
203                   SVN_ERR_UNVERSIONED_RESOURCE,
204                   SVN_ERR_ENTRY_NOT_FOUND,
205                   SVN_NO_ERROR));
206        }
207
208      if (opt_state->xml)
209        SVN_ERR(svn_cl__xml_print_footer("properties", pool));
210
211      svn_pool_destroy(subpool);
212    }
213
214  return SVN_NO_ERROR;
215}
Note: See TracBrowser for help on using the repository browser.