In the command-line client, forbid
[svn.git] / subversion / libsvn_client / url.c
blobad5aabf0dbbd00ab900e296e3ae6db18438bc932
1 /*
2 * url.c: converting paths to urls
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 * ====================================================================
21 #include <apr_pools.h>
23 #include "svn_pools.h"
24 #include "svn_error.h"
25 #include "svn_types.h"
26 #include "svn_opt.h"
27 #include "svn_wc.h"
28 #include "svn_client.h"
29 #include "svn_path.h"
31 #include "private/svn_wc_private.h"
32 #include "client.h"
33 #include "svn_private_config.h"
37 svn_error_t *
38 svn_client_url_from_path(const char **url,
39 const char *path_or_url,
40 apr_pool_t *pool)
42 svn_opt_revision_t revision;
43 revision.kind = svn_opt_revision_unspecified;
44 return svn_client__derive_location(url, NULL, path_or_url, &revision,
45 NULL, NULL, NULL, pool);
49 svn_error_t *
50 svn_client_root_url_from_path(const char **url,
51 const char *path_or_url,
52 svn_client_ctx_t *ctx,
53 apr_pool_t *pool)
55 svn_opt_revision_t peg_revision;
56 peg_revision.kind = svn_path_is_url(path_or_url) ? svn_opt_revision_head
57 : svn_opt_revision_base;
58 return svn_client__get_repos_root(url, path_or_url, &peg_revision,
59 NULL, ctx, pool);
62 svn_error_t *
63 svn_client__derive_location(const char **url,
64 svn_revnum_t *peg_revnum,
65 const char *path_or_url,
66 const svn_opt_revision_t *peg_revision,
67 const svn_ra_session_t *ra_session,
68 svn_wc_adm_access_t *adm_access,
69 svn_client_ctx_t *ctx,
70 apr_pool_t *pool)
72 /* If PATH_OR_URL is a local path (not a URL), we need to transform
73 it into a URL. */
74 if (! svn_path_is_url(path_or_url))
76 const svn_wc_entry_t *entry;
78 if (adm_access)
80 SVN_ERR(svn_wc__entry_versioned(&entry, path_or_url, adm_access,
81 FALSE, pool));
83 else
85 svn_cancel_func_t cancel_func;
86 void *cancel_baton;
88 if (ctx)
90 cancel_func = ctx->cancel_func;
91 cancel_baton = ctx->cancel_baton;
94 SVN_ERR(svn_wc_adm_probe_open3(&adm_access, NULL, path_or_url,
95 FALSE, 0, cancel_func, cancel_baton,
96 pool));
97 SVN_ERR(svn_wc__entry_versioned(&entry, path_or_url, adm_access,
98 FALSE, pool));
99 SVN_ERR(svn_wc_adm_close(adm_access));
102 SVN_ERR(svn_client__entry_location(url, peg_revnum, path_or_url,
103 peg_revision->kind, entry, pool));
105 else
107 *url = path_or_url;
108 /* peg_revnum (if provided) will be set below. */
111 /* If we haven't resolved for ourselves a numeric peg revision, do so. */
112 if (peg_revnum && !SVN_IS_VALID_REVNUM(*peg_revnum))
114 /* Use sesspool to assure that if we opened an RA session, we
115 close it. */
116 apr_pool_t *sesspool = NULL;
117 svn_ra_session_t *session = (svn_ra_session_t *) ra_session;
118 if (session == NULL)
120 sesspool = svn_pool_create(pool);
121 SVN_ERR(svn_client__open_ra_session_internal(&session, *url, NULL,
122 NULL, NULL, FALSE,
123 TRUE, ctx, sesspool));
125 SVN_ERR(svn_client__get_revision_number(peg_revnum, NULL, session,
126 peg_revision, NULL, pool));
127 if (sesspool)
128 svn_pool_destroy(sesspool);
131 return SVN_NO_ERROR;
134 svn_error_t *
135 svn_client__entry_location(const char **url, svn_revnum_t *revnum,
136 const char *wc_path,
137 enum svn_opt_revision_kind peg_rev_kind,
138 const svn_wc_entry_t *entry, apr_pool_t *pool)
140 if (entry->copyfrom_url && peg_rev_kind == svn_opt_revision_working)
142 *url = entry->copyfrom_url;
143 if (revnum)
144 *revnum = entry->copyfrom_rev;
146 else if (entry->url)
148 *url = entry->url;
149 if (revnum)
150 *revnum = entry->revision;
152 else
154 return svn_error_createf(SVN_ERR_ENTRY_MISSING_URL, NULL,
155 _("Entry for '%s' has no URL"),
156 svn_path_local_style(wc_path, pool));
159 return SVN_NO_ERROR;