2 * checkout.c : read a repository and drive a checkout editor.
4 * ====================================================================
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
21 * ====================================================================
27 #include "svn_dirent_uri.h"
28 #include "svn_private_config.h"
32 svn_ra_local__split_URL(svn_repos_t **repos,
33 const char **repos_url,
38 svn_error_t *err = SVN_NO_ERROR;
39 const char *repos_dirent;
40 const char *repos_root_dirent;
41 svn_stringbuf_t *urlbuf;
44 SVN_ERR(svn_uri_get_dirent_from_file_url(&repos_dirent, URL, pool));
46 /* Search for a repository in the full path. */
47 repos_root_dirent = svn_repos_find_root_path(repos_dirent, pool);
48 if (!repos_root_dirent)
49 return svn_error_createf(SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED, NULL,
50 _("Unable to open repository '%s'"), URL);
52 /* Attempt to open a repository at URL. */
53 err = svn_repos_open2(repos, repos_root_dirent, NULL, pool);
55 return svn_error_createf(SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED, err,
56 _("Unable to open repository '%s'"), URL);
58 /* Assert capabilities directly, since client == server. */
60 apr_array_header_t *caps = apr_array_make(pool, 1, sizeof(const char *));
61 APR_ARRAY_PUSH(caps, const char *) = SVN_RA_CAPABILITY_MERGEINFO;
62 SVN_ERR(svn_repos_remember_client_capabilities(*repos, caps));
65 /* = apr_pstrcat(pool,
67 svn_dirent_skip_ancestor(repos_root_dirent, repos_dirent),
68 (const char *)NULL); */
69 root_end = strlen(repos_root_dirent);
70 if (! repos_dirent[root_end])
72 else if (repos_dirent[root_end] == '/')
73 *fs_path = &repos_dirent[root_end];
76 /* On Windows "C:/" is the parent directory of "C:/dir" */
77 *fs_path = &repos_dirent[root_end-1];
78 SVN_ERR_ASSERT((*fs_path)[0] == '/');
81 /* Remove the path components after the root dirent from the original URL,
82 to get a URL to the repository root.
84 We don't use svn_uri_get_file_url_from_dirent() here as that would
85 transform several uris to form a differently formed url than
86 svn_uri_canonicalize would.
88 E.g. file://localhost/C:/dir -> file:///C:/dir
89 (a transform that was originally supported directly by this function,
90 before the implementation moved)
93 file:///dir -> file:///E:/dir (When E: is the current disk)
95 urlbuf = svn_stringbuf_create(URL, pool);
96 svn_path_remove_components(urlbuf,
97 svn_path_component_count(repos_dirent)
98 - svn_path_component_count(repos_root_dirent));
99 *repos_url = urlbuf->data;
101 /* Configure hook script environment variables. */
102 SVN_ERR(svn_repos_hooks_setenv(*repos, NULL, pool));