1 /* changes.h --- FSX changed paths lists container
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_CHANGES_H
24 #define SVN_LIBSVN_FS_X_CHANGES_H
25 
26 #include "svn_io.h"
27 #include "fs.h"
28 
29 /* Entries in a revision's change list tend to be widely redundant (similar
30  * changes to similar paths).  Even more so, change lists from a larger
31  * revision range also tend to overlap.
32  *
33  * In its serialized form, the svn_fs_x__changes_t container extracts most
34  * of that redundancy and the run-time representation is also much smaller
35  * than sum of the respective svn_fs_x__change_t* arrays.
36  *
37  * As with other containers, this one has two modes: 'construction', in
38  * which you may add data to it, and 'getter' in which there is only r/o
39  * access to the data.
40  */
41 
42 /* An opaque collection of change lists (apr_array_header_t * of
43  * svn_fs_x__change_t *).
44  */
45 typedef struct svn_fs_x__changes_t svn_fs_x__changes_t;
46 
47 /* Create and populate changes containers. */
48 
49 /* Create and return a new changes container with an initial capacity of
50  * INITIAL_COUNT svn_fs_x__change_t objects.
51  * Allocate the result in RESULT_POOL.
52  */
53 svn_fs_x__changes_t *
54 svn_fs_x__changes_create(apr_size_t initial_count,
55                          apr_pool_t *result_pool);
56 
57 /* Start a new change list CHANGES (implicitly terminating the previous one)
58  * and return its index in *LIST_INDEX.  Append all changes from LIST to
59  * that new change list.
60  */
61 svn_error_t *
62 svn_fs_x__changes_append_list(apr_size_t *list_index,
63                               svn_fs_x__changes_t *changes,
64                               apr_array_header_t *list);
65 
66 /* Return a rough estimate in bytes for the serialized representation
67  * of CHANGES.
68  */
69 apr_size_t
70 svn_fs_x__changes_estimate_size(const svn_fs_x__changes_t *changes);
71 
72 /* Read changes containers. */
73 
74 /* From CHANGES, access the change list with the given IDX and extract the
75  * next entries according to CONTEXT.  Allocate the result in RESULT_POOL
76  * and return it in *LIST.
77  */
78 svn_error_t *
79 svn_fs_x__changes_get_list(apr_array_header_t **list,
80                            const svn_fs_x__changes_t *changes,
81                            apr_size_t idx,
82                            svn_fs_x__changes_context_t *context,
83                            apr_pool_t *result_pool);
84 
85 /* I/O interface. */
86 
87 /* Write a serialized representation of CHANGES to STREAM.
88  * Use SCRATCH_POOL for temporary allocations.
89  */
90 svn_error_t *
91 svn_fs_x__write_changes_container(svn_stream_t *stream,
92                                   const svn_fs_x__changes_t *changes,
93                                   apr_pool_t *scratch_pool);
94 
95 /* Read a changes container from its serialized representation in STREAM.
96  * Allocate the result in RESULT_POOL and return it in *CHANGES_P.  Use
97  * SCRATCH_POOL for temporary allocations.
98  */
99 svn_error_t *
100 svn_fs_x__read_changes_container(svn_fs_x__changes_t **changes_p,
101                                  svn_stream_t *stream,
102                                  apr_pool_t *result_pool,
103                                  apr_pool_t *scratch_pool);
104 
105 /* Implements #svn_cache__serialize_func_t for svn_fs_x__changes_t objects.
106  */
107 svn_error_t *
108 svn_fs_x__serialize_changes_container(void **data,
109                                       apr_size_t *data_len,
110                                       void *in,
111                                       apr_pool_t *pool);
112 
113 /* Implements #svn_cache__deserialize_func_t for svn_fs_x__changes_t objects.
114  */
115 svn_error_t *
116 svn_fs_x__deserialize_changes_container(void **out,
117                                         void *data,
118                                         apr_size_t data_len,
119                                         apr_pool_t *result_pool);
120 
121 /* Baton type to be used with svn_fs_x__changes_get_list_func. */
122 typedef struct svn_fs_x__changes_get_list_baton_t
123 {
124   /* Sub-item to query */
125   apr_uint32_t sub_item;
126 
127   /* Deliver data starting from this index within the changes list. */
128   int start;
129 
130   /* To be set by svn_fs_x__changes_get_list_func:
131      Did we deliver the last change in that list? */
132   svn_boolean_t *eol;
133 } svn_fs_x__changes_get_list_baton_t;
134 
135 /* Implements svn_cache__partial_getter_func_t for svn_fs_x__changes_t,
136  * setting *OUT to the change list (apr_array_header_t *) selected by
137  * the svn_fs_x__changes_get_list_baton_t passed in as *BATON.  This
138  * function is similar to svn_fs_x__changes_get_list but operates on
139  * the cache serialized representation of the container.
140  */
141 svn_error_t *
142 svn_fs_x__changes_get_list_func(void **out,
143                                 const void *data,
144                                 apr_size_t data_len,
145                                 void *baton,
146                                 apr_pool_t *pool);
147 
148 #endif
149