1289177Speter/* transaction.h --- transaction-related functions of FSX
2289177Speter *
3289177Speter * ====================================================================
4289177Speter *    Licensed to the Apache Software Foundation (ASF) under one
5289177Speter *    or more contributor license agreements.  See the NOTICE file
6289177Speter *    distributed with this work for additional information
7289177Speter *    regarding copyright ownership.  The ASF licenses this file
8289177Speter *    to you under the Apache License, Version 2.0 (the
9289177Speter *    "License"); you may not use this file except in compliance
10289177Speter *    with the License.  You may obtain a copy of the License at
11289177Speter *
12289177Speter *      http://www.apache.org/licenses/LICENSE-2.0
13289177Speter *
14289177Speter *    Unless required by applicable law or agreed to in writing,
15289177Speter *    software distributed under the License is distributed on an
16289177Speter *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17289177Speter *    KIND, either express or implied.  See the License for the
18289177Speter *    specific language governing permissions and limitations
19289177Speter *    under the License.
20289177Speter * ====================================================================
21289177Speter */
22289177Speter
23362181Sdim#ifndef SVN_LIBSVN_FS_X_TRANSACTION_H
24362181Sdim#define SVN_LIBSVN_FS_X_TRANSACTION_H
25289177Speter
26289177Speter#include "fs.h"
27289177Speter
28289177Speter/* Return the transaction ID of TXN.
29289177Speter */
30289177Spetersvn_fs_x__txn_id_t
31289177Spetersvn_fs_x__txn_get_id(svn_fs_txn_t *txn);
32289177Speter
33289177Speter/* Obtain a write lock on the filesystem FS in a subpool of SCRATCH_POOL,
34289177Speter   call BODY with BATON and that subpool, destroy the subpool (releasing the
35289177Speter   write lock) and return what BODY returned. */
36289177Spetersvn_error_t *
37289177Spetersvn_fs_x__with_write_lock(svn_fs_t *fs,
38289177Speter                          svn_error_t *(*body)(void *baton,
39289177Speter                                               apr_pool_t *scratch_pool),
40289177Speter                          void *baton,
41289177Speter                          apr_pool_t *scratch_pool);
42289177Speter
43289177Speter/* Obtain a pack operation lock on the filesystem FS in a subpool of
44289177Speter   SCRATCH_POOL, call BODY with BATON and that subpool, destroy the subpool
45289177Speter   (releasing the write lock) and return what BODY returned. */
46289177Spetersvn_error_t *
47289177Spetersvn_fs_x__with_pack_lock(svn_fs_t *fs,
48289177Speter                         svn_error_t *(*body)(void *baton,
49289177Speter                                              apr_pool_t *scratch_pool),
50289177Speter                         void *baton,
51289177Speter                         apr_pool_t *scratch_pool);
52289177Speter
53289177Speter/* Obtain the txn-current file lock on the filesystem FS in a subpool of
54289177Speter   SCRATCH_POOL, call BODY with BATON and that subpool, destroy the subpool
55289177Speter   (releasing the write lock) and return what BODY returned. */
56289177Spetersvn_error_t *
57289177Spetersvn_fs_x__with_txn_current_lock(svn_fs_t *fs,
58289177Speter                                svn_error_t *(*body)(void *baton,
59289177Speter                                                   apr_pool_t *scratch_pool),
60289177Speter                                void *baton,
61289177Speter                                apr_pool_t *scratch_pool);
62289177Speter
63289177Speter/* Obtain all locks on the filesystem FS in a subpool of SCRATCH_POOL,
64289177Speter   call BODY with BATON and that subpool, destroy the subpool (releasing
65289177Speter   the locks) and return what BODY returned.
66289177Speter
67362181Sdim   This combines svn_fs_x__with_write_lock, svn_fs_x__with_pack_lock,
68362181Sdim   and svn_fs_x__with_txn_current_lock, ensuring correct lock ordering. */
69289177Spetersvn_error_t *
70289177Spetersvn_fs_x__with_all_locks(svn_fs_t *fs,
71289177Speter                         svn_error_t *(*body)(void *baton,
72289177Speter                                              apr_pool_t *scratch_pool),
73289177Speter                         void *baton,
74289177Speter                         apr_pool_t *scratch_pool);
75289177Speter
76289177Speter/* Return TRUE, iff NODEREV is the root node of a transaction that has not
77289177Speter   seen any modifications, yet. */
78289177Spetersvn_boolean_t
79289177Spetersvn_fs_x__is_fresh_txn_root(svn_fs_x__noderev_t *noderev);
80289177Speter
81289177Speter/* Store NODEREV as the node-revision in the transaction defined by NODEREV's
82289177Speter   ID within FS.  Do any necessary temporary allocation in SCRATCH_POOL. */
83289177Spetersvn_error_t *
84289177Spetersvn_fs_x__put_node_revision(svn_fs_t *fs,
85289177Speter                            svn_fs_x__noderev_t *noderev,
86289177Speter                            apr_pool_t *scratch_pool);
87289177Speter
88289177Speter/* Find the paths which were changed in transaction TXN_ID of
89289177Speter   filesystem FS and store them in *CHANGED_PATHS_P.
90289177Speter   Get any temporary allocations from SCRATCH_POOL. */
91289177Spetersvn_error_t *
92289177Spetersvn_fs_x__txn_changes_fetch(apr_hash_t **changed_paths_p,
93289177Speter                            svn_fs_t *fs,
94289177Speter                            svn_fs_x__txn_id_t txn_id,
95289177Speter                            apr_pool_t *scratch_pool);
96289177Speter
97289177Speter/* Set the transaction property NAME to the value VALUE in transaction
98289177Speter   TXN.  Perform temporary allocations from SCRATCH_POOL. */
99289177Spetersvn_error_t *
100289177Spetersvn_fs_x__change_txn_prop(svn_fs_txn_t *txn,
101289177Speter                          const char *name,
102289177Speter                          const svn_string_t *value,
103289177Speter                          apr_pool_t *scratch_pool);
104289177Speter
105289177Speter/* Change transaction properties in transaction TXN based on PROPS.
106289177Speter   Perform temporary allocations from SCRATCH_POOL. */
107289177Spetersvn_error_t *
108289177Spetersvn_fs_x__change_txn_props(svn_fs_txn_t *txn,
109289177Speter                           const apr_array_header_t *props,
110289177Speter                           apr_pool_t *scratch_pool);
111289177Speter
112289177Speter/* Store a transaction record in *TXN_P for the transaction identified
113289177Speter   by TXN_ID in filesystem FS.  Allocate everything from POOL. */
114289177Spetersvn_error_t *
115289177Spetersvn_fs_x__get_txn(svn_fs_x__transaction_t **txn_p,
116289177Speter                  svn_fs_t *fs,
117289177Speter                  svn_fs_x__txn_id_t txn_id,
118289177Speter                  apr_pool_t *pool);
119289177Speter
120289177Speter/* Return the next available copy_id in *COPY_ID for the transaction
121289177Speter   TXN_ID in filesystem FS.  Allocate temporaries in SCRATCH_POOL. */
122289177Spetersvn_error_t *
123289177Spetersvn_fs_x__reserve_copy_id(svn_fs_x__id_t *copy_id_p,
124289177Speter                          svn_fs_t *fs,
125289177Speter                          svn_fs_x__txn_id_t txn_id,
126289177Speter                          apr_pool_t *scratch_pool);
127289177Speter
128289177Speter/* Create an entirely new mutable node in the filesystem FS, whose
129289177Speter   node-revision is NODEREV.  COPY_ID is the copy_id to use in the
130289177Speter   node revision ID.  TXN_ID is the Subversion transaction  under
131362181Sdim   which this occurs.  Use SCRATCH_POOL for temporary allocations. */
132289177Spetersvn_error_t *
133289177Spetersvn_fs_x__create_node(svn_fs_t *fs,
134289177Speter                      svn_fs_x__noderev_t *noderev,
135289177Speter                      const svn_fs_x__id_t *copy_id,
136289177Speter                      svn_fs_x__txn_id_t txn_id,
137289177Speter                      apr_pool_t *scratch_pool);
138289177Speter
139289177Speter/* Remove all references to the transaction TXN_ID from filesystem FS.
140289177Speter   Temporary allocations are from SCRATCH_POOL. */
141289177Spetersvn_error_t *
142289177Spetersvn_fs_x__purge_txn(svn_fs_t *fs,
143289177Speter                    const char *txn_id,
144289177Speter                    apr_pool_t *scratch_pool);
145289177Speter
146289177Speter/* Abort the existing transaction TXN, performing any temporary
147289177Speter   allocations in SCRATCH_POOL. */
148289177Spetersvn_error_t *
149289177Spetersvn_fs_x__abort_txn(svn_fs_txn_t *txn,
150289177Speter                    apr_pool_t *scratch_pool);
151289177Speter
152289177Speter/* Add or set in filesystem FS, transaction TXN_ID, in directory
153289177Speter   PARENT_NODEREV a directory entry for NAME pointing to ID of type
154289177Speter   KIND.  The PARENT_NODEREV's DATA_REP will be redirected to the in-txn
155289177Speter   representation, if it had not been mutable before.
156289177Speter
157289177Speter   If PARENT_NODEREV does not have a DATA_REP, allocate one in RESULT_POOL.
158289177Speter   Temporary allocations are done in SCRATCH_POOL. */
159289177Spetersvn_error_t *
160289177Spetersvn_fs_x__set_entry(svn_fs_t *fs,
161289177Speter                    svn_fs_x__txn_id_t txn_id,
162289177Speter                    svn_fs_x__noderev_t *parent_noderev,
163289177Speter                    const char *name,
164289177Speter                    const svn_fs_x__id_t *id,
165289177Speter                    svn_node_kind_t kind,
166289177Speter                    apr_pool_t *result_pool,
167289177Speter                    apr_pool_t *scratch_pool);
168289177Speter
169289177Speter/* Add a change to the changes record for filesystem FS in transaction
170362181Sdim   TXN_ID.  Mark path PATH as changed according to the type in
171362181Sdim   CHANGE_KIND.  If the text representation was changed set TEXT_MOD
172362181Sdim   to TRUE, and likewise for PROP_MOD as well as MERGEINFO_MOD.
173289177Speter   If this change was the result of a copy, set COPYFROM_REV and
174289177Speter   COPYFROM_PATH to the revision and path of the copy source, otherwise
175289177Speter   they should be set to SVN_INVALID_REVNUM and NULL.  Perform any
176289177Speter   temporary allocations from SCRATCH_POOL. */
177289177Spetersvn_error_t *
178289177Spetersvn_fs_x__add_change(svn_fs_t *fs,
179289177Speter                     svn_fs_x__txn_id_t txn_id,
180289177Speter                     const char *path,
181289177Speter                     svn_fs_path_change_kind_t change_kind,
182289177Speter                     svn_boolean_t text_mod,
183289177Speter                     svn_boolean_t prop_mod,
184289177Speter                     svn_boolean_t mergeinfo_mod,
185289177Speter                     svn_node_kind_t node_kind,
186289177Speter                     svn_revnum_t copyfrom_rev,
187289177Speter                     const char *copyfrom_path,
188289177Speter                     apr_pool_t *scratch_pool);
189289177Speter
190289177Speter/* Return a writable stream in *STREAM, allocated in RESULT_POOL, that
191289177Speter   allows storing the text representation of node-revision NODEREV in
192289177Speter   filesystem FS. */
193289177Spetersvn_error_t *
194289177Spetersvn_fs_x__set_contents(svn_stream_t **stream,
195289177Speter                       svn_fs_t *fs,
196289177Speter                       svn_fs_x__noderev_t *noderev,
197289177Speter                       apr_pool_t *result_pool);
198289177Speter
199289177Speter/* Create a node revision in FS which is an immediate successor of
200289177Speter   NEW_NODEREV's predecessor.  Use SCRATCH_POOL for any temporary allocation.
201289177Speter
202289177Speter   COPY_ID, is a key into the `copies' table, and
203289177Speter   indicates that this new node is being created as the result of a
204289177Speter   copy operation, and specifically which operation that was.
205289177Speter
206289177Speter   TXN_ID is the Subversion transaction under which this occurs.
207289177Speter
208289177Speter   After this call, the deltification code assumes that the new node's
209289177Speter   contents will change frequently, and will avoid representing other
210289177Speter   nodes as deltas against this node's contents.  */
211289177Spetersvn_error_t *
212289177Spetersvn_fs_x__create_successor(svn_fs_t *fs,
213289177Speter                           svn_fs_x__noderev_t *new_noderev,
214289177Speter                           const svn_fs_x__id_t *copy_id,
215289177Speter                           svn_fs_x__txn_id_t txn_id,
216289177Speter                           apr_pool_t *scratch_pool);
217289177Speter
218289177Speter/* Write a new property list PROPLIST for node-revision NODEREV in
219289177Speter   filesystem FS.  Perform any temporary allocations in SCRATCH_POOL. */
220289177Spetersvn_error_t *
221289177Spetersvn_fs_x__set_proplist(svn_fs_t *fs,
222289177Speter                       svn_fs_x__noderev_t *noderev,
223289177Speter                       apr_hash_t *proplist,
224289177Speter                       apr_pool_t *scratch_pool);
225289177Speter
226289177Speter/* Append the L2P and P2L indexes given by their proto index file names
227289177Speter * L2P_PROTO_INDEX and P2L_PROTO_INDEX to the revision / pack FILE.
228289177Speter * The latter contains revision(s) starting at REVISION in FS.
229289177Speter * Use SCRATCH_POOL for temporary allocations.  */
230289177Spetersvn_error_t *
231289177Spetersvn_fs_x__add_index_data(svn_fs_t *fs,
232289177Speter                         apr_file_t *file,
233289177Speter                         const char *l2p_proto_index,
234289177Speter                         const char *p2l_proto_index,
235289177Speter                         svn_revnum_t revision,
236289177Speter                         apr_pool_t *scratch_pool);
237289177Speter
238289177Speter/* Commit the transaction TXN in filesystem FS and return its new
239289177Speter   revision number in *REV.  If the transaction is out of date, return
240289177Speter   the error SVN_ERR_FS_TXN_OUT_OF_DATE. Use SCRATCH_POOL for temporary
241289177Speter   allocations. */
242289177Spetersvn_error_t *
243289177Spetersvn_fs_x__commit(svn_revnum_t *new_rev_p,
244289177Speter                 svn_fs_t *fs,
245289177Speter                 svn_fs_txn_t *txn,
246289177Speter                 apr_pool_t *scratch_pool);
247289177Speter
248289177Speter/* Set *NAMES_P to an array of names which are all the active
249289177Speter   transactions in filesystem FS.  Allocate the array from POOL. */
250289177Spetersvn_error_t *
251289177Spetersvn_fs_x__list_transactions(apr_array_header_t **names_p,
252289177Speter                            svn_fs_t *fs,
253289177Speter                            apr_pool_t *pool);
254289177Speter
255289177Speter/* Open the transaction named NAME in filesystem FS.  Set *TXN_P to
256289177Speter * the transaction. If there is no such transaction, return
257289177Speter` * SVN_ERR_FS_NO_SUCH_TRANSACTION.  Allocate the new transaction in
258289177Speter * POOL. */
259289177Spetersvn_error_t *
260289177Spetersvn_fs_x__open_txn(svn_fs_txn_t **txn_p,
261289177Speter                   svn_fs_t *fs,
262289177Speter                   const char *name,
263289177Speter                   apr_pool_t *pool);
264289177Speter
265289177Speter/* Return the property list from transaction TXN and store it in
266289177Speter   *PROPLIST.  Allocate the property list from POOL. */
267289177Spetersvn_error_t *
268289177Spetersvn_fs_x__txn_proplist(apr_hash_t **table_p,
269289177Speter                       svn_fs_txn_t *txn,
270289177Speter                       apr_pool_t *pool);
271289177Speter
272289177Speter/* Delete the mutable node-revision referenced by ID, along with any
273289177Speter   mutable props or directory contents associated with it.  Perform
274289177Speter   temporary allocations in SCRATCH_POOL. */
275289177Spetersvn_error_t *
276289177Spetersvn_fs_x__delete_node_revision(svn_fs_t *fs,
277289177Speter                               const svn_fs_x__id_t *id,
278289177Speter                               apr_pool_t *scratch_pool);
279289177Speter
280289177Speter/* Retrieve information about the Subversion transaction TXN_ID from
281289177Speter   the `transactions' table of FS, using SCRATCH_POOL for temporary
282289177Speter   allocations.  Set *RENUM to the transaction's base revision.
283289177Speter
284289177Speter   If there is no such transaction, SVN_ERR_FS_NO_SUCH_TRANSACTION is
285289177Speter   the error returned.
286289177Speter
287289177Speter   Returns SVN_ERR_FS_TRANSACTION_NOT_MUTABLE if TXN_NAME refers to a
288289177Speter   transaction that has already been committed.  */
289289177Spetersvn_error_t *
290289177Spetersvn_fs_x__get_base_rev(svn_revnum_t *revnum,
291289177Speter                       svn_fs_t *fs,
292289177Speter                       svn_fs_x__txn_id_t txn_id,
293289177Speter                       apr_pool_t *scratch_pool);
294289177Speter
295289177Speter/* Find the value of the property named PROPNAME in transaction TXN.
296289177Speter   Return the contents in *VALUE_P.  The contents will be allocated
297289177Speter   from POOL. */
298289177Spetersvn_error_t *
299289177Spetersvn_fs_x__txn_prop(svn_string_t **value_p,
300289177Speter                   svn_fs_txn_t *txn,
301289177Speter                   const char *propname,
302289177Speter                   apr_pool_t *pool);
303289177Speter
304289177Speter/* Begin a new transaction in filesystem FS, based on existing
305289177Speter   revision REV.  The new transaction is returned in *TXN_P, allocated
306289177Speter   in RESULT_POOL.  Allocate temporaries from SCRATCH_POOL. */
307289177Spetersvn_error_t *
308289177Spetersvn_fs_x__begin_txn(svn_fs_txn_t **txn_p,
309289177Speter                    svn_fs_t *fs,
310289177Speter                    svn_revnum_t rev,
311289177Speter                    apr_uint32_t flags,
312289177Speter                    apr_pool_t *result_pool,
313289177Speter                    apr_pool_t *scratch_pool);
314289177Speter
315289177Speter#endif
316