]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/subversion/subversion/libsvn_fs_fs/low_level.h
MFC r275385 (by bapt):
[FreeBSD/stable/10.git] / contrib / subversion / subversion / libsvn_fs_fs / low_level.h
1 /* low_level.c --- low level r/w access to fs_fs file structures
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 "svn_fs.h"
24
25 #include "fs_fs.h"
26 #include "id.h"
27
28 /* Kinds that a node-rev can be. */
29 #define SVN_FS_FS__KIND_FILE          "file"
30 #define SVN_FS_FS__KIND_DIR           "dir"
31
32 /* The functions are grouped as follows:
33  *
34  * - revision trailer (up to format 6)
35  * - revision footer (since format 7)
36  * - changed path list
37  * - node revision
38  * - representation (as in "text:" and "props:" lines)
39  * - representation header ("PLAIN" and "DELTA" lines)
40  */
41
42 /* Given the last "few" bytes (should be at least 40) of revision REV in
43  * TRAILER,  parse the last line and return the offset of the root noderev
44  * in *ROOT_OFFSET and the offset of the changed paths list in
45  * *CHANGES_OFFSET.  Offsets are relative to the revision's start offset.
46  * ROOT_OFFSET and / or CHANGES_OFFSET may be NULL.
47  *
48  * Note that REV is only used to construct nicer error objects.
49  */
50 svn_error_t *
51 svn_fs_fs__parse_revision_trailer(apr_off_t *root_offset,
52                                   apr_off_t *changes_offset,
53                                   svn_stringbuf_t *trailer,
54                                   svn_revnum_t rev);
55
56 /* Given the offset of the root noderev in ROOT_OFFSET and the offset of
57  * the changed paths list in CHANGES_OFFSET,  return the corresponding
58  * revision's trailer.  Allocate it in RESULT_POOL.
59  */
60 svn_stringbuf_t *
61 svn_fs_fs__unparse_revision_trailer(apr_off_t root_offset,
62                                     apr_off_t changes_offset,
63                                     apr_pool_t *result_pool);
64
65 /* Given the format 7+ revision / pack FOOTER, parse it destructively
66  * and return the start offsets of the index data in *L2P_OFFSET and
67  * *P2L_OFFSET, respectively.  Also, return the expected checksums in
68  * in *L2P_CHECKSUM and *P2L_CHECKSUM.
69  *
70  * Note that REV is only used to construct nicer error objects that
71  * mention this revision.  Allocate the checksums in RESULT_POOL.
72  */
73 svn_error_t *
74 svn_fs_fs__parse_footer(apr_off_t *l2p_offset,
75                         svn_checksum_t **l2p_checksum,
76                         apr_off_t *p2l_offset,
77                         svn_checksum_t **p2l_checksum,
78                         svn_stringbuf_t *footer,
79                         svn_revnum_t rev,
80                         apr_pool_t *result_pool);
81
82 /* Given the offset of the L2P index data in L2P_OFFSET, the content
83  * checksum in L2P_CHECKSUM and the offset plus checksum of the P2L
84  * index data in P2L_OFFSET and P2L_CHECKSUM.
85  *
86  * Return the corresponding format 7+ revision / pack file footer.
87  * Allocate it in RESULT_POOL and use SCRATCH_POOL for temporary.
88  */
89 svn_stringbuf_t *
90 svn_fs_fs__unparse_footer(apr_off_t l2p_offset,
91                           svn_checksum_t *l2p_checksum,
92                           apr_off_t p2l_offset,
93                           svn_checksum_t *p2l_checksum,
94                           apr_pool_t *result_pool,
95                           apr_pool_t *scratch_pool);
96
97 /* Read all the changes from STREAM and store them in *CHANGES,
98    allocated in RESULT_POOL. Do temporary allocations in SCRATCH_POOL. */
99 svn_error_t *
100 svn_fs_fs__read_changes(apr_array_header_t **changes,
101                         svn_stream_t *stream,
102                         apr_pool_t *result_pool,
103                         apr_pool_t *scratch_pool);
104
105 /* Callback function used by svn_fs_fs__read_changes_incrementally(),
106  * asking the receiver to process to process CHANGE using BATON.  CHANGE
107  * and SCRATCH_POOL will not be valid beyond the current callback invocation.
108  */
109 typedef svn_error_t *(*svn_fs_fs__change_receiver_t)(
110   void *baton,
111   change_t *change,
112   apr_pool_t *scratch_pool);
113
114 /* Read all the changes from STREAM and invoke CHANGE_RECEIVER on each change.
115    Do all allocations in SCRATCH_POOL. */
116 svn_error_t *
117 svn_fs_fs__read_changes_incrementally(svn_stream_t *stream,
118                                       svn_fs_fs__change_receiver_t
119                                         change_receiver,
120                                       void *change_receiver_baton,
121                                       apr_pool_t *scratch_pool);
122
123 /* Write the changed path info from CHANGES in filesystem FS to the
124    output stream STREAM.  You may call this function multiple time on
125    the same stream.  If you are writing to a (proto-)revision file,
126    the last call must set TERMINATE_LIST to write an extra empty line
127    that marks the end of the changed paths list.
128    Perform temporary allocations in SCRATCH_POOL.
129  */
130 svn_error_t *
131 svn_fs_fs__write_changes(svn_stream_t *stream,
132                          svn_fs_t *fs,
133                          apr_hash_t *changes,
134                          svn_boolean_t terminate_list,
135                          apr_pool_t *scratch_pool);
136
137 /* Read a node-revision from STREAM. Set *NODEREV to the new structure,
138    allocated in RESULT_POOL. */
139 svn_error_t *
140 svn_fs_fs__read_noderev(node_revision_t **noderev,
141                         svn_stream_t *stream,
142                         apr_pool_t *result_pool,
143                         apr_pool_t *scratch_pool);
144
145 /* Write the node-revision NODEREV into the stream OUTFILE, compatible with
146    filesystem format FORMAT.  Only write mergeinfo-related metadata if
147    INCLUDE_MERGEINFO is true.  Temporary allocations are from SCRATCH_POOL. */
148 svn_error_t *
149 svn_fs_fs__write_noderev(svn_stream_t *outfile,
150                          node_revision_t *noderev,
151                          int format,
152                          svn_boolean_t include_mergeinfo,
153                          apr_pool_t *scratch_pool);
154
155 /* Parse the description of a representation from TEXT and store it
156    into *REP_P.  TEXT will be invalidated by this call.  Allocate *REP_P in
157    RESULT_POOL and use SCRATCH_POOL for temporaries. */
158 svn_error_t *
159 svn_fs_fs__parse_representation(representation_t **rep_p,
160                                 svn_stringbuf_t *text,
161                                 apr_pool_t *result_pool,
162                                 apr_pool_t *scratch_pool);
163
164 /* Return a formatted string, compatible with filesystem format FORMAT,
165    that represents the location of representation REP.  If
166    MUTABLE_REP_TRUNCATED is given, the rep is for props or dir contents,
167    and only a "-1" revision number will be given for a mutable rep.
168    If MAY_BE_CORRUPT is true, guard for NULL when constructing the string.
169    Allocate the result in RESULT_POOL and temporaries in SCRATCH_POOL. */
170 svn_stringbuf_t *
171 svn_fs_fs__unparse_representation(representation_t *rep,
172                                   int format,
173                                   svn_boolean_t mutable_rep_truncated,
174                                   apr_pool_t *result_pool,
175                                   apr_pool_t *scratch_pool);
176
177 /* This type enumerates all forms of representations that we support. */
178 typedef enum svn_fs_fs__rep_type_t
179 {
180   /* this is a PLAIN representation */
181   svn_fs_fs__rep_plain,
182
183   /* this is a DELTA representation with no base representation */
184   svn_fs_fs__rep_self_delta,
185
186   /* this is a DELTA representation against some base representation */
187   svn_fs_fs__rep_delta
188 } svn_fs_fs__rep_type_t;
189
190 /* This structure is used to hold the information stored in a representation
191  * header. */
192 typedef struct svn_fs_fs__rep_header_t
193 {
194   /* type of the representation, i.e. whether it is PLAIN, self-DELTA etc. */
195   svn_fs_fs__rep_type_t type;
196
197   /* if this rep is a delta against some other rep, that base rep can
198    * be found in this revision.  Should be 0 if there is no base rep. */
199   svn_revnum_t base_revision;
200
201   /* if this rep is a delta against some other rep, that base rep can
202    * be found at this item index within the base rep's revision.  Should
203    * be 0 if there is no base rep. */
204   apr_off_t base_item_index;
205
206   /* if this rep is a delta against some other rep, this is the (deltified)
207    * size of that base rep.  Should be 0 if there is no base rep. */
208   svn_filesize_t base_length;
209
210   /* length of the textual representation of the header in the rep or pack
211    * file, including EOL.  Only valid after reading it from disk.
212    * Should be 0 otherwise. */
213   apr_size_t header_size;
214 } svn_fs_fs__rep_header_t;
215
216 /* Read the next line from STREAM and parse it as a text
217    representation header.  Return the parsed entry in *HEADER, allocated
218    in RESULT_POOL. Perform temporary allocations in SCRATCH_POOL. */
219 svn_error_t *
220 svn_fs_fs__read_rep_header(svn_fs_fs__rep_header_t **header,
221                            svn_stream_t *stream,
222                            apr_pool_t *result_pool,
223                            apr_pool_t *scratch_pool);
224
225 /* Write the representation HEADER to STREAM.
226  * Use SCRATCH_POOL for temporary allocations. */
227 svn_error_t *
228 svn_fs_fs__write_rep_header(svn_fs_fs__rep_header_t *header,
229                             svn_stream_t *stream,
230                             apr_pool_t *scratch_pool);