]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/subversion/subversion/libsvn_ra_local/split_url.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.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
43   SVN_ERR(svn_uri_get_dirent_from_file_url(&repos_dirent, URL, pool));
44
45   /* Search for a repository in the full path. */
46   repos_root_dirent = svn_repos_find_root_path(repos_dirent, pool);
47   if (!repos_root_dirent)
48     return svn_error_createf(SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED, NULL,
49                              _("Unable to open repository '%s'"), URL);
50
51   /* Attempt to open a repository at URL. */
52   err = svn_repos_open2(repos, repos_root_dirent, NULL, pool);
53   if (err)
54     return svn_error_createf(SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED, err,
55                              _("Unable to open repository '%s'"), URL);
56
57   /* Assert capabilities directly, since client == server. */
58   {
59     apr_array_header_t *caps = apr_array_make(pool, 1, sizeof(const char *));
60     APR_ARRAY_PUSH(caps, const char *) = SVN_RA_CAPABILITY_MERGEINFO;
61     SVN_ERR(svn_repos_remember_client_capabilities(*repos, caps));
62   }
63
64   /* = apr_pstrcat(pool,
65                    "/",
66                    svn_dirent_skip_ancestor(repos_root_dirent, repos_dirent),
67                    (const char *)NULL); */
68   *fs_path = &repos_dirent[strlen(repos_root_dirent)];
69
70   if (**fs_path == '\0')
71     *fs_path = "/";
72
73   /* Remove the path components after the root dirent from the original URL,
74      to get a URL to the repository root.
75
76      We don't use svn_uri_get_file_url_from_dirent() here as that would
77      transform several uris to form a differently formed url than
78      svn_uri_canonicalize would.
79
80      E.g. file://localhost/C:/dir -> file:///C:/dir
81           (a transform that was originally supported directly by this function,
82            before the implementation moved)
83
84           On on Windows:
85           file:///dir -> file:///E:/dir  (When E: is the current disk)
86      */
87   urlbuf = svn_stringbuf_create(URL, pool);
88   svn_path_remove_components(urlbuf,
89                              svn_path_component_count(repos_dirent)
90                              - svn_path_component_count(repos_root_dirent));
91   *repos_url = urlbuf->data;
92
93   /* Configure hook script environment variables. */
94   SVN_ERR(svn_repos_hooks_setenv(*repos, NULL, pool));
95
96   return SVN_NO_ERROR;
97 }