1 /* node-rev.c --- storing and retrieving NODE-REVISION skels
2 *
3 * ====================================================================
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 * ====================================================================
21 */
22
23 #include <string.h>
24
25 #define SVN_WANT_BDB
26 #include "svn_private_config.h"
27
28 #include "svn_fs.h"
29 #include "fs.h"
30 #include "err.h"
31 #include "node-rev.h"
32 #include "reps-strings.h"
33 #include "id.h"
34 #include "../libsvn_fs/fs-loader.h"
35
36 #include "bdb/nodes-table.h"
37 #include "bdb/node-origins-table.h"
38
39
40 /* Creating completely new nodes. */
41
42
43 svn_error_t *
svn_fs_base__create_node(const svn_fs_id_t ** id_p,svn_fs_t * fs,node_revision_t * noderev,const char * copy_id,const char * txn_id,trail_t * trail,apr_pool_t * pool)44 svn_fs_base__create_node(const svn_fs_id_t **id_p,
45 svn_fs_t *fs,
46 node_revision_t *noderev,
47 const char *copy_id,
48 const char *txn_id,
49 trail_t *trail,
50 apr_pool_t *pool)
51 {
52 svn_fs_id_t *id;
53 base_fs_data_t *bfd = fs->fsap_data;
54
55 /* Find an unused ID for the node. */
56 SVN_ERR(svn_fs_bdb__new_node_id(&id, fs, copy_id, txn_id, trail, pool));
57
58 /* Store its NODE-REVISION skel. */
59 SVN_ERR(svn_fs_bdb__put_node_revision(fs, id, noderev, trail, pool));
60
61 /* Add a record in the node origins index table if our format
62 supports it. */
63 if (bfd->format >= SVN_FS_BASE__MIN_NODE_ORIGINS_FORMAT)
64 {
65 SVN_ERR(svn_fs_bdb__set_node_origin(fs, svn_fs_base__id_node_id(id),
66 id, trail, pool));
67 }
68
69 *id_p = id;
70 return SVN_NO_ERROR;
71 }
72
73
74
75 /* Creating new revisions of existing nodes. */
76
77 svn_error_t *
svn_fs_base__create_successor(const svn_fs_id_t ** new_id_p,svn_fs_t * fs,const svn_fs_id_t * old_id,node_revision_t * new_noderev,const char * copy_id,const char * txn_id,trail_t * trail,apr_pool_t * pool)78 svn_fs_base__create_successor(const svn_fs_id_t **new_id_p,
79 svn_fs_t *fs,
80 const svn_fs_id_t *old_id,
81 node_revision_t *new_noderev,
82 const char *copy_id,
83 const char *txn_id,
84 trail_t *trail,
85 apr_pool_t *pool)
86 {
87 svn_fs_id_t *new_id;
88
89 /* Choose an ID for the new node, and store it in the database. */
90 SVN_ERR(svn_fs_bdb__new_successor_id(&new_id, fs, old_id, copy_id,
91 txn_id, trail, pool));
92
93 /* Store the new skel under that ID. */
94 SVN_ERR(svn_fs_bdb__put_node_revision(fs, new_id, new_noderev,
95 trail, pool));
96
97 *new_id_p = new_id;
98 return SVN_NO_ERROR;
99 }
100
101
102
103 /* Deleting a node revision. */
104
105 svn_error_t *
svn_fs_base__delete_node_revision(svn_fs_t * fs,const svn_fs_id_t * id,svn_boolean_t origin_also,trail_t * trail,apr_pool_t * pool)106 svn_fs_base__delete_node_revision(svn_fs_t *fs,
107 const svn_fs_id_t *id,
108 svn_boolean_t origin_also,
109 trail_t *trail,
110 apr_pool_t *pool)
111 {
112 base_fs_data_t *bfd = fs->fsap_data;
113
114 /* ### todo: here, we should adjust other nodes to compensate for
115 the missing node. */
116
117 /* Delete the node origin record, too, if asked to do so and our
118 format supports it. */
119 if (origin_also && (bfd->format >= SVN_FS_BASE__MIN_NODE_ORIGINS_FORMAT))
120 {
121 SVN_ERR(svn_fs_bdb__delete_node_origin(fs, svn_fs_base__id_node_id(id),
122 trail, pool));
123 }
124
125 return svn_fs_bdb__delete_nodes_entry(fs, id, trail, pool);
126 }
127