transaction.h revision 362181
1/* transaction.h --- transaction-related functions of FSX
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#ifndef SVN_LIBSVN_FS_X_TRANSACTION_H
24#define SVN_LIBSVN_FS_X_TRANSACTION_H
25
26#include "fs.h"
27
28/* Return the transaction ID of TXN.
29 */
30svn_fs_x__txn_id_t
31svn_fs_x__txn_get_id(svn_fs_txn_t *txn);
32
33/* Obtain a write lock on the filesystem FS in a subpool of SCRATCH_POOL,
34   call BODY with BATON and that subpool, destroy the subpool (releasing the
35   write lock) and return what BODY returned. */
36svn_error_t *
37svn_fs_x__with_write_lock(svn_fs_t *fs,
38                          svn_error_t *(*body)(void *baton,
39                                               apr_pool_t *scratch_pool),
40                          void *baton,
41                          apr_pool_t *scratch_pool);
42
43/* Obtain a pack operation lock on the filesystem FS in a subpool of
44   SCRATCH_POOL, call BODY with BATON and that subpool, destroy the subpool
45   (releasing the write lock) and return what BODY returned. */
46svn_error_t *
47svn_fs_x__with_pack_lock(svn_fs_t *fs,
48                         svn_error_t *(*body)(void *baton,
49                                              apr_pool_t *scratch_pool),
50                         void *baton,
51                         apr_pool_t *scratch_pool);
52
53/* Obtain the txn-current file lock on the filesystem FS in a subpool of
54   SCRATCH_POOL, call BODY with BATON and that subpool, destroy the subpool
55   (releasing the write lock) and return what BODY returned. */
56svn_error_t *
57svn_fs_x__with_txn_current_lock(svn_fs_t *fs,
58                                svn_error_t *(*body)(void *baton,
59                                                   apr_pool_t *scratch_pool),
60                                void *baton,
61                                apr_pool_t *scratch_pool);
62
63/* Obtain all locks on the filesystem FS in a subpool of SCRATCH_POOL,
64   call BODY with BATON and that subpool, destroy the subpool (releasing
65   the locks) and return what BODY returned.
66
67   This combines svn_fs_x__with_write_lock, svn_fs_x__with_pack_lock,
68   and svn_fs_x__with_txn_current_lock, ensuring correct lock ordering. */
69svn_error_t *
70svn_fs_x__with_all_locks(svn_fs_t *fs,
71                         svn_error_t *(*body)(void *baton,
72                                              apr_pool_t *scratch_pool),
73                         void *baton,
74                         apr_pool_t *scratch_pool);
75
76/* Return TRUE, iff NODEREV is the root node of a transaction that has not
77   seen any modifications, yet. */
78svn_boolean_t
79svn_fs_x__is_fresh_txn_root(svn_fs_x__noderev_t *noderev);
80
81/* Store NODEREV as the node-revision in the transaction defined by NODEREV's
82   ID within FS.  Do any necessary temporary allocation in SCRATCH_POOL. */
83svn_error_t *
84svn_fs_x__put_node_revision(svn_fs_t *fs,
85                            svn_fs_x__noderev_t *noderev,
86                            apr_pool_t *scratch_pool);
87
88/* Find the paths which were changed in transaction TXN_ID of
89   filesystem FS and store them in *CHANGED_PATHS_P.
90   Get any temporary allocations from SCRATCH_POOL. */
91svn_error_t *
92svn_fs_x__txn_changes_fetch(apr_hash_t **changed_paths_p,
93                            svn_fs_t *fs,
94                            svn_fs_x__txn_id_t txn_id,
95                            apr_pool_t *scratch_pool);
96
97/* Set the transaction property NAME to the value VALUE in transaction
98   TXN.  Perform temporary allocations from SCRATCH_POOL. */
99svn_error_t *
100svn_fs_x__change_txn_prop(svn_fs_txn_t *txn,
101                          const char *name,
102                          const svn_string_t *value,
103                          apr_pool_t *scratch_pool);
104
105/* Change transaction properties in transaction TXN based on PROPS.
106   Perform temporary allocations from SCRATCH_POOL. */
107svn_error_t *
108svn_fs_x__change_txn_props(svn_fs_txn_t *txn,
109                           const apr_array_header_t *props,
110                           apr_pool_t *scratch_pool);
111
112/* Store a transaction record in *TXN_P for the transaction identified
113   by TXN_ID in filesystem FS.  Allocate everything from POOL. */
114svn_error_t *
115svn_fs_x__get_txn(svn_fs_x__transaction_t **txn_p,
116                  svn_fs_t *fs,
117                  svn_fs_x__txn_id_t txn_id,
118                  apr_pool_t *pool);
119
120/* Return the next available copy_id in *COPY_ID for the transaction
121   TXN_ID in filesystem FS.  Allocate temporaries in SCRATCH_POOL. */
122svn_error_t *
123svn_fs_x__reserve_copy_id(svn_fs_x__id_t *copy_id_p,
124                          svn_fs_t *fs,
125                          svn_fs_x__txn_id_t txn_id,
126                          apr_pool_t *scratch_pool);
127
128/* Create an entirely new mutable node in the filesystem FS, whose
129   node-revision is NODEREV.  COPY_ID is the copy_id to use in the
130   node revision ID.  TXN_ID is the Subversion transaction  under
131   which this occurs.  Use SCRATCH_POOL for temporary allocations. */
132svn_error_t *
133svn_fs_x__create_node(svn_fs_t *fs,
134                      svn_fs_x__noderev_t *noderev,
135                      const svn_fs_x__id_t *copy_id,
136                      svn_fs_x__txn_id_t txn_id,
137                      apr_pool_t *scratch_pool);
138
139/* Remove all references to the transaction TXN_ID from filesystem FS.
140   Temporary allocations are from SCRATCH_POOL. */
141svn_error_t *
142svn_fs_x__purge_txn(svn_fs_t *fs,
143                    const char *txn_id,
144                    apr_pool_t *scratch_pool);
145
146/* Abort the existing transaction TXN, performing any temporary
147   allocations in SCRATCH_POOL. */
148svn_error_t *
149svn_fs_x__abort_txn(svn_fs_txn_t *txn,
150                    apr_pool_t *scratch_pool);
151
152/* Add or set in filesystem FS, transaction TXN_ID, in directory
153   PARENT_NODEREV a directory entry for NAME pointing to ID of type
154   KIND.  The PARENT_NODEREV's DATA_REP will be redirected to the in-txn
155   representation, if it had not been mutable before.
156
157   If PARENT_NODEREV does not have a DATA_REP, allocate one in RESULT_POOL.
158   Temporary allocations are done in SCRATCH_POOL. */
159svn_error_t *
160svn_fs_x__set_entry(svn_fs_t *fs,
161                    svn_fs_x__txn_id_t txn_id,
162                    svn_fs_x__noderev_t *parent_noderev,
163                    const char *name,
164                    const svn_fs_x__id_t *id,
165                    svn_node_kind_t kind,
166                    apr_pool_t *result_pool,
167                    apr_pool_t *scratch_pool);
168
169/* Add a change to the changes record for filesystem FS in transaction
170   TXN_ID.  Mark path PATH as changed according to the type in
171   CHANGE_KIND.  If the text representation was changed set TEXT_MOD
172   to TRUE, and likewise for PROP_MOD as well as MERGEINFO_MOD.
173   If this change was the result of a copy, set COPYFROM_REV and
174   COPYFROM_PATH to the revision and path of the copy source, otherwise
175   they should be set to SVN_INVALID_REVNUM and NULL.  Perform any
176   temporary allocations from SCRATCH_POOL. */
177svn_error_t *
178svn_fs_x__add_change(svn_fs_t *fs,
179                     svn_fs_x__txn_id_t txn_id,
180                     const char *path,
181                     svn_fs_path_change_kind_t change_kind,
182                     svn_boolean_t text_mod,
183                     svn_boolean_t prop_mod,
184                     svn_boolean_t mergeinfo_mod,
185                     svn_node_kind_t node_kind,
186                     svn_revnum_t copyfrom_rev,
187                     const char *copyfrom_path,
188                     apr_pool_t *scratch_pool);
189
190/* Return a writable stream in *STREAM, allocated in RESULT_POOL, that
191   allows storing the text representation of node-revision NODEREV in
192   filesystem FS. */
193svn_error_t *
194svn_fs_x__set_contents(svn_stream_t **stream,
195                       svn_fs_t *fs,
196                       svn_fs_x__noderev_t *noderev,
197                       apr_pool_t *result_pool);
198
199/* Create a node revision in FS which is an immediate successor of
200   NEW_NODEREV's predecessor.  Use SCRATCH_POOL for any temporary allocation.
201
202   COPY_ID, is a key into the `copies' table, and
203   indicates that this new node is being created as the result of a
204   copy operation, and specifically which operation that was.
205
206   TXN_ID is the Subversion transaction under which this occurs.
207
208   After this call, the deltification code assumes that the new node's
209   contents will change frequently, and will avoid representing other
210   nodes as deltas against this node's contents.  */
211svn_error_t *
212svn_fs_x__create_successor(svn_fs_t *fs,
213                           svn_fs_x__noderev_t *new_noderev,
214                           const svn_fs_x__id_t *copy_id,
215                           svn_fs_x__txn_id_t txn_id,
216                           apr_pool_t *scratch_pool);
217
218/* Write a new property list PROPLIST for node-revision NODEREV in
219   filesystem FS.  Perform any temporary allocations in SCRATCH_POOL. */
220svn_error_t *
221svn_fs_x__set_proplist(svn_fs_t *fs,
222                       svn_fs_x__noderev_t *noderev,
223                       apr_hash_t *proplist,
224                       apr_pool_t *scratch_pool);
225
226/* Append the L2P and P2L indexes given by their proto index file names
227 * L2P_PROTO_INDEX and P2L_PROTO_INDEX to the revision / pack FILE.
228 * The latter contains revision(s) starting at REVISION in FS.
229 * Use SCRATCH_POOL for temporary allocations.  */
230svn_error_t *
231svn_fs_x__add_index_data(svn_fs_t *fs,
232                         apr_file_t *file,
233                         const char *l2p_proto_index,
234                         const char *p2l_proto_index,
235                         svn_revnum_t revision,
236                         apr_pool_t *scratch_pool);
237
238/* Commit the transaction TXN in filesystem FS and return its new
239   revision number in *REV.  If the transaction is out of date, return
240   the error SVN_ERR_FS_TXN_OUT_OF_DATE. Use SCRATCH_POOL for temporary
241   allocations. */
242svn_error_t *
243svn_fs_x__commit(svn_revnum_t *new_rev_p,
244                 svn_fs_t *fs,
245                 svn_fs_txn_t *txn,
246                 apr_pool_t *scratch_pool);
247
248/* Set *NAMES_P to an array of names which are all the active
249   transactions in filesystem FS.  Allocate the array from POOL. */
250svn_error_t *
251svn_fs_x__list_transactions(apr_array_header_t **names_p,
252                            svn_fs_t *fs,
253                            apr_pool_t *pool);
254
255/* Open the transaction named NAME in filesystem FS.  Set *TXN_P to
256 * the transaction. If there is no such transaction, return
257` * SVN_ERR_FS_NO_SUCH_TRANSACTION.  Allocate the new transaction in
258 * POOL. */
259svn_error_t *
260svn_fs_x__open_txn(svn_fs_txn_t **txn_p,
261                   svn_fs_t *fs,
262                   const char *name,
263                   apr_pool_t *pool);
264
265/* Return the property list from transaction TXN and store it in
266   *PROPLIST.  Allocate the property list from POOL. */
267svn_error_t *
268svn_fs_x__txn_proplist(apr_hash_t **table_p,
269                       svn_fs_txn_t *txn,
270                       apr_pool_t *pool);
271
272/* Delete the mutable node-revision referenced by ID, along with any
273   mutable props or directory contents associated with it.  Perform
274   temporary allocations in SCRATCH_POOL. */
275svn_error_t *
276svn_fs_x__delete_node_revision(svn_fs_t *fs,
277                               const svn_fs_x__id_t *id,
278                               apr_pool_t *scratch_pool);
279
280/* Retrieve information about the Subversion transaction TXN_ID from
281   the `transactions' table of FS, using SCRATCH_POOL for temporary
282   allocations.  Set *RENUM to the transaction's base revision.
283
284   If there is no such transaction, SVN_ERR_FS_NO_SUCH_TRANSACTION is
285   the error returned.
286
287   Returns SVN_ERR_FS_TRANSACTION_NOT_MUTABLE if TXN_NAME refers to a
288   transaction that has already been committed.  */
289svn_error_t *
290svn_fs_x__get_base_rev(svn_revnum_t *revnum,
291                       svn_fs_t *fs,
292                       svn_fs_x__txn_id_t txn_id,
293                       apr_pool_t *scratch_pool);
294
295/* Find the value of the property named PROPNAME in transaction TXN.
296   Return the contents in *VALUE_P.  The contents will be allocated
297   from POOL. */
298svn_error_t *
299svn_fs_x__txn_prop(svn_string_t **value_p,
300                   svn_fs_txn_t *txn,
301                   const char *propname,
302                   apr_pool_t *pool);
303
304/* Begin a new transaction in filesystem FS, based on existing
305   revision REV.  The new transaction is returned in *TXN_P, allocated
306   in RESULT_POOL.  Allocate temporaries from SCRATCH_POOL. */
307svn_error_t *
308svn_fs_x__begin_txn(svn_fs_txn_t **txn_p,
309                    svn_fs_t *fs,
310                    svn_revnum_t rev,
311                    apr_uint32_t flags,
312                    apr_pool_t *result_pool,
313                    apr_pool_t *scratch_pool);
314
315#endif
316