2 * branch_repos.c : Element-Based Branching and Move Tracking.
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 * ====================================================================
26 #include "svn_types.h"
27 #include "svn_error.h"
28 #include "svn_dirent_uri.h"
31 #include "private/svn_branch_repos.h"
32 #include "svn_private_config.h"
35 /* Per-repository branching info.
37 struct svn_branch__repos_t
39 /* Array of (svn_branch__txn_t *), indexed by revision number. */
40 apr_array_header_t *rev_roots;
42 /* The pool in which this object lives. */
48 svn_branch__repos_create(apr_pool_t *result_pool)
50 svn_branch__repos_t *repos = apr_pcalloc(result_pool, sizeof(*repos));
52 repos->rev_roots = apr_array_make(result_pool, 0, sizeof(void *));
53 repos->pool = result_pool;
58 svn_branch__repos_add_revision(svn_branch__repos_t *repos,
59 svn_branch__txn_t *rev_root)
61 APR_ARRAY_PUSH(repos->rev_roots, void *) = rev_root;
66 struct svn_branch__txn_t *
67 svn_branch__repos_get_revision(const svn_branch__repos_t *repos,
70 assert(revnum < repos->rev_roots->nelts);
71 return APR_ARRAY_IDX(repos->rev_roots, revnum, void *);
75 svn_branch__repos_get_base_revision_root(svn_branch__txn_t *rev_root)
77 return svn_branch__repos_get_revision(rev_root->repos, rev_root->base_rev);
81 svn_branch__repos_get_branch_by_id(svn_branch__state_t **branch_p,
82 const svn_branch__repos_t *repos,
84 const char *branch_id,
85 apr_pool_t *scratch_pool)
87 svn_branch__txn_t *rev_root;
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);
93 rev_root = svn_branch__repos_get_revision(repos, revnum);
94 *branch_p = svn_branch__txn_get_branch_by_id(rev_root, branch_id,
97 return svn_error_createf(SVN_BRANCH__ERR, NULL,
98 _("Branch %s not found in r%ld"),
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,
107 const char *branch_id,
109 apr_pool_t *result_pool,
110 apr_pool_t *scratch_pool)
112 svn_branch__el_rev_id_t *el_rev = apr_palloc(result_pool, sizeof(*el_rev));
113 svn_element__content_t *element;
115 el_rev->rev = revnum;
116 SVN_ERR(svn_branch__repos_get_branch_by_id(&el_rev->branch,
117 repos, revnum, branch_id,
119 SVN_ERR(svn_branch__state_get_element(el_rev->branch, &element,