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"
28 #include "svn_client.h"
31 #include "private/svn_wc_private.h"
33 #include "svn_private_config.h"
38 svn_client_url_from_path(const char **url
,
39 const char *path_or_url
,
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
);
50 svn_client_root_url_from_path(const char **url
,
51 const char *path_or_url
,
52 svn_client_ctx_t
*ctx
,
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
,
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
,
72 /* If PATH_OR_URL is a local path (not a URL), we need to transform
74 if (! svn_path_is_url(path_or_url
))
76 const svn_wc_entry_t
*entry
;
80 SVN_ERR(svn_wc__entry_versioned(&entry
, path_or_url
, adm_access
,
85 svn_cancel_func_t cancel_func
;
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
,
97 SVN_ERR(svn_wc__entry_versioned(&entry
, path_or_url
, adm_access
,
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
));
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
116 apr_pool_t
*sesspool
= NULL
;
117 svn_ra_session_t
*session
= (svn_ra_session_t
*) ra_session
;
120 sesspool
= svn_pool_create(pool
);
121 SVN_ERR(svn_client__open_ra_session_internal(&session
, *url
, NULL
,
123 TRUE
, ctx
, sesspool
));
125 SVN_ERR(svn_client__get_revision_number(peg_revnum
, NULL
, session
,
126 peg_revision
, NULL
, pool
));
128 svn_pool_destroy(sesspool
);
135 svn_client__entry_location(const char **url
, svn_revnum_t
*revnum
,
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
;
144 *revnum
= entry
->copyfrom_rev
;
150 *revnum
= entry
->revision
;
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
));