This repository has been archived by the owner on Jul 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
export.c
632 lines (524 loc) · 21.7 KB
/
export.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
/* Copyright (C) 2014-2015 by Maxim Bublis <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "export.h"
#include "node.h"
#include "sorts.h"
#include "tree.h"
#include "utils.h"
#include <apr_portable.h>
#include <svn_dirent_uri.h>
#include <svn_hash.h>
#include <svn_pools.h>
#include <svn_props.h>
#include <svn_sorts.h>
#include <svn_time.h>
#define NULL_SHA1 "0000000000000000000000000000000000000000"
typedef struct
{
svn_fs_root_t *root;
svn_revnum_t revnum;
apr_time_t timestamp;
const author_t *author;
svn_string_t *message;
apr_hash_t *commits;
apr_hash_t *removes;
apr_hash_t *changes;
} revision_t;
typedef struct
{
svn_fs_path_change_kind_t action;
node_t *node;
} change_t;
static svn_error_t *
get_revision(revision_t **rev,
svn_revnum_t revnum,
svn_fs_t *fs,
export_ctx_t *ctx,
apr_pool_t *pool)
{
apr_hash_t *revprops;
revision_t *r;
svn_fs_root_t *root;
svn_string_t *value;
SVN_ERR(svn_fs_revision_root(&root, fs, revnum, pool));
SVN_ERR(svn_fs_revision_proplist(&revprops, fs, revnum, pool));
r = apr_pcalloc(pool, sizeof(revision_t));
r->root = root;
r->revnum = revnum;
r->message = svn_string_create_empty(pool);
r->commits = apr_hash_make(pool);
r->removes = apr_hash_make(pool);
r->changes = apr_hash_make(pool);
value = svn_hash_gets(revprops, SVN_PROP_REVISION_AUTHOR);
if (value != NULL) {
r->author = author_storage_lookup(ctx->authors, value->data);
} else {
r->author = author_storage_default_author(ctx->authors);
}
value = svn_hash_gets(revprops, SVN_PROP_REVISION_DATE);
if (value != NULL) {
SVN_ERR(svn_time_from_cstring(&r->timestamp, value->data, pool));
}
value = svn_hash_gets(revprops, SVN_PROP_REVISION_LOG);
if (value != NULL) {
r->message = value;
}
*rev = r;
return SVN_NO_ERROR;
}
static apr_array_header_t *
get_branch_changes(revision_t *rev, branch_t *branch)
{
apr_array_header_t *changes;
changes = apr_hash_get(rev->changes, branch, sizeof(branch_t *));
if (changes == NULL) {
apr_pool_t *pool = apr_hash_pool_get(rev->changes);
changes = apr_array_make(pool, 0, sizeof(change_t));
apr_hash_set(rev->changes, branch, sizeof(branch_t *), changes);
}
return changes;
}
static svn_error_t *
get_mergeinfo_for_path(svn_mergeinfo_t *mergeinfo,
svn_fs_root_t *root,
const char *path,
apr_pool_t *result_pool,
apr_pool_t *scratch_pool)
{
apr_array_header_t *paths;
svn_mergeinfo_catalog_t catalog;
paths = apr_array_make(scratch_pool, 1, sizeof(const char *));
APR_ARRAY_PUSH(paths, const char *) = path;
SVN_ERR(svn_fs_get_mergeinfo2(&catalog, root, paths,
svn_mergeinfo_inherited, FALSE, TRUE,
result_pool, scratch_pool));
*mergeinfo = svn_hash_gets(catalog, path);
return SVN_NO_ERROR;
}
static svn_error_t *
process_change_record(const char *path,
svn_fs_path_change2_t *change,
svn_stream_t *dst,
revision_t *rev,
export_ctx_t *ctx,
apr_pool_t *result_pool,
apr_pool_t *scratch_pool)
{
const char *src_path = NULL, *node_path;
const char *ignored, *not_ignored;
commit_t *commit, *parent;
branch_t *branch = NULL, *src_branch = NULL, *merge_branch;
node_t *node;
svn_boolean_t dst_is_root = FALSE, src_is_root = FALSE;
svn_boolean_t modify;
svn_fs_path_change_kind_t action = change->change_kind;
svn_mergeinfo_t mergeinfo = NULL;
svn_node_kind_t kind = change->node_kind;
svn_revnum_t src_rev = change->copyfrom_rev;
ignored = tree_match(ctx->absignores, path, scratch_pool);
if (ignored != NULL) {
return SVN_NO_ERROR;
}
modify = (action == svn_fs_path_change_replace ||
action == svn_fs_path_change_add ||
action == svn_fs_path_change_modify);
if (change->copyfrom_known && SVN_IS_VALID_REVNUM(src_rev)) {
src_path = change->copyfrom_path;
src_branch = branch_storage_lookup_path(ctx->branches, src_path, scratch_pool);
}
branch = branch_storage_lookup_path(ctx->branches, path, scratch_pool);
if (branch == NULL) {
return SVN_NO_ERROR;
}
dst_is_root = branch_path_is_root(branch, path);
src_is_root = (src_branch != NULL && branch_path_is_root(src_branch, src_path));
if (kind == svn_node_dir && src_branch == NULL) {
if (action == svn_fs_path_change_add || action == svn_fs_path_change_modify) {
return SVN_NO_ERROR;
}
}
if (action == svn_fs_path_change_delete && dst_is_root) {
apr_hash_set(rev->removes, branch, sizeof(branch_t *), branch);
return SVN_NO_ERROR;
}
node_path = svn_relpath_skip_ancestor(branch->path, path);
if (node_path == NULL) {
return SVN_NO_ERROR;
}
ignored = tree_match(ctx->ignores, node_path, scratch_pool);
not_ignored = tree_match(ctx->no_ignores, path, scratch_pool);
if (ignored != NULL && not_ignored == NULL) {
return SVN_NO_ERROR;
}
commit = apr_hash_get(rev->commits, branch, sizeof(branch_t *));
if (commit == NULL) {
parent = commit_cache_get(ctx->commits, rev->revnum - 1, branch);
commit = commit_cache_add(ctx->commits, rev->revnum, branch);
if (parent != NULL && branch->dirty == FALSE) {
commit->parent = parent->mark;
}
apr_hash_set(rev->commits, branch, sizeof(branch_t *), commit);
}
if (modify && src_branch != NULL && dst_is_root && src_is_root && branch->dirty) {
parent = commit_cache_get(ctx->commits, change->copyfrom_rev, src_branch);
if (parent != NULL) {
commit->parent = parent->mark;
return SVN_NO_ERROR;
}
}
apr_array_header_t *changes = get_branch_changes(rev, branch);
change_t *c = apr_array_push(changes);
node = apr_pcalloc(result_pool, sizeof(node_t));
node->kind = kind;
node->path = node_path;
c->action = action;
c->node = node;
if (action == svn_fs_path_change_delete) {
return SVN_NO_ERROR;
}
if (action == svn_fs_path_change_replace && kind == svn_node_dir && src_path == NULL) {
c->action = svn_fs_path_change_delete;
return SVN_NO_ERROR;
}
SVN_ERR(set_node_mode(&node->mode, rev->root, path, scratch_pool));
if (change->mergeinfo_mod == svn_tristate_true) {
SVN_ERR(get_mergeinfo_for_path(&mergeinfo, rev->root, path, scratch_pool, scratch_pool));
}
if (mergeinfo != NULL) {
apr_hash_index_t *idx;
for (idx = apr_hash_first(scratch_pool, mergeinfo); idx; idx = apr_hash_next(idx)) {
const char *merge_src_path = apr_hash_this_key(idx);
merge_src_path = svn_dirent_skip_ancestor("/", merge_src_path);
svn_rangelist_t *merge_ranges = apr_hash_this_val(idx);
svn_merge_range_t *last_range;
svn_revnum_t last_merged;
merge_branch = branch_storage_lookup_path(ctx->branches, merge_src_path, scratch_pool);
if (merge_branch == NULL) {
continue;
}
last_range = &APR_ARRAY_IDX(merge_ranges, merge_ranges->nelts - 1, svn_merge_range_t);
if (last_range->start < last_range->end) {
last_merged = last_range->end;
} else {
last_merged = last_range->start;
}
if (last_merged > rev->revnum) {
last_merged = rev->revnum - 1;
}
parent = commit_cache_get(ctx->commits, last_merged, merge_branch);
if (parent != NULL) {
commit_cache_add_merge(ctx->commits, commit, parent, scratch_pool);
}
}
}
if (src_branch != NULL) {
parent = commit_cache_get(ctx->commits, change->copyfrom_rev, src_branch);
if (parent != NULL) {
commit_cache_add_merge(ctx->commits, commit, parent, scratch_pool);
}
}
if (kind == svn_node_file) {
SVN_ERR(set_content_checksum(&node->checksum, &node->cached,
dst, ctx->blobs, rev->root, path,
result_pool, scratch_pool));
return SVN_NO_ERROR;
}
if (kind == svn_node_dir && src_branch != NULL) {
const char *src_node_path = svn_relpath_skip_ancestor(src_branch->path, src_path);
svn_fs_t *fs = svn_fs_root_fs(rev->root);
svn_fs_root_t *src_root;
tree_t *ignores = NULL;
// Ignore paths of sub-branches
const tree_t *sub_branches = tree_subtree(ctx->branches->tree, src_path, scratch_pool);
// Ignore by absolute path
const tree_t *abs_ignores = tree_subtree(ctx->absignores, src_path, scratch_pool);
// Ignore by relative path
const tree_t *rel_ignores = tree_subtree(ctx->ignores, src_node_path, scratch_pool);
// Do not ignore by absolute path
const tree_t *no_ignores = tree_subtree(ctx->no_ignores, src_path, scratch_pool);
tree_merge(&ignores, sub_branches, abs_ignores, scratch_pool);
tree_merge(&ignores, ignores, rel_ignores, scratch_pool);
tree_diff(&ignores, ignores, no_ignores, scratch_pool);
// Do not match by tree root node, i.e. do not ignore source path itself.
// We can merge orphan branch into parent branch.
ignores->value = NULL;
SVN_ERR(svn_fs_revision_root(&src_root, fs, change->copyfrom_rev, scratch_pool));
SVN_ERR(set_tree_checksum(&node->checksum, &node->cached, &node->entries,
dst, ctx->blobs, src_root, src_path,
src_path, node->path, ignores,
result_pool, scratch_pool));
}
return SVN_NO_ERROR;
}
static svn_error_t *
reset_branch(svn_stream_t *dst,
branch_t *branch,
commit_t *commit,
apr_pool_t *pool)
{
SVN_ERR(svn_stream_printf(dst, pool, "reset %s\n", branch->refname));
SVN_ERR(svn_stream_printf(dst, pool, "from :%d\n", commit->mark));
return SVN_NO_ERROR;
}
static svn_error_t *
node_modify(svn_stream_t *dst, const node_t *node, apr_pool_t *pool)
{
const char *checksum;
checksum = svn_checksum_to_cstring_display(node->checksum, pool);
if (node->kind == svn_node_dir && node->cached == FALSE) {
for (int i = 0; i < node->entries->nelts; i++) {
const node_t *subnode = &APR_ARRAY_IDX(node->entries, i, node_t);
SVN_ERR(node_modify(dst, subnode, pool));
}
} else {
SVN_ERR(svn_stream_printf(dst, pool, "M %o %s \"%s\"\n",
node->mode, checksum, node->path));
}
return SVN_NO_ERROR;
}
static svn_error_t *
node_delete(svn_stream_t *dst, const node_t *node, apr_pool_t *pool)
{
SVN_ERR(svn_stream_printf(dst, pool, "D \"%s\"\n", node->path));
return SVN_NO_ERROR;
}
static svn_error_t *
write_commit(svn_stream_t *dst,
branch_t *branch,
commit_t *commit,
revision_t *rev,
export_ctx_t *ctx,
apr_pool_t *pool)
{
apr_array_header_t *changes;
changes = get_branch_changes(rev, branch);
if (changes->nelts == 0 && commit->parent) {
// In case there is only one node in a commit and this node is
// a root directory copied from another branch, mark this commit
// as dummy, set copyfrom commit as its parent and reset branch to it.
commit->mark = commit->parent;
SVN_ERR(reset_branch(dst, branch, commit, pool));
} else {
apr_time_exp_t time_exp;
commit_cache_set_mark(ctx->commits, commit);
apr_time_exp_lt(&time_exp, rev->timestamp);
SVN_ERR(svn_stream_printf(dst, pool, "commit %s\n", branch->refname));
SVN_ERR(svn_stream_printf(dst, pool, "mark :%d\n", commit->mark));
SVN_ERR(svn_stream_printf(dst, pool, "committer %s %ld %+.2d%.2d\n",
author_to_cstring(rev->author, pool),
apr_time_sec(rev->timestamp),
time_exp.tm_gmtoff / 3600,
(abs(time_exp.tm_gmtoff) / 60) % 60));
SVN_ERR(svn_stream_printf(dst, pool, "data %ld\n", rev->message->len));
SVN_ERR(svn_stream_printf(dst, pool, "%s\n", rev->message->data));
if (commit->parent) {
SVN_ERR(svn_stream_printf(dst, pool, "from :%d\n", commit->parent));
}
for (int i = 0; i < commit->merges->nelts; i++) {
mark_t merge = APR_ARRAY_IDX(commit->merges, i, mark_t);
SVN_ERR(svn_stream_printf(dst, pool, "merge :%d\n", merge));
}
}
for (int i = 0; i < changes->nelts; i++) {
change_t *change = &APR_ARRAY_IDX(changes, i, change_t);
switch (change->action) {
case svn_fs_path_change_add:
case svn_fs_path_change_modify:
SVN_ERR(node_modify(dst, change->node, pool));
break;
case svn_fs_path_change_delete:
SVN_ERR(node_delete(dst, change->node, pool));
break;
case svn_fs_path_change_replace:
SVN_ERR(node_delete(dst, change->node, pool));
SVN_ERR(node_modify(dst, change->node, pool));
default:
// noop
break;
}
}
branch->dirty = FALSE;
return SVN_NO_ERROR;
}
static svn_error_t *
remove_branch(svn_stream_t *dst, branch_t *branch, apr_pool_t *pool)
{
SVN_ERR(svn_stream_printf(dst, pool, "reset %s\n", branch->refname));
SVN_ERR(svn_stream_printf(dst, pool, "from %s\n", NULL_SHA1));
branch->dirty = TRUE;
return SVN_NO_ERROR;
}
static svn_error_t *
write_revision(svn_stream_t *dst,
revision_t *rev,
export_ctx_t *ctx,
apr_pool_t *pool)
{
apr_hash_index_t *idx;
svn_boolean_t skip;
skip = (apr_hash_count(rev->commits) == 0 &&
apr_hash_count(rev->removes) == 0);
if (skip) {
SVN_ERR(svn_stream_printf(dst, pool,
"progress Skipped revision %ld\n",
rev->revnum));
return SVN_NO_ERROR;
}
for (idx = apr_hash_first(pool, rev->removes); idx; idx = apr_hash_next(idx)) {
branch_t *branch = apr_hash_this_val(idx);
SVN_ERR(remove_branch(dst, branch, pool));
}
for (idx = apr_hash_first(pool, rev->commits); idx; idx = apr_hash_next(idx)) {
branch_t *branch = (branch_t *) apr_hash_this_key(idx);
commit_t *commit = apr_hash_this_val(idx);
SVN_ERR(write_commit(dst, branch, commit, rev, ctx, pool));
}
SVN_ERR(svn_stream_printf(dst, pool,
"progress Imported revision %ld\n",
rev->revnum));
return SVN_NO_ERROR;
}
static svn_error_t *
prepare_changes(apr_array_header_t **dst,
apr_array_header_t *fs_changes,
svn_fs_root_t *root,
export_ctx_t *ctx,
apr_pool_t *result_pool,
apr_pool_t *scratch_pool)
{
apr_array_header_t *changes = apr_array_make(result_pool, 0, sizeof(sort_item_t));
for (int i = 0; i < fs_changes->nelts; i++) {
apr_array_header_t *copies, *removes;
svn_boolean_t remove, modify;
sort_item_t item = APR_ARRAY_IDX(fs_changes, i, sort_item_t);
svn_fs_path_change2_t *change = item.value;
svn_fs_path_change_kind_t action = change->change_kind;
// Convert dirent paths to relpaths.
const char *path = svn_dirent_skip_ancestor("/", item.key);
if (change->copyfrom_known && SVN_IS_VALID_REVNUM(change->copyfrom_rev)) {
change->copyfrom_path = svn_dirent_skip_ancestor("/", change->copyfrom_path);
}
sort_item_t *new_item = apr_array_push(changes);
new_item->key = path;
new_item->value = change;
if (change->node_kind != svn_node_dir) {
continue;
}
remove = (action == svn_fs_path_change_replace ||
action == svn_fs_path_change_delete);
modify = (action == svn_fs_path_change_replace ||
action == svn_fs_path_change_add ||
action == svn_fs_path_change_modify);
if (remove) {
removes = tree_values(ctx->branches->tree, path, scratch_pool, scratch_pool);
for (int i = 0; i < removes->nelts; i++) {
branch_t *branch = APR_ARRAY_IDX(removes, i, branch_t *);
if (branch_path_is_root(branch, path)) {
continue;
}
sort_item_t *subitem = apr_array_push(changes);
svn_fs_path_change2_t *subchange = apr_pcalloc(result_pool, sizeof(svn_fs_path_change2_t));
subitem->key = branch->path;
subitem->value = subchange;
subchange->change_kind = svn_fs_path_change_delete;
subchange->node_kind = svn_node_dir;
}
}
if (modify && change->copyfrom_known && SVN_IS_VALID_REVNUM(change->copyfrom_rev)) {
const char *src_path = change->copyfrom_path;
svn_fs_t *fs = svn_fs_root_fs(root);
svn_fs_root_t *src_root;
SVN_ERR(svn_fs_revision_root(&src_root, fs, change->copyfrom_rev, scratch_pool));
copies = tree_values(ctx->branches->tree, src_path, scratch_pool, scratch_pool);
for (int i = 0; i < copies->nelts; i++) {
const char *new_path;
svn_node_kind_t kind;
branch_t *branch = APR_ARRAY_IDX(copies, i, branch_t *);
if (branch_path_is_root(branch, path)) {
continue;
}
SVN_ERR(svn_fs_check_path(&kind, src_root, branch->path, scratch_pool));
if (kind == svn_node_none) {
continue;
}
new_path = svn_relpath_join(path, svn_relpath_skip_ancestor(src_path, branch->path), result_pool);
sort_item_t *subitem = apr_array_push(changes);
svn_fs_path_change2_t *subchange = apr_pcalloc(result_pool, sizeof(svn_fs_path_change2_t));
subitem->key = new_path;
subitem->value = subchange;
subchange->change_kind = svn_fs_path_change_add;
subchange->node_kind = svn_node_dir;
subchange->copyfrom_known = TRUE;
subchange->copyfrom_rev = change->copyfrom_rev;
subchange->copyfrom_path = branch->path;
}
}
}
*dst = changes;
return SVN_NO_ERROR;
}
export_ctx_t *
export_ctx_create(apr_pool_t *pool)
{
export_ctx_t *ctx = apr_pcalloc(pool, sizeof(export_ctx_t));
ctx->authors = author_storage_create(pool);
ctx->branches = branch_storage_create(pool);
ctx->commits = commit_cache_create(pool);
ctx->blobs = checksum_cache_create(pool);
ctx->ignores = tree_create(pool);
ctx->absignores = tree_create(pool);
ctx->no_ignores = tree_create(pool);
return ctx;
}
svn_error_t *
export_revision_range(svn_stream_t *dst,
svn_fs_t *fs,
svn_revnum_t lower,
svn_revnum_t upper,
export_ctx_t *ctx,
svn_cancel_func_t cancel_func,
apr_pool_t *pool)
{
apr_pool_t *rev_pool, *scratch_pool;
rev_pool = svn_pool_create(pool);
for (svn_revnum_t revnum = lower; revnum <= upper; revnum++) {
SVN_ERR(cancel_func(NULL));
apr_array_header_t *changes, *sorted_changes;
apr_hash_t *fs_changes;
revision_t *rev;
svn_pool_clear(rev_pool);
scratch_pool = svn_pool_create(rev_pool);
SVN_ERR(get_revision(&rev, revnum, fs, ctx, rev_pool));
// Fetch the paths changed under revision root.
SVN_ERR(svn_fs_paths_changed2(&fs_changes, rev->root, rev_pool));
sorted_changes = sort_hash(fs_changes, compare_items_as_paths, rev_pool);
SVN_ERR(prepare_changes(&changes, sorted_changes, rev->root, ctx, rev_pool, scratch_pool));
for (int i = 0; i < changes->nelts; i++) {
svn_pool_clear(scratch_pool);
sort_item_t item = APR_ARRAY_IDX(changes, i, sort_item_t);
SVN_ERR(process_change_record(item.key, item.value, dst, rev, ctx, rev_pool, scratch_pool));
}
SVN_ERR(write_revision(dst, rev, ctx, rev_pool));
}
SVN_ERR(svn_stream_printf(dst, pool, "done\n"));
return SVN_NO_ERROR;
}