]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/subversion/subversion/libsvn_ra_local/split_url.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / subversion / subversion / libsvn_ra_local / split_url.c
1 /*
2  * checkout.c : read a repository and drive a checkout editor.
3  *
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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
20  *    under the License.
21  * ====================================================================
22  */
23
24 #include "ra_local.h"
25 #include <string.h>
26 #include "svn_path.h"
27 #include "svn_dirent_uri.h"
28 #include "svn_private_config.h"
29
30
31 svn_error_t *
32 svn_ra_local__split_URL(svn_repos_t **repos,
33                         const char **repos_url,
34                         const char **fs_path,
35                         const char *URL,
36                         apr_pool_t *pool)
37 {
38   svn_error_t *err = SVN_NO_ERROR;
39   const char *repos_dirent;
40   const char *repos_root_dirent;
41   svn_stringbuf_t *urlbuf;
42   apr_size_t root_end;
43
44   SVN_ERR(svn_uri_get_dirent_from_file_url(&repos_dirent, URL, pool));
45
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);
51
52   /* Attempt to open a repository at URL. */
53   err = svn_repos_open2(repos, repos_root_dirent, NULL, pool);
54   if (err)
55     return svn_error_createf(SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED, err,
56                              _("Unable to open repository '%s'"), URL);
57
58   /* Assert capabilities directly, since client == server. */
59   {
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));
63   }
64
65   /* = apr_pstrcat(pool,
66                    "/",
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])
71     *fs_path = "/";
72   else if (repos_dirent[root_end] == '/')
73     *fs_path = &repos_dirent[root_end];
74   else
75     {
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] == '/');
79     }
80
81   /* Remove the path components after the root dirent from the original URL,
82      to get a URL to the repository root.
83
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.
87
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)
91
92           On on Windows:
93           file:///dir -> file:///E:/dir  (When E: is the current disk)
94      */
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;
100
101   /* Configure hook script environment variables. */
102   SVN_ERR(svn_repos_hooks_setenv(*repos, NULL, pool));
103
104   return SVN_NO_ERROR;
105 }