]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/subversion/subversion/libsvn_delta/branch_repos.c
Update svn-1.9.7 to 1.10.0.
[FreeBSD/FreeBSD.git] / contrib / subversion / subversion / libsvn_delta / branch_repos.c
1 /*
2  * branch_repos.c : Element-Based Branching and Move Tracking.
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 <assert.h>
25
26 #include "svn_types.h"
27 #include "svn_error.h"
28 #include "svn_dirent_uri.h"
29 #include "svn_iter.h"
30
31 #include "private/svn_branch_repos.h"
32 #include "svn_private_config.h"
33
34
35 /* Per-repository branching info.
36  */
37 struct svn_branch__repos_t
38 {
39   /* Array of (svn_branch__txn_t *), indexed by revision number. */
40   apr_array_header_t *rev_roots;
41
42   /* The pool in which this object lives. */
43   apr_pool_t *pool;
44 };
45
46
47 svn_branch__repos_t *
48 svn_branch__repos_create(apr_pool_t *result_pool)
49 {
50   svn_branch__repos_t *repos = apr_pcalloc(result_pool, sizeof(*repos));
51
52   repos->rev_roots = apr_array_make(result_pool, 0, sizeof(void *));
53   repos->pool = result_pool;
54   return repos;
55 }
56
57 svn_error_t *
58 svn_branch__repos_add_revision(svn_branch__repos_t *repos,
59                                svn_branch__txn_t *rev_root)
60 {
61   APR_ARRAY_PUSH(repos->rev_roots, void *) = rev_root;
62
63   return SVN_NO_ERROR;
64 }
65
66 struct svn_branch__txn_t *
67 svn_branch__repos_get_revision(const svn_branch__repos_t *repos,
68                                svn_revnum_t revnum)
69 {
70   assert(revnum < repos->rev_roots->nelts);
71   return APR_ARRAY_IDX(repos->rev_roots, revnum, void *);
72 }
73
74 svn_branch__txn_t *
75 svn_branch__repos_get_base_revision_root(svn_branch__txn_t *rev_root)
76 {
77   return svn_branch__repos_get_revision(rev_root->repos, rev_root->base_rev);
78 }
79
80 svn_error_t *
81 svn_branch__repos_get_branch_by_id(svn_branch__state_t **branch_p,
82                                    const svn_branch__repos_t *repos,
83                                    svn_revnum_t revnum,
84                                    const char *branch_id,
85                                    apr_pool_t *scratch_pool)
86 {
87   svn_branch__txn_t *rev_root;
88
89   if (revnum < 0 || revnum >= repos->rev_roots->nelts)
90     return svn_error_createf(SVN_ERR_FS_NO_SUCH_REVISION, NULL,
91                              _("No such revision %ld"), revnum);
92
93   rev_root = svn_branch__repos_get_revision(repos, revnum);
94   *branch_p = svn_branch__txn_get_branch_by_id(rev_root, branch_id,
95                                                scratch_pool);
96   if (! *branch_p)
97     return svn_error_createf(SVN_BRANCH__ERR, NULL,
98                              _("Branch %s not found in r%ld"),
99                              branch_id, revnum);
100   return SVN_NO_ERROR;
101 }
102
103 svn_error_t *
104 svn_branch__repos_find_el_rev_by_id(svn_branch__el_rev_id_t **el_rev_p,
105                                     const svn_branch__repos_t *repos,
106                                     svn_revnum_t revnum,
107                                     const char *branch_id,
108                                     int eid,
109                                     apr_pool_t *result_pool,
110                                     apr_pool_t *scratch_pool)
111 {
112   svn_branch__el_rev_id_t *el_rev = apr_palloc(result_pool, sizeof(*el_rev));
113   svn_element__content_t *element;
114
115   el_rev->rev = revnum;
116   SVN_ERR(svn_branch__repos_get_branch_by_id(&el_rev->branch,
117                                              repos, revnum, branch_id,
118                                              scratch_pool));
119   SVN_ERR(svn_branch__state_get_element(el_rev->branch, &element,
120                                         eid, scratch_pool));
121   if (element)
122     {
123       el_rev->eid = eid;
124     }
125   else
126     {
127       el_rev->eid = -1;
128     }
129   *el_rev_p = el_rev;
130   return SVN_NO_ERROR;
131 }
132