summaryrefslogtreecommitdiff
path: root/subversion/include/svn_mergeinfo.h
blob: ad1bd47f17f0aecaa1937ef3d07f43f6ad04ec28 (plain)
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
633
634
635
636
637
638
639
640
641
/**
 * @copyright
 * ====================================================================
 *    Licensed to the Apache Software Foundation (ASF) under one
 *    or more contributor license agreements.  See the NOTICE file
 *    distributed with this work for additional information
 *    regarding copyright ownership.  The ASF licenses this file
 *    to you under the Apache License, Version 2.0 (the
 *    "License"); you may not use this file except in compliance
 *    with the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing,
 *    software distributed under the License is distributed on an
 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *    KIND, either express or implied.  See the License for the
 *    specific language governing permissions and limitations
 *    under the License.
 * ====================================================================
 * @endcopyright
 *
 * @file svn_mergeinfo.h
 * @brief mergeinfo handling and processing
 */


#ifndef SVN_MERGEINFO_H
#define SVN_MERGEINFO_H

#include <apr_pools.h>
#include <apr_tables.h>  /* for apr_array_header_t */
#include <apr_hash.h>

#include "svn_types.h"
#include "svn_string.h"  /* for svn_string_t */


#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/** Overview of the @c SVN_PROP_MERGEINFO property.
 *
 * Merge history is stored in the @c SVN_PROP_MERGEINFO property of files
 * and directories.  The @c SVN_PROP_MERGEINFO property on a path stores the
 * complete list of changes merged to that path, either directly or via the
 * path's parent, grand-parent, etc..  A path may have empty mergeinfo which
 * means that nothing has been merged to that path or all previous merges
 * to the path were reversed.  Note that a path may have no mergeinfo, this
 * is not the same as empty mergeinfo.
 *
 * Every path in a tree may have @c SVN_PROP_MERGEINFO set, but if the
 * @c SVN_PROP_MERGEINFO for a path is equivalent to the
 * @c SVN_PROP_MERGEINFO for its parent, then the @c SVN_PROP_MERGEINFO on
 * the path will 'elide' (be removed) from the path as a post step to any
 * merge.  If a path's parent does not have any @c SVN_PROP_MERGEINFO set,
 * the path's mergeinfo can elide to its nearest grand-parent,
 * great-grand-parent, etc. that has equivalent @c SVN_PROP_MERGEINFO set
 * on it.
 *
 * If a path has no @c SVN_PROP_MERGEINFO of its own, it inherits mergeinfo
 * from its nearest parent that has @c SVN_PROP_MERGEINFO set.  The
 * exception to this is @c SVN_PROP_MERGEINFO with non-inheritable revision
 * ranges.  These non-inheritable ranges apply only to the path which they
 * are set on.
 *
 * Due to Subversion's allowance for mixed revision working copies, both
 * elision and inheritance within the working copy presume the path
 * between a path and its nearest parent with mergeinfo is at the same
 * working revision.  If this is not the case then neither inheritance nor
 * elision can occur.
 *
 * The value of the @c SVN_PROP_MERGEINFO property is either an empty string
 * (representing empty mergeinfo) or a non-empty string consisting of
 * a path, a colon, and comma separated revision list, containing one or more
 * revision or revision ranges. Revision range start and end points are
 * separated by "-".  Revisions and revision ranges may have the optional
 * @c SVN_MERGEINFO_NONINHERITABLE_STR suffix to signify a non-inheritable
 * revision/revision range.
 *
 * @c SVN_PROP_MERGEINFO Value Grammar:
 *
 *   Token             Definition
 *   -----             ----------
 *   revisionrange     REVISION1 "-" REVISION2
 *   revisioneelement  (revisionrange | REVISION)"*"?
 *   rangelist         revisioneelement (COMMA revisioneelement)*
 *   revisionline      PATHNAME COLON rangelist
 *   top               "" | (revisionline (NEWLINE revisionline))*
 *
 * The PATHNAME is the source of a merge and the rangelist the revision(s)
 * merged to the path @c SVN_PROP_MERGEINFO is set on directly or indirectly
 * via inheritance.  PATHNAME must always exist at the specified rangelist
 * and thus a single merge may result in multiple revisionlines if the source
 * was renamed.
 *
 * Rangelists must be sorted from lowest to highest revision and cannot
 * contain overlapping revisionlistelements.  REVISION1 must be less than
 * REVISION2.  Consecutive single revisions that can be represented by a
 * revisionrange are allowed however (e.g. '5,6,7,8,9-12' or '5-12' are
 * both acceptable).
 */

/** Suffix for SVN_PROP_MERGEINFO revision ranges indicating a given
   range is non-inheritable. */
#define SVN_MERGEINFO_NONINHERITABLE_STR "*"

/** Terminology for data structures that contain mergeinfo.
 *
 * Subversion commonly uses several data structures to represent
 * mergeinfo in RAM:
 *
 * (a) Strings (@c svn_string_t *) containing "unparsed mergeinfo".
 *
 * (b) @c svn_rangelist_t, called a "rangelist".
 *
 * (c) @c svn_mergeinfo_t, called "mergeinfo".
 *
 * (d) @c svn_mergeinfo_catalog_t, called a "mergeinfo catalog".
 *
 * Both @c svn_mergeinfo_t and @c svn_mergeinfo_catalog_t are just
 * typedefs for @c apr_hash_t *; there is no static type-checking, and
 * you still use standard @c apr_hash_t functions to interact with
 * them.
 */

/** An array of non-overlapping merge ranges (@c svn_merge_range_t *),
 * sorted as said by @c svn_sort_compare_ranges().  An empty range list is
 * represented by an empty array.
 *
 * Unless specifically noted otherwise, all APIs require rangelists that
 * describe only forward ranges, i.e. the range's start revision is less
 * than its end revision. */
typedef apr_array_header_t svn_rangelist_t;

/** A hash mapping merge source paths to non-empty rangelist arrays.
 *
 * The keys are (@c const char *) absolute paths from the repository root,
 * starting with slashes. A @c NULL hash represents no mergeinfo and an
 * empty hash represents empty mergeinfo. */
typedef apr_hash_t *svn_mergeinfo_t;

/** A hash mapping paths (@c const char *) to @c svn_mergeinfo_t.
 *
 * @note While the keys of #svn_mergeinfo_t are always absolute from the
 * repository root, the keys of a catalog may be relative to something
 * else, such as an RA session root.
 * */
typedef apr_hash_t *svn_mergeinfo_catalog_t;

/** Parse the mergeinfo from @a input into @a *mergeinfo.  If no
 * mergeinfo is available, return an empty mergeinfo (never @c NULL).
 *
 * If @a input is not a grammatically correct @c SVN_PROP_MERGEINFO
 * property, contains overlapping revision ranges of differing
 * inheritability, or revision ranges with a start revision greater
 * than or equal to its end revision, or contains paths mapped to empty
 * revision ranges, then return  @c SVN_ERR_MERGEINFO_PARSE_ERROR.
 * Unordered revision ranges are  allowed, but will be sorted when
 * placed into @a *mergeinfo.  Overlapping revision ranges of the same
 * inheritability are also allowed, but will be combined into a single
 * range when placed into @a *mergeinfo.
 *
 * @a input may contain relative merge source paths, but these are
 * converted to absolute paths in @a *mergeinfo.
 *
 * Allocate the result deeply in @a pool. Also perform temporary
 * allocations in @a pool.
 *
 * @since New in 1.5.
 */
svn_error_t *
svn_mergeinfo_parse(svn_mergeinfo_t *mergeinfo, const char *input,
                    apr_pool_t *pool);

/** Calculate the delta between two mergeinfos, @a mergefrom and @a mergeto
 * (either or both of which may be @c NULL meaning an empty mergeinfo).
 * Place the result in @a *deleted and @a *added (neither output argument
 * may be @c NULL), both allocated in @a result_pool.  The resulting
 * @a *deleted and @a *added will not be null.
 *
 * @a consider_inheritance determines how the rangelists in the two
 * hashes are compared for equality.  If @a consider_inheritance is FALSE,
 * then the start and end revisions of the @c svn_merge_range_t's being
 * compared are the only factors considered when determining equality.
 *
 *  e.g. '/trunk: 1,3-4*,5' == '/trunk: 1,3-5'
 *
 * If @a consider_inheritance is TRUE, then the inheritability of the
 * @c svn_merge_range_t's is also considered and must be the same for two
 * otherwise identical ranges to be judged equal.
 *
 *  e.g. '/trunk: 1,3-4*,5' != '/trunk: 1,3-5'
 *       '/trunk: 1,3-4*,5' == '/trunk: 1,3-4*,5'
 *       '/trunk: 1,3-4,5'  == '/trunk: 1,3-4,5'
 *
 * @since New in 1.8.
 */
svn_error_t *
svn_mergeinfo_diff2(svn_mergeinfo_t *deleted, svn_mergeinfo_t *added,
                    svn_mergeinfo_t mergefrom, svn_mergeinfo_t mergeto,
                    svn_boolean_t consider_inheritance,
                    apr_pool_t *result_pool,
                    apr_pool_t *scratch_pool);

/** Similar to svn_mergeinfo_diff2(), but users only one pool.
 *
 * @deprecated Provided for backward compatibility with the 1.7 API.
 * @since New in 1.5.
 */
SVN_DEPRECATED
svn_error_t *
svn_mergeinfo_diff(svn_mergeinfo_t *deleted, svn_mergeinfo_t *added,
                   svn_mergeinfo_t mergefrom, svn_mergeinfo_t mergeto,
                   svn_boolean_t consider_inheritance,
                   apr_pool_t *pool);

/** Merge a shallow copy of one mergeinfo, @a changes, into another mergeinfo
 * @a mergeinfo.
 *
 * Rangelists for merge source paths common to @a changes and @a mergeinfo may
 * result in new rangelists; these are allocated in @a result_pool.
 * Temporary allocations are made in @a scratch_pool.
 *
 * When intersecting rangelists for a path are merged, the inheritability of
 * the resulting svn_merge_range_t depends on the inheritability of the
 * operands.  If two non-inheritable ranges are merged the result is always
 * non-inheritable, in all other cases the resulting range is inheritable.
 *
 *  e.g. '/A: 1,3-4'  merged with '/A: 1,3,4*,5' --> '/A: 1,3-5'
 *       '/A: 1,3-4*' merged with '/A: 1,3,4*,5' --> '/A: 1,3,4*,5'
 *
 * @since New in 1.8.
 */
svn_error_t *
svn_mergeinfo_merge2(svn_mergeinfo_t mergeinfo,
                     svn_mergeinfo_t changes,
                     apr_pool_t *result_pool,
                     apr_pool_t *scratch_pool);

/** Like svn_mergeinfo_merge2, but uses only one pool.
 *
 * @deprecated Provided for backward compatibility with the 1.5 API.
 */
SVN_DEPRECATED
svn_error_t *
svn_mergeinfo_merge(svn_mergeinfo_t mergeinfo,
                    svn_mergeinfo_t changes,
                    apr_pool_t *pool);

/** Combine one mergeinfo catalog, @a changes_catalog, into another mergeinfo
 * catalog @a mergeinfo_catalog.  If both catalogs have mergeinfo for the same
 * key, use svn_mergeinfo_merge() to combine the mergeinfos.
 *
 * Additions to @a mergeinfo_catalog are deep copies allocated in
 * @a result_pool.  Temporary allocations are made in @a scratch_pool.
 *
 * @since New in 1.7.
 */
svn_error_t *
svn_mergeinfo_catalog_merge(svn_mergeinfo_catalog_t mergeinfo_catalog,
                            svn_mergeinfo_catalog_t changes_catalog,
                            apr_pool_t *result_pool,
                            apr_pool_t *scratch_pool);

/** Like svn_mergeinfo_remove2, but always considers inheritance.
 *
 * @deprecated Provided for backward compatibility with the 1.6 API.
 */
SVN_DEPRECATED
svn_error_t *
svn_mergeinfo_remove(svn_mergeinfo_t *mergeinfo, svn_mergeinfo_t eraser,
                     svn_mergeinfo_t whiteboard, apr_pool_t *pool);

/** Removes @a eraser (the subtrahend) from @a whiteboard (the
 * minuend), and places the resulting difference in @a *mergeinfo.
 * Allocates @a *mergeinfo in @a result_pool.  Temporary allocations
 * will be performed in @a scratch_pool.
 *
 * @a consider_inheritance determines how to account for the inheritability
 * of the two mergeinfo's ranges when calculating the range equivalence,
 * as described for svn_mergeinfo_diff().
 *
 * @since New in 1.7.
 */
svn_error_t *
svn_mergeinfo_remove2(svn_mergeinfo_t *mergeinfo,
                      svn_mergeinfo_t eraser,
                      svn_mergeinfo_t whiteboard,
                      svn_boolean_t consider_inheritance,
                      apr_pool_t *result_pool,
                      apr_pool_t *scratch_pool);

/** Calculate the delta between two rangelists consisting of @c
 * svn_merge_range_t * elements (sorted in ascending order), @a from
 * and @a to, and place the result in @a *deleted and @a *added
 * (neither output argument will ever be @c NULL).
 *
 * @a consider_inheritance determines how to account for the inheritability
 * of the two rangelist's ranges when calculating the diff,
 * as described for svn_mergeinfo_diff().
 *
 * @since New in 1.5.
 */
svn_error_t *
svn_rangelist_diff(svn_rangelist_t **deleted, svn_rangelist_t **added,
                   const svn_rangelist_t *from, const svn_rangelist_t *to,
                   svn_boolean_t consider_inheritance,
                   apr_pool_t *pool);

/** Merge two rangelists consisting of @c svn_merge_range_t *
 * elements, @a rangelist and @a changes, placing the results in
 * @a rangelist. New elements added to @a rangelist are allocated
 * in @a result_pool. Either rangelist may be empty.
 *
 * When intersecting rangelists are merged, the inheritability of
 * the resulting svn_merge_range_t depends on the inheritability of the
 * operands: see svn_mergeinfo_merge().
 *
 * Note: @a rangelist and @a changes must be sorted as said by @c
 * svn_sort_compare_ranges().  @a rangelist is guaranteed to remain
 * in sorted order and be compacted to the minimal number of ranges
 * needed to represent the merged result.
 *
 * If the original rangelist contains non-collapsed adjacent ranges,
 * the final result is not guaranteed to be compacted either.
 *
 * Use @a scratch_pool for temporary allocations.
 *
 * @since New in 1.8.
 */
svn_error_t *
svn_rangelist_merge2(svn_rangelist_t *rangelist,
                     const svn_rangelist_t *changes,
                     apr_pool_t *result_pool,
                     apr_pool_t *scratch_pool);

/** Like svn_rangelist_merge2(), but with @a rangelist as an input/output
 * argument. This function always allocates a new rangelist in @a pool and
 * returns its result in @a *rangelist. It does not modify @a *rangelist
 * in place. If not used carefully, this function can use up a lot of memory
 * if called in a loop.
 *
 * It performs an extra adjacent range compaction round to make sure non
 * collapsed input ranges are compacted in the result.
 *
 * @since New in 1.5.
 * @deprecated Provided for backward compatibility with the 1.7 API.
 */
SVN_DEPRECATED
svn_error_t *
svn_rangelist_merge(svn_rangelist_t **rangelist,
                    const svn_rangelist_t *changes,
                    apr_pool_t *pool);

/** Removes @a eraser (the subtrahend) from @a whiteboard (the
 * minuend), and places the resulting difference in @a output.
 *
 * Note: @a eraser and @a whiteboard must be sorted as said by @c
 * svn_sort_compare_ranges().  @a output is guaranteed to be in sorted
 * order.
 *
 * @a consider_inheritance determines how to account for the
 * @c svn_merge_range_t inheritable field when comparing @a whiteboard's
 * and @a *eraser's rangelists for equality.  @see svn_mergeinfo_diff().
 *
 * Allocate the entire output in @a pool.
 *
 * @since New in 1.5.
 */
svn_error_t *
svn_rangelist_remove(svn_rangelist_t **output, const svn_rangelist_t *eraser,
                     const svn_rangelist_t *whiteboard,
                     svn_boolean_t consider_inheritance,
                     apr_pool_t *pool);

/** Find the intersection of two mergeinfos, @a mergeinfo1 and @a
 * mergeinfo2, and place the result in @a *mergeinfo, which is (deeply)
 * allocated in @a result_pool.  Temporary allocations will be performed
 * in @a scratch_pool.
 *
 * @a consider_inheritance determines how to account for the inheritability
 * of the two mergeinfo's ranges when calculating the range equivalence,
 * @see svn_rangelist_intersect().
 *
 * @since New in 1.7.
 */
svn_error_t *
svn_mergeinfo_intersect2(svn_mergeinfo_t *mergeinfo,
                         svn_mergeinfo_t mergeinfo1,
                         svn_mergeinfo_t mergeinfo2,
                         svn_boolean_t consider_inheritance,
                         apr_pool_t *result_pool,
                         apr_pool_t *scratch_pool);

/** Like svn_mergeinfo_intersect2, but always considers inheritance.
 *
 * @deprecated Provided for backward compatibility with the 1.6 API.
 */
SVN_DEPRECATED
svn_error_t *
svn_mergeinfo_intersect(svn_mergeinfo_t *mergeinfo,
                        svn_mergeinfo_t mergeinfo1,
                        svn_mergeinfo_t mergeinfo2,
                        apr_pool_t *pool);

/** Find the intersection of two rangelists consisting of @c
 * svn_merge_range_t * elements, @a rangelist1 and @a rangelist2, and
 * place the result in @a *rangelist (which is never @c NULL).
 *
 * @a consider_inheritance determines how to account for the inheritability
 * of the two rangelist's ranges when calculating the intersection,
 * @see svn_mergeinfo_diff().  If @a consider_inheritance is FALSE then
 * ranges with different inheritance can intersect, but the resulting
 * @a *rangelist is non-inheritable only if the corresponding ranges from
 * both @a rangelist1 and @a rangelist2 are non-inheritable.
 * If @a consider_inheritance is TRUE, then ranges with different
 * inheritance can never intersect.
 *
 * Note: @a rangelist1 and @a rangelist2 must be sorted as said by @c
 * svn_sort_compare_ranges(). @a *rangelist is guaranteed to be in sorted
 * order.
 *
 * Allocate the entire output in @a pool.
 *
 * @since New in 1.5.
 */
svn_error_t *
svn_rangelist_intersect(svn_rangelist_t **rangelist,
                        const svn_rangelist_t *rangelist1,
                        const svn_rangelist_t *rangelist2,
                        svn_boolean_t consider_inheritance,
                        apr_pool_t *pool);

/** Reverse @a rangelist, and the @c start and @c end fields of each
 * range in @a rangelist, in place.
 *
 * TODO(miapi): Is this really a valid function?  Rangelists that
 * aren't sorted, or rangelists containing reverse ranges, are
 * generally not valid in mergeinfo code.  Can we rewrite the two
 * places where this is used?
 *
 * @since New in 1.5.
 */
svn_error_t *
svn_rangelist_reverse(svn_rangelist_t *rangelist, apr_pool_t *pool);

/** Take an array of svn_merge_range_t *'s in @a rangelist, and convert it
 * back to a text format rangelist in @a output.  If @a rangelist contains
 * no elements, sets @a output to the empty string.
 *
 * @since New in 1.5.
 */
svn_error_t *
svn_rangelist_to_string(svn_string_t **output,
                        const svn_rangelist_t *rangelist,
                        apr_pool_t *pool);

/** Remove non-inheritable or inheritable revision ranges from a rangelist.
 *
 * Set @a *inheritable_rangelist to a deep copy of @a rangelist, excluding
 * all non-inheritable @c svn_merge_range_t if @a inheritable is TRUE or
 * excluding all inheritable @c svn_merge_range_t otherwise.
 *
 * If @a start and @a end are valid revisions and @a start is less than or
 * equal to @a end, then exclude only the (non-inheritable or inheritable)
 * revision ranges that intersect inclusively with the range defined by
 * @a start and @a end.
 *
 * If there are no remaining ranges, return an empty array.
 *
 * Allocate the copy in @a result_pool, and use @a scratch_pool for
 * temporary allocations.
 *
 * @since New in 1.7.
 */
svn_error_t *
svn_rangelist_inheritable2(svn_rangelist_t **inheritable_rangelist,
                           const svn_rangelist_t *rangelist,
                           svn_revnum_t start,
                           svn_revnum_t end,
                           svn_boolean_t inheritable,
                           apr_pool_t *result_pool,
                           apr_pool_t *scratch_pool);

/** Like svn_rangelist_inheritable2, but always finds inheritable ranges.
 *
 * @since New in 1.5.
 * @deprecated Provided for backward compatibility with the 1.6 API.
 */
SVN_DEPRECATED
svn_error_t *
svn_rangelist_inheritable(svn_rangelist_t **inheritable_rangelist,
                          const svn_rangelist_t *rangelist,
                          svn_revnum_t start,
                          svn_revnum_t end,
                          apr_pool_t *pool);

/** Remove non-inheritable or inheritable revision ranges from mergeinfo.
 *
 * Set @a *inheritable_mergeinfo to a deep copy of @a mergeinfo, excluding
 * all non-inheritable @c svn_merge_range_t if @a inheritable is TRUE or
 * excluding all inheritable @c svn_merge_range_t otherwise.
 *
 * If @a start and @a end are valid revisions and @a start is less than or
 * equal to @a end, then exclude only the (non-inheritable or inheritable)
 * revisions that intersect inclusively with the range defined by @a start
 * and @a end.
 *
 * If @a path is not NULL remove (non-inheritable or inheritable) ranges
 * only for @a path.
 *
 * If all ranges are removed for a given path then remove that path as well.
 * If @a mergeinfo is initially empty or all paths are removed from it then
 * set @a *inheritable_mergeinfo to an empty mergeinfo.
 *
 * Allocate the copy in @a result_pool, and use @a scratch_pool for
 * temporary allocations.
 *
 * @since New in 1.7.
 */
svn_error_t *
svn_mergeinfo_inheritable2(svn_mergeinfo_t *inheritable_mergeinfo,
                           svn_mergeinfo_t mergeinfo,
                           const char *path,
                           svn_revnum_t start,
                           svn_revnum_t end,
                           svn_boolean_t inheritable,
                           apr_pool_t *result_pool,
                           apr_pool_t *scratch_pool);

/** Like svn_mergeinfo_inheritable2, but always finds inheritable mergeinfo.
 *
 * @since New in 1.5.
 * @deprecated Provided for backward compatibility with the 1.6 API.
 */
SVN_DEPRECATED
svn_error_t *
svn_mergeinfo_inheritable(svn_mergeinfo_t *inheritable_mergeinfo,
                          svn_mergeinfo_t mergeinfo,
                          const char *path,
                          svn_revnum_t start,
                          svn_revnum_t end,
                          apr_pool_t *pool);

/** Take a mergeinfo in @a mergeinput, and convert it to unparsed
 *  mergeinfo. Set @a *output to the result, allocated in @a pool.
 *  If @a input contains no elements, set @a *output to the empty string.
 *
 * @a mergeinput may contain relative merge source paths, but these are
 * converted to absolute paths in @a *output.
 *
 * @since New in 1.5.
*/
svn_error_t *
svn_mergeinfo_to_string(svn_string_t **output,
                        svn_mergeinfo_t mergeinput,
                        apr_pool_t *pool);

/** Take a hash of mergeinfo in @a mergeinfo, and sort the rangelists
 * associated with each key (in place).
 *
 * TODO(miapi): mergeinfos should *always* be sorted.  This should be
 * a private function.
 *
 * @since New in 1.5
 */
svn_error_t *
svn_mergeinfo_sort(svn_mergeinfo_t mergeinfo, apr_pool_t *pool);

/** Return a deep copy of @a mergeinfo_catalog, allocated in @a pool.
 *
 * @since New in 1.6.
 */
svn_mergeinfo_catalog_t
svn_mergeinfo_catalog_dup(svn_mergeinfo_catalog_t mergeinfo_catalog,
                          apr_pool_t *pool);

/** Return a deep copy of @a mergeinfo, allocated in @a pool.
 *
 * @since New in 1.5.
 */
svn_mergeinfo_t
svn_mergeinfo_dup(svn_mergeinfo_t mergeinfo, apr_pool_t *pool);

/** Return a deep copy of @a rangelist, allocated in @a pool.
 *
 * @since New in 1.5.
 */
svn_rangelist_t *
svn_rangelist_dup(const svn_rangelist_t *rangelist, apr_pool_t *pool);


/**
 * The three ways to request mergeinfo affecting a given path.
 *
 * @since New in 1.5.
 */
typedef enum svn_mergeinfo_inheritance_t
{
  /** Explicit mergeinfo only. */
  svn_mergeinfo_explicit,

  /** Explicit mergeinfo, or if that doesn't exist, the inherited
      mergeinfo from a target's nearest (path-wise, not history-wise)
      ancestor. */
  svn_mergeinfo_inherited,

  /** Mergeinfo inherited from a target's nearest (path-wise, not
      history-wise) ancestor, regardless of whether target has explicit
      mergeinfo. */
  svn_mergeinfo_nearest_ancestor
} svn_mergeinfo_inheritance_t;

/** Return a constant string expressing @a inherit as an English word,
 * i.e., "explicit" (default), "inherited", or "nearest_ancestor".
 * The string is not localized, as it may be used for client<->server
 * communications.
 *
 * @since New in 1.5.
 */
const char *
svn_inheritance_to_word(svn_mergeinfo_inheritance_t inherit);


/** Return the appropriate @c svn_mergeinfo_inheritance_t for @a word.
 * @a word is as returned from svn_inheritance_to_word().  Defaults to
 * @c svn_mergeinfo_explicit.
 *
 * @since New in 1.5.
 */
svn_mergeinfo_inheritance_t
svn_inheritance_from_word(const char *word);


#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* SVN_MERGEINFO_H */