In the command-line client, forbid
[svn.git] / subversion / svn / cat-cmd.c
blobee4ea99ccf6762527f3a0956d7d265a6fb8f22cf
1 /*
2 * cat-cmd.c -- Print the content of a file or URL.
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 /* ==================================================================== */
23 /*** Includes. ***/
25 #include "svn_pools.h"
26 #include "svn_client.h"
27 #include "svn_error.h"
28 #include "cl.h"
31 /*** Code. ***/
33 /* This implements the `svn_opt_subcommand_t' interface. */
34 svn_error_t *
35 svn_cl__cat(apr_getopt_t *os,
36 void *baton,
37 apr_pool_t *pool)
39 svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
40 svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
41 apr_array_header_t *targets;
42 int i;
43 svn_stream_t *out;
44 apr_pool_t *subpool = svn_pool_create(pool);
46 SVN_ERR(svn_opt_args_to_target_array2(&targets, os,
47 opt_state->targets, pool));
49 /* Cat cannot operate on an implicit '.' so a filename is required */
50 if (! targets->nelts)
51 return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);
53 SVN_ERR(svn_stream_for_stdout(&out, pool));
55 for (i = 0; i < targets->nelts; i++)
57 const char *target = APR_ARRAY_IDX(targets, i, const char *);
58 const char *truepath;
59 svn_opt_revision_t peg_revision;
61 svn_pool_clear(subpool);
62 SVN_ERR(svn_cl__check_cancel(ctx->cancel_baton));
64 /* Get peg revisions. */
65 SVN_ERR(svn_opt_parse_path(&peg_revision, &truepath, target,
66 subpool));
68 SVN_ERR(svn_cl__try(svn_client_cat2(out, truepath, &peg_revision,
69 &(opt_state->start_revision),
70 ctx, subpool),
71 NULL, opt_state->quiet,
72 SVN_ERR_UNVERSIONED_RESOURCE,
73 SVN_ERR_ENTRY_NOT_FOUND,
74 SVN_ERR_CLIENT_IS_DIRECTORY,
75 SVN_NO_ERROR));
77 svn_pool_destroy(subpool);
79 return SVN_NO_ERROR;