1 /* noderevs.h --- FSX node revision container
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
20 * ====================================================================
23 #include "svn_private_config.h"
25 #include "private/svn_dep_compat.h"
26 #include "private/svn_packed_data.h"
27 #include "private/svn_subr_private.h"
28 #include "private/svn_temp_serializer.h"
31 #include "string_table.h"
32 #include "temp_serializer.h"
34 /* These flags will be used with the FLAGS field in binary_noderev_t.
37 /* (flags & NODEREV_KIND_MASK) extracts the noderev type */
38 #define NODEREV_KIND_MASK 0x00007
40 /* the noderev has merge info */
41 #define NODEREV_HAS_MINFO 0x00008
43 /* the noderev has copy-from-path and revision */
44 #define NODEREV_HAS_COPYFROM 0x00010
46 /* the noderev has copy-root path and revision */
47 #define NODEREV_HAS_COPYROOT 0x00020
49 /* the noderev has copy-root path and revision */
50 #define NODEREV_HAS_CPATH 0x00040
52 /* Our internal representation of a svn_fs_x__noderev_t.
54 * We will store path strings in a string container and reference them
55 * from here. Similarly, IDs and representations are being stored in
56 * separate containers and then also referenced here. This eliminates
57 * the need to store the same IDs and representations more than once.
59 typedef struct binary_noderev_t
61 /* node type and presence indicators */
64 /* Index+1 of the noderev-id for this node-rev. */
67 /* Index+1 of the node-id for this node-rev. */
70 /* Index+1 of the copy-id for this node-rev. */
73 /* Index+1 of the predecessor node revision id, or 0 if there is no
74 predecessor for this node revision */
77 /* number of predecessors this node revision has (recursively), or
78 -1 if not known (for backward compatibility). */
79 int predecessor_count;
81 /* If this node-rev is a copy, what revision was it copied from? */
82 svn_revnum_t copyfrom_rev;
84 /* Helper for history tracing, root revision of the parent tree from
85 whence this node-rev was copied. */
86 svn_revnum_t copyroot_rev;
88 /* If this node-rev is a copy, this is the string index+1 of the path
89 from which that copy way made. 0, otherwise. */
90 apr_size_t copyfrom_path;
92 /* String index+1 of the root of the parent tree from whence this node-
94 apr_size_t copyroot_path;
96 /* Index+1 of the representation key for this node's properties.
97 May be 0 if there are no properties. */
100 /* Index+1 of the representation for this node's data.
101 May be 0 if there is no data. */
104 /* String index+1 of the path at which this node first came into
106 apr_size_t created_path;
108 /* Number of nodes with svn:mergeinfo properties that are
109 descendants of this node (including it itself) */
110 apr_int64_t mergeinfo_count;
114 /* The actual container object. Node revisions are concatenated into
115 * NODEREVS, referenced representations are stored in DATA_REPS / PROP_REPS
116 * and the ids in IDs. PATHS is the string table for all paths.
118 * During construction, BUILDER will be used instead of PATHS. IDS_DICT,
119 * DATA_REPS_DICT and PROP_REPS_DICT are also only used during construction
120 * and are NULL otherwise.
122 struct svn_fs_x__noderevs_t
124 /* The paths - either in 'builder' mode or finalized mode.
125 * The respective other pointer will be NULL. */
126 string_table_builder_t *builder;
127 string_table_t *paths;
129 /* During construction, maps a full binary_id_t to an index into IDS */
130 apr_hash_t *ids_dict;
132 /* During construction, maps a full binary_representation_t to an index
134 apr_hash_t *reps_dict;
136 /* array of binary_id_t */
137 apr_array_header_t *ids;
139 /* array of binary_representation_t */
140 apr_array_header_t *reps;
142 /* array of binary_noderev_t. */
143 apr_array_header_t *noderevs;
146 svn_fs_x__noderevs_t *
147 svn_fs_x__noderevs_create(int initial_count,
148 apr_pool_t* result_pool)
150 svn_fs_x__noderevs_t *noderevs
151 = apr_palloc(result_pool, sizeof(*noderevs));
153 noderevs->builder = svn_fs_x__string_table_builder_create(result_pool);
154 noderevs->ids_dict = svn_hash__make(result_pool);
155 noderevs->reps_dict = svn_hash__make(result_pool);
156 noderevs->paths = NULL;
159 = apr_array_make(result_pool, 2 * initial_count, sizeof(svn_fs_x__id_t));
161 = apr_array_make(result_pool, 2 * initial_count,
162 sizeof(svn_fs_x__representation_t));
164 = apr_array_make(result_pool, initial_count, sizeof(binary_noderev_t));
169 /* Given the ID, return the index+1 into IDS that contains a binary_id
170 * for it. Returns 0 for NULL IDs. We use DICT to detect duplicates.
173 store_id(apr_array_header_t *ids,
175 const svn_fs_x__id_t *id)
180 if (!svn_fs_x__id_used(id))
183 idx_void = apr_hash_get(dict, &id, sizeof(id));
184 idx = (int)(apr_uintptr_t)idx_void;
187 APR_ARRAY_PUSH(ids, svn_fs_x__id_t) = *id;
189 apr_hash_set(dict, ids->elts + (idx-1) * ids->elt_size,
190 ids->elt_size, (void*)(apr_uintptr_t)idx);
196 /* Given the REP, return the index+1 into REPS that contains a copy of it.
197 * Returns 0 for NULL IDs. We use DICT to detect duplicates.
200 store_representation(apr_array_header_t *reps,
202 const svn_fs_x__representation_t *rep)
210 idx_void = apr_hash_get(dict, rep, sizeof(*rep));
211 idx = (int)(apr_uintptr_t)idx_void;
214 APR_ARRAY_PUSH(reps, svn_fs_x__representation_t) = *rep;
216 apr_hash_set(dict, reps->elts + (idx-1) * reps->elt_size,
217 reps->elt_size, (void*)(apr_uintptr_t)idx);
224 svn_fs_x__noderevs_add(svn_fs_x__noderevs_t *container,
225 svn_fs_x__noderev_t *noderev)
227 binary_noderev_t binary_noderev = { 0 };
229 binary_noderev.flags = (noderev->has_mergeinfo ? NODEREV_HAS_MINFO : 0)
230 | (noderev->copyfrom_path ? NODEREV_HAS_COPYFROM : 0)
231 | (noderev->copyroot_path ? NODEREV_HAS_COPYROOT : 0)
232 | (noderev->created_path ? NODEREV_HAS_CPATH : 0)
233 | (int)noderev->kind;
236 = store_id(container->ids, container->ids_dict, &noderev->noderev_id);
237 binary_noderev.node_id
238 = store_id(container->ids, container->ids_dict, &noderev->node_id);
239 binary_noderev.copy_id
240 = store_id(container->ids, container->ids_dict, &noderev->copy_id);
241 binary_noderev.predecessor_id
242 = store_id(container->ids, container->ids_dict, &noderev->predecessor_id);
244 if (noderev->copyfrom_path)
246 binary_noderev.copyfrom_path
247 = svn_fs_x__string_table_builder_add(container->builder,
248 noderev->copyfrom_path,
250 binary_noderev.copyfrom_rev = noderev->copyfrom_rev;
253 if (noderev->copyroot_path)
255 binary_noderev.copyroot_path
256 = svn_fs_x__string_table_builder_add(container->builder,
257 noderev->copyroot_path,
259 binary_noderev.copyroot_rev = noderev->copyroot_rev;
262 binary_noderev.predecessor_count = noderev->predecessor_count;
263 binary_noderev.prop_rep = store_representation(container->reps,
264 container->reps_dict,
266 binary_noderev.data_rep = store_representation(container->reps,
267 container->reps_dict,
270 if (noderev->created_path)
271 binary_noderev.created_path
272 = svn_fs_x__string_table_builder_add(container->builder,
273 noderev->created_path,
276 binary_noderev.mergeinfo_count = noderev->mergeinfo_count;
278 APR_ARRAY_PUSH(container->noderevs, binary_noderev_t) = binary_noderev;
280 return container->noderevs->nelts - 1;
284 svn_fs_x__noderevs_estimate_size(const svn_fs_x__noderevs_t *container)
286 /* CONTAINER must be in 'builder' mode */
287 if (container->builder == NULL)
290 /* string table code makes its own prediction,
291 * noderevs should be < 16 bytes each,
292 * id parts < 4 bytes each,
293 * data representations < 40 bytes each,
294 * property representations < 30 bytes each,
295 * some static overhead should be assumed */
296 return svn_fs_x__string_table_builder_estimate_size(container->builder)
297 + container->noderevs->nelts * 16
298 + container->ids->nelts * 4
299 + container->reps->nelts * 40
303 /* Set *ID to the ID part stored at index IDX in IDS.
306 get_id(svn_fs_x__id_t *id,
307 const apr_array_header_t *ids,
310 /* handle NULL IDs */
313 svn_fs_x__id_reset(id);
317 /* check for corrupted data */
318 if (idx < 0 || idx > ids->nelts)
319 return svn_error_createf(SVN_ERR_FS_CONTAINER_INDEX, NULL,
320 _("ID part index %d exceeds container size %d"),
323 /* Return the requested ID. */
324 *id = APR_ARRAY_IDX(ids, idx - 1, svn_fs_x__id_t);
329 /* Create a svn_fs_x__representation_t in *REP, allocated in POOL based on the
330 * representation stored at index IDX in REPS.
333 get_representation(svn_fs_x__representation_t **rep,
334 const apr_array_header_t *reps,
338 /* handle NULL representations */
345 /* check for corrupted data */
346 if (idx < 0 || idx > reps->nelts)
347 return svn_error_createf(SVN_ERR_FS_CONTAINER_INDEX, NULL,
348 _("Node revision ID index %d"
349 " exceeds container size %d"),
352 /* no translation required. Just duplicate the info */
353 *rep = apr_pmemdup(pool,
354 &APR_ARRAY_IDX(reps, idx - 1, svn_fs_x__representation_t),
361 svn_fs_x__noderevs_get(svn_fs_x__noderev_t **noderev_p,
362 const svn_fs_x__noderevs_t *container,
364 apr_pool_t *result_pool)
366 svn_fs_x__noderev_t *noderev;
367 binary_noderev_t *binary_noderev;
369 /* CONTAINER must be in 'finalized' mode */
370 SVN_ERR_ASSERT(container->builder == NULL);
371 SVN_ERR_ASSERT(container->paths);
374 if (idx >= (apr_size_t)container->noderevs->nelts)
375 return svn_error_createf(SVN_ERR_FS_CONTAINER_INDEX, NULL,
376 apr_psprintf(result_pool,
377 _("Node revision index %%%s"
378 " exceeds container size %%d"),
380 idx, container->noderevs->nelts);
382 /* allocate result struct and fill it field by field */
383 noderev = apr_pcalloc(result_pool, sizeof(*noderev));
384 binary_noderev = &APR_ARRAY_IDX(container->noderevs, idx, binary_noderev_t);
386 noderev->kind = (svn_node_kind_t)(binary_noderev->flags & NODEREV_KIND_MASK);
387 SVN_ERR(get_id(&noderev->noderev_id, container->ids, binary_noderev->id));
388 SVN_ERR(get_id(&noderev->node_id, container->ids,
389 binary_noderev->node_id));
390 SVN_ERR(get_id(&noderev->copy_id, container->ids,
391 binary_noderev->copy_id));
392 SVN_ERR(get_id(&noderev->predecessor_id, container->ids,
393 binary_noderev->predecessor_id));
395 if (binary_noderev->flags & NODEREV_HAS_COPYFROM)
397 noderev->copyfrom_path
398 = svn_fs_x__string_table_get(container->paths,
399 binary_noderev->copyfrom_path,
402 noderev->copyfrom_rev = binary_noderev->copyfrom_rev;
406 noderev->copyfrom_path = NULL;
407 noderev->copyfrom_rev = SVN_INVALID_REVNUM;
410 if (binary_noderev->flags & NODEREV_HAS_COPYROOT)
412 noderev->copyroot_path
413 = svn_fs_x__string_table_get(container->paths,
414 binary_noderev->copyroot_path,
417 noderev->copyroot_rev = binary_noderev->copyroot_rev;
421 noderev->copyroot_path = NULL;
422 noderev->copyroot_rev = 0;
425 noderev->predecessor_count = binary_noderev->predecessor_count;
427 SVN_ERR(get_representation(&noderev->prop_rep, container->reps,
428 binary_noderev->prop_rep, result_pool));
429 SVN_ERR(get_representation(&noderev->data_rep, container->reps,
430 binary_noderev->data_rep, result_pool));
432 if (binary_noderev->flags & NODEREV_HAS_CPATH)
433 noderev->created_path
434 = svn_fs_x__string_table_get(container->paths,
435 binary_noderev->created_path,
439 noderev->mergeinfo_count = binary_noderev->mergeinfo_count;
441 noderev->has_mergeinfo = (binary_noderev->flags & NODEREV_HAS_MINFO) ? 1 : 0;
442 *noderev_p = noderev;
447 /* Create and return a stream for representations in PARENT.
448 * Initialize the sub-streams for all fields, except checksums.
450 static svn_packed__int_stream_t *
451 create_rep_stream(svn_packed__int_stream_t *parent)
453 svn_packed__int_stream_t *stream
454 = svn_packed__create_int_substream(parent, FALSE, FALSE);
456 /* sub-streams for members - except for checksums */
458 svn_packed__create_int_substream(stream, FALSE, FALSE);
460 /* rev, item_index, size, expanded_size */
461 svn_packed__create_int_substream(stream, TRUE, FALSE);
462 svn_packed__create_int_substream(stream, FALSE, FALSE);
463 svn_packed__create_int_substream(stream, FALSE, FALSE);
464 svn_packed__create_int_substream(stream, FALSE, FALSE);
469 /* Serialize all representations in REP. Store checksums in DIGEST_STREAM,
470 * put all other fields into REP_STREAM.
473 write_reps(svn_packed__int_stream_t *rep_stream,
474 svn_packed__byte_stream_t *digest_stream,
475 apr_array_header_t *reps)
478 for (i = 0; i < reps->nelts; ++i)
480 svn_fs_x__representation_t *rep
481 = &APR_ARRAY_IDX(reps, i, svn_fs_x__representation_t);
483 svn_packed__add_uint(rep_stream, rep->has_sha1);
485 svn_packed__add_uint(rep_stream, rep->id.change_set);
486 svn_packed__add_uint(rep_stream, rep->id.number);
487 svn_packed__add_uint(rep_stream, rep->size);
488 svn_packed__add_uint(rep_stream, rep->expanded_size);
490 svn_packed__add_bytes(digest_stream,
491 (const char *)rep->md5_digest,
492 sizeof(rep->md5_digest));
494 svn_packed__add_bytes(digest_stream,
495 (const char *)rep->sha1_digest,
496 sizeof(rep->sha1_digest));
501 svn_fs_x__write_noderevs_container(svn_stream_t *stream,
502 const svn_fs_x__noderevs_t *container,
503 apr_pool_t *scratch_pool)
507 string_table_t *paths = container->paths
509 : svn_fs_x__string_table_create(container->builder,
512 svn_packed__data_root_t *root = svn_packed__data_create_root(scratch_pool);
514 /* one common top-level stream for all arrays. One sub-stream */
515 svn_packed__int_stream_t *structs_stream
516 = svn_packed__create_int_stream(root, FALSE, FALSE);
517 svn_packed__int_stream_t *ids_stream
518 = svn_packed__create_int_substream(structs_stream, FALSE, FALSE);
519 svn_packed__int_stream_t *reps_stream
520 = create_rep_stream(structs_stream);
521 svn_packed__int_stream_t *noderevs_stream
522 = svn_packed__create_int_substream(structs_stream, FALSE, FALSE);
523 svn_packed__byte_stream_t *digests_stream
524 = svn_packed__create_bytes_stream(root);
526 /* structure the IDS_STREAM such we can extract much of the redundancy
527 * from the svn_fs_x__ip_part_t structs */
528 for (i = 0; i < 2; ++i)
529 svn_packed__create_int_substream(ids_stream, TRUE, FALSE);
531 /* Same storing binary_noderev_t in the NODEREVS_STREAM */
532 svn_packed__create_int_substream(noderevs_stream, FALSE, FALSE);
533 for (i = 0; i < 13; ++i)
534 svn_packed__create_int_substream(noderevs_stream, TRUE, FALSE);
536 /* serialize ids array */
537 for (i = 0; i < container->ids->nelts; ++i)
539 svn_fs_x__id_t *id = &APR_ARRAY_IDX(container->ids, i, svn_fs_x__id_t);
541 svn_packed__add_int(ids_stream, id->change_set);
542 svn_packed__add_uint(ids_stream, id->number);
545 /* serialize rep arrays */
546 write_reps(reps_stream, digests_stream, container->reps);
548 /* serialize noderevs array */
549 for (i = 0; i < container->noderevs->nelts; ++i)
551 const binary_noderev_t *noderev
552 = &APR_ARRAY_IDX(container->noderevs, i, binary_noderev_t);
554 svn_packed__add_uint(noderevs_stream, noderev->flags);
556 svn_packed__add_uint(noderevs_stream, noderev->id);
557 svn_packed__add_uint(noderevs_stream, noderev->node_id);
558 svn_packed__add_uint(noderevs_stream, noderev->copy_id);
559 svn_packed__add_uint(noderevs_stream, noderev->predecessor_id);
560 svn_packed__add_uint(noderevs_stream, noderev->predecessor_count);
562 svn_packed__add_uint(noderevs_stream, noderev->copyfrom_path);
563 svn_packed__add_int(noderevs_stream, noderev->copyfrom_rev);
564 svn_packed__add_uint(noderevs_stream, noderev->copyroot_path);
565 svn_packed__add_int(noderevs_stream, noderev->copyroot_rev);
567 svn_packed__add_uint(noderevs_stream, noderev->prop_rep);
568 svn_packed__add_uint(noderevs_stream, noderev->data_rep);
570 svn_packed__add_uint(noderevs_stream, noderev->created_path);
571 svn_packed__add_uint(noderevs_stream, noderev->mergeinfo_count);
575 SVN_ERR(svn_fs_x__write_string_table(stream, paths, scratch_pool));
576 SVN_ERR(svn_packed__data_write(stream, root, scratch_pool));
581 /* Allocate a svn_fs_x__representation_t array in RESULT_POOL and return it
582 * in REPS_P. Deserialize the data in REP_STREAM and DIGEST_STREAM and store
583 * the resulting representations into the *REPS_P.
586 read_reps(apr_array_header_t **reps_p,
587 svn_packed__int_stream_t *rep_stream,
588 svn_packed__byte_stream_t *digest_stream,
589 apr_pool_t *result_pool)
596 = svn_packed__int_count(svn_packed__first_int_substream(rep_stream));
597 apr_array_header_t *reps
598 = apr_array_make(result_pool, (int)count,
599 sizeof(svn_fs_x__representation_t));
601 for (i = 0; i < count; ++i)
603 svn_fs_x__representation_t rep;
605 rep.has_sha1 = (svn_boolean_t)svn_packed__get_uint(rep_stream);
607 rep.id.change_set = (svn_revnum_t)svn_packed__get_uint(rep_stream);
608 rep.id.number = svn_packed__get_uint(rep_stream);
609 rep.size = svn_packed__get_uint(rep_stream);
610 rep.expanded_size = svn_packed__get_uint(rep_stream);
612 /* when extracting the checksums, beware of buffer under/overflows
613 caused by disk data corruption. */
614 bytes = svn_packed__get_bytes(digest_stream, &len);
615 if (len != sizeof(rep.md5_digest))
616 return svn_error_createf(SVN_ERR_FS_CONTAINER_INDEX, NULL,
617 apr_psprintf(result_pool,
619 " digest size %%%s"),
623 memcpy(rep.md5_digest, bytes, sizeof(rep.md5_digest));
626 bytes = svn_packed__get_bytes(digest_stream, &len);
627 if (len != sizeof(rep.sha1_digest))
628 return svn_error_createf(SVN_ERR_FS_CONTAINER_INDEX, NULL,
629 apr_psprintf(result_pool,
631 " digest size %%%s"),
635 memcpy(rep.sha1_digest, bytes, sizeof(rep.sha1_digest));
638 APR_ARRAY_PUSH(reps, svn_fs_x__representation_t) = rep;
647 svn_fs_x__read_noderevs_container(svn_fs_x__noderevs_t **container,
648 svn_stream_t *stream,
649 apr_pool_t *result_pool,
650 apr_pool_t *scratch_pool)
655 svn_fs_x__noderevs_t *noderevs
656 = apr_pcalloc(result_pool, sizeof(*noderevs));
658 svn_packed__data_root_t *root;
659 svn_packed__int_stream_t *structs_stream;
660 svn_packed__int_stream_t *ids_stream;
661 svn_packed__int_stream_t *reps_stream;
662 svn_packed__int_stream_t *noderevs_stream;
663 svn_packed__byte_stream_t *digests_stream;
665 /* read everything from disk */
666 SVN_ERR(svn_fs_x__read_string_table(&noderevs->paths, stream,
667 result_pool, scratch_pool));
668 SVN_ERR(svn_packed__data_read(&root, stream, result_pool, scratch_pool));
671 structs_stream = svn_packed__first_int_stream(root);
672 ids_stream = svn_packed__first_int_substream(structs_stream);
673 reps_stream = svn_packed__next_int_stream(ids_stream);
674 noderevs_stream = svn_packed__next_int_stream(reps_stream);
675 digests_stream = svn_packed__first_byte_stream(root);
679 = svn_packed__int_count(svn_packed__first_int_substream(ids_stream));
681 = apr_array_make(result_pool, (int)count, sizeof(svn_fs_x__id_t));
682 for (i = 0; i < count; ++i)
686 id.change_set = (svn_revnum_t)svn_packed__get_int(ids_stream);
687 id.number = svn_packed__get_uint(ids_stream);
689 APR_ARRAY_PUSH(noderevs->ids, svn_fs_x__id_t) = id;
692 /* read rep arrays */
693 SVN_ERR(read_reps(&noderevs->reps, reps_stream, digests_stream,
696 /* read noderevs array */
698 = svn_packed__int_count(svn_packed__first_int_substream(noderevs_stream));
700 = apr_array_make(result_pool, (int)count, sizeof(binary_noderev_t));
701 for (i = 0; i < count; ++i)
703 binary_noderev_t noderev;
705 noderev.flags = (apr_uint32_t)svn_packed__get_uint(noderevs_stream);
707 noderev.id = (int)svn_packed__get_uint(noderevs_stream);
708 noderev.node_id = (int)svn_packed__get_uint(noderevs_stream);
709 noderev.copy_id = (int)svn_packed__get_uint(noderevs_stream);
710 noderev.predecessor_id = (int)svn_packed__get_uint(noderevs_stream);
711 noderev.predecessor_count = (int)svn_packed__get_uint(noderevs_stream);
713 noderev.copyfrom_path = (apr_size_t)svn_packed__get_uint(noderevs_stream);
714 noderev.copyfrom_rev = (svn_revnum_t)svn_packed__get_int(noderevs_stream);
715 noderev.copyroot_path = (apr_size_t)svn_packed__get_uint(noderevs_stream);
716 noderev.copyroot_rev = (svn_revnum_t)svn_packed__get_int(noderevs_stream);
718 noderev.prop_rep = (int)svn_packed__get_uint(noderevs_stream);
719 noderev.data_rep = (int)svn_packed__get_uint(noderevs_stream);
721 noderev.created_path = (apr_size_t)svn_packed__get_uint(noderevs_stream);
722 noderev.mergeinfo_count = svn_packed__get_uint(noderevs_stream);
724 APR_ARRAY_PUSH(noderevs->noderevs, binary_noderev_t) = noderev;
727 *container = noderevs;
733 svn_fs_x__serialize_noderevs_container(void **data,
734 apr_size_t *data_len,
738 svn_fs_x__noderevs_t *noderevs = in;
739 svn_stringbuf_t *serialized;
741 = noderevs->ids->elt_size * noderevs->ids->nelts
742 + noderevs->reps->elt_size * noderevs->reps->nelts
743 + noderevs->noderevs->elt_size * noderevs->noderevs->nelts
744 + 10 * noderevs->noderevs->elt_size
747 /* serialize array header and all its elements */
748 svn_temp_serializer__context_t *context
749 = svn_temp_serializer__init(noderevs, sizeof(*noderevs), size, pool);
751 /* serialize sub-structures */
752 svn_fs_x__serialize_string_table(context, &noderevs->paths);
753 svn_fs_x__serialize_apr_array(context, &noderevs->ids);
754 svn_fs_x__serialize_apr_array(context, &noderevs->reps);
755 svn_fs_x__serialize_apr_array(context, &noderevs->noderevs);
757 /* return the serialized result */
758 serialized = svn_temp_serializer__get(context);
760 *data = serialized->data;
761 *data_len = serialized->len;
767 svn_fs_x__deserialize_noderevs_container(void **out,
770 apr_pool_t *result_pool)
772 svn_fs_x__noderevs_t *noderevs = (svn_fs_x__noderevs_t *)data;
774 /* de-serialize sub-structures */
775 svn_fs_x__deserialize_string_table(noderevs, &noderevs->paths);
776 svn_fs_x__deserialize_apr_array(noderevs, &noderevs->ids, result_pool);
777 svn_fs_x__deserialize_apr_array(noderevs, &noderevs->reps, result_pool);
778 svn_fs_x__deserialize_apr_array(noderevs, &noderevs->noderevs, result_pool);
786 /* Deserialize the cache serialized APR struct at *IN in BUFFER and write
787 * the result to OUT. Note that this will only resolve the pointers and
788 * not the array elements themselves. */
790 resolve_apr_array_header(apr_array_header_t *out,
792 apr_array_header_t * const *in)
794 const apr_array_header_t *array
795 = svn_temp_deserializer__ptr(buffer, (const void *const *)in);
797 = svn_temp_deserializer__ptr(array, (const void *const *)&array->elts);
800 out->elts = (char *)elements;
805 svn_fs_x__noderevs_get_func(void **out,
811 svn_fs_x__noderev_t *noderev;
812 binary_noderev_t *binary_noderev;
814 apr_array_header_t ids;
815 apr_array_header_t reps;
816 apr_array_header_t noderevs;
818 apr_uint32_t idx = *(apr_uint32_t *)baton;
819 const svn_fs_x__noderevs_t *container = data;
821 /* Resolve all container pointers */
822 const string_table_t *paths
823 = svn_temp_deserializer__ptr(container,
824 (const void *const *)&container->paths);
826 resolve_apr_array_header(&ids, container, &container->ids);
827 resolve_apr_array_header(&reps, container, &container->reps);
828 resolve_apr_array_header(&noderevs, container, &container->noderevs);
830 /* allocate result struct and fill it field by field */
831 noderev = apr_pcalloc(pool, sizeof(*noderev));
832 binary_noderev = &APR_ARRAY_IDX(&noderevs, idx, binary_noderev_t);
834 noderev->kind = (svn_node_kind_t)(binary_noderev->flags & NODEREV_KIND_MASK);
835 SVN_ERR(get_id(&noderev->noderev_id, &ids, binary_noderev->id));
836 SVN_ERR(get_id(&noderev->node_id, &ids, binary_noderev->node_id));
837 SVN_ERR(get_id(&noderev->copy_id, &ids, binary_noderev->copy_id));
838 SVN_ERR(get_id(&noderev->predecessor_id, &ids,
839 binary_noderev->predecessor_id));
841 if (binary_noderev->flags & NODEREV_HAS_COPYFROM)
843 noderev->copyfrom_path
844 = svn_fs_x__string_table_get_func(paths,
845 binary_noderev->copyfrom_path,
848 noderev->copyfrom_rev = binary_noderev->copyfrom_rev;
852 noderev->copyfrom_path = NULL;
853 noderev->copyfrom_rev = SVN_INVALID_REVNUM;
856 if (binary_noderev->flags & NODEREV_HAS_COPYROOT)
858 noderev->copyroot_path
859 = svn_fs_x__string_table_get_func(paths,
860 binary_noderev->copyroot_path,
863 noderev->copyroot_rev = binary_noderev->copyroot_rev;
867 noderev->copyroot_path = NULL;
868 noderev->copyroot_rev = 0;
871 noderev->predecessor_count = binary_noderev->predecessor_count;
873 SVN_ERR(get_representation(&noderev->prop_rep, &reps,
874 binary_noderev->prop_rep, pool));
875 SVN_ERR(get_representation(&noderev->data_rep, &reps,
876 binary_noderev->data_rep, pool));
878 if (binary_noderev->flags & NODEREV_HAS_CPATH)
879 noderev->created_path
880 = svn_fs_x__string_table_get_func(paths,
881 binary_noderev->created_path,
885 noderev->mergeinfo_count = binary_noderev->mergeinfo_count;
887 noderev->has_mergeinfo = (binary_noderev->flags & NODEREV_HAS_MINFO) ? 1 : 0;
894 svn_fs_x__mergeinfo_count_get_func(void **out,
900 binary_noderev_t *binary_noderev;
901 apr_array_header_t noderevs;
903 apr_uint32_t idx = *(apr_uint32_t *)baton;
904 const svn_fs_x__noderevs_t *container = data;
906 /* Resolve all container pointers */
907 resolve_apr_array_header(&noderevs, container, &container->noderevs);
908 binary_noderev = &APR_ARRAY_IDX(&noderevs, idx, binary_noderev_t);
910 *(apr_int64_t *)out = binary_noderev->mergeinfo_count;