2
* ls.c: list local and remote directory entries.
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
/* ==================================================================== */
24
#include "svn_client.h"
27
#include "svn_private_config.h"
30
get_dir_contents (apr_hash_t *dirents,
33
svn_ra_session_t *ra_session,
34
svn_boolean_t recurse,
35
svn_client_ctx_t *ctx,
38
apr_hash_t *tmpdirents;
39
svn_dirent_t *the_ent;
42
/* Get the directory's entries, but not its props. */
43
SVN_ERR (svn_ra_get_dir (ra_session, dir, rev, &tmpdirents,
47
SVN_ERR (ctx->cancel_func (ctx->cancel_baton));
49
for (hi = apr_hash_first (pool, tmpdirents);
51
hi = apr_hash_next (hi))
57
apr_hash_this (hi, &key, NULL, &val);
61
path = svn_path_join (dir, key, pool);
63
apr_hash_set (dirents, path, APR_HASH_KEY_STRING, val);
65
if (recurse && the_ent->kind == svn_node_dir)
66
SVN_ERR (get_dir_contents (dirents, path, rev, ra_session,
74
svn_client_ls2 (apr_hash_t **dirents,
75
const char *path_or_url,
76
const svn_opt_revision_t *peg_revision,
77
const svn_opt_revision_t *revision,
78
svn_boolean_t recurse,
79
svn_client_ctx_t *ctx,
82
svn_ra_session_t *ra_session;
84
svn_node_kind_t url_kind;
87
/* Get an RA plugin for this filesystem object. */
88
SVN_ERR (svn_client__ra_session_from_path (&ra_session, &rev,
89
&url, path_or_url, peg_revision,
90
revision, ctx, pool));
92
/* Decide if the URL is a file or directory. */
93
SVN_ERR (svn_ra_check_path (ra_session, "", rev, &url_kind, pool));
95
if (url_kind == svn_node_dir)
97
*dirents = apr_hash_make (pool);
99
SVN_ERR (get_dir_contents (*dirents, "", rev, ra_session, recurse,
102
else if (url_kind == svn_node_file)
104
apr_hash_t *parent_ents;
105
const char *parent_url, *base_name;
106
svn_dirent_t *the_ent;
108
/* Re-open the session to the file's parent instead. */
109
svn_path_split (url, &parent_url, &base_name, pool);
110
/* 'base_name' is now the last component of an URL, but we want
111
to use it as a plain file name. Therefore, we must URI-decode
113
base_name = svn_path_uri_decode(base_name, pool);
114
SVN_ERR (svn_client__open_ra_session (&ra_session, parent_url,
116
NULL, NULL, FALSE, TRUE,
119
/* Get all parent's entries, no props. */
120
SVN_ERR (svn_ra_get_dir (ra_session, "", rev, &parent_ents,
123
/* Copy the relevant entry into the caller's hash. */
124
*dirents = apr_hash_make (pool);
125
the_ent = apr_hash_get (parent_ents, base_name, APR_HASH_KEY_STRING);
127
return svn_error_createf (SVN_ERR_FS_NOT_FOUND, NULL,
128
_("URL '%s' non-existent in that revision"),
131
apr_hash_set (*dirents, base_name, APR_HASH_KEY_STRING, the_ent);
134
return svn_error_createf (SVN_ERR_FS_NOT_FOUND, NULL,
135
_("URL '%s' non-existent in that revision"),
142
svn_client_ls (apr_hash_t **dirents,
143
const char *path_or_url,
144
svn_opt_revision_t *revision,
145
svn_boolean_t recurse,
146
svn_client_ctx_t *ctx,
149
return svn_client_ls2 (dirents, path_or_url, revision,
150
revision, recurse, ctx, pool);