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 * @file svn_mergeinfo.h
24 * @brief mergeinfo handling and processing
28 #ifndef SVN_MERGEINFO_H
29 #define SVN_MERGEINFO_H
31 #include <apr_pools.h>
32 #include <apr_tables.h> /* for apr_array_header_t */
35 #include "svn_types.h"
36 #include "svn_string.h" /* for svn_string_t */
41 #endif /* __cplusplus */
43 /** Overview of the @c SVN_PROP_MERGEINFO property.
45 * Merge history is stored in the @c SVN_PROP_MERGEINFO property of files
46 * and directories. The @c SVN_PROP_MERGEINFO property on a path stores the
47 * complete list of changes merged to that path, either directly or via the
48 * path's parent, grand-parent, etc.. A path may have empty mergeinfo which
49 * means that nothing has been merged to that path or all previous merges
50 * to the path were reversed. Note that a path may have no mergeinfo, this
51 * is not the same as empty mergeinfo.
53 * Every path in a tree may have @c SVN_PROP_MERGEINFO set, but if the
54 * @c SVN_PROP_MERGEINFO for a path is equivalent to the
55 * @c SVN_PROP_MERGEINFO for its parent, then the @c SVN_PROP_MERGEINFO on
56 * the path will 'elide' (be removed) from the path as a post step to any
57 * merge. If a path's parent does not have any @c SVN_PROP_MERGEINFO set,
58 * the path's mergeinfo can elide to its nearest grand-parent,
59 * great-grand-parent, etc. that has equivalent @c SVN_PROP_MERGEINFO set
62 * If a path has no @c SVN_PROP_MERGEINFO of its own, it inherits mergeinfo
63 * from its nearest parent that has @c SVN_PROP_MERGEINFO set. The
64 * exception to this is @c SVN_PROP_MERGEINFO with non-inheritable revision
65 * ranges. These non-inheritable ranges apply only to the path which they
68 * Due to Subversion's allowance for mixed revision working copies, both
69 * elision and inheritance within the working copy presume the path
70 * between a path and its nearest parent with mergeinfo is at the same
71 * working revision. If this is not the case then neither inheritance nor
74 * The value of the @c SVN_PROP_MERGEINFO property is either an empty string
75 * (representing empty mergeinfo) or a non-empty string consisting of
76 * a path, a colon, and comma separated revision list, containing one or more
77 * revision or revision ranges. Revision range start and end points are
78 * separated by "-". Revisions and revision ranges may have the optional
79 * @c SVN_MERGEINFO_NONINHERITABLE_STR suffix to signify a non-inheritable
80 * revision/revision range.
82 * @c SVN_PROP_MERGEINFO Value Grammar:
86 * revisionrange REVISION1 "-" REVISION2
87 * revisioneelement (revisionrange | REVISION)"*"?
88 * rangelist revisioneelement (COMMA revisioneelement)*
89 * revisionline PATHNAME COLON rangelist
90 * top "" | (revisionline (NEWLINE revisionline))*
92 * The PATHNAME is the source of a merge and the rangelist the revision(s)
93 * merged to the path @c SVN_PROP_MERGEINFO is set on directly or indirectly
94 * via inheritance. PATHNAME must always exist at the specified rangelist
95 * and thus a single merge may result in multiple revisionlines if the source
98 * Rangelists must be sorted from lowest to highest revision and cannot
99 * contain overlapping revisionlistelements. REVISION1 must be less than
100 * REVISION2. Consecutive single revisions that can be represented by a
101 * revisionrange are allowed however (e.g. '5,6,7,8,9-12' or '5-12' are
105 /** Suffix for SVN_PROP_MERGEINFO revision ranges indicating a given
106 range is non-inheritable. */
107 #define SVN_MERGEINFO_NONINHERITABLE_STR "*"
109 /** Terminology for data structures that contain mergeinfo.
111 * Subversion commonly uses several data structures to represent
114 * (a) Strings (@c svn_string_t *) containing "unparsed mergeinfo".
116 * (b) @c svn_rangelist_t, called a "rangelist".
118 * (c) @c svn_mergeinfo_t, called "mergeinfo".
120 * (d) @c svn_mergeinfo_catalog_t, called a "mergeinfo catalog".
122 * Both @c svn_mergeinfo_t and @c svn_mergeinfo_catalog_t are just
123 * typedefs for @c apr_hash_t *; there is no static type-checking, and
124 * you still use standard @c apr_hash_t functions to interact with
128 /** An array of non-overlapping merge ranges (@c svn_merge_range_t *),
129 * sorted as said by @c svn_sort_compare_ranges(). An empty range list is
130 * represented by an empty array.
132 * Unless specifically noted otherwise, all APIs require rangelists that
133 * describe only forward ranges, i.e. the range's start revision is less
134 * than its end revision. */
135 typedef apr_array_header_t svn_rangelist_t;
137 /** A hash mapping merge source paths to non-empty rangelist arrays.
139 * The keys are (@c const char *) absolute paths from the repository root,
140 * starting with slashes. A @c NULL hash represents no mergeinfo and an
141 * empty hash represents empty mergeinfo. */
142 typedef apr_hash_t *svn_mergeinfo_t;
144 /** A hash mapping paths (@c const char *) to @c svn_mergeinfo_t.
146 * @note While the keys of #svn_mergeinfo_t are always absolute from the
147 * repository root, the keys of a catalog may be relative to something
148 * else, such as an RA session root.
150 typedef apr_hash_t *svn_mergeinfo_catalog_t;
152 /** Parse the mergeinfo from @a input into @a *mergeinfo. If no
153 * mergeinfo is available, return an empty mergeinfo (never @c NULL).
155 * If @a input is not a grammatically correct @c SVN_PROP_MERGEINFO
156 * property, contains overlapping revision ranges of differing
157 * inheritability, or revision ranges with a start revision greater
158 * than or equal to its end revision, or contains paths mapped to empty
159 * revision ranges, then return @c SVN_ERR_MERGEINFO_PARSE_ERROR.
160 * Unordered revision ranges are allowed, but will be sorted when
161 * placed into @a *mergeinfo. Overlapping revision ranges of the same
162 * inheritability are also allowed, but will be combined into a single
163 * range when placed into @a *mergeinfo.
165 * @a input may contain relative merge source paths, but these are
166 * converted to absolute paths in @a *mergeinfo.
168 * Allocate the result deeply in @a pool. Also perform temporary
169 * allocations in @a pool.
174 svn_mergeinfo_parse(svn_mergeinfo_t *mergeinfo, const char *input,
177 /** Calculate the delta between two mergeinfos, @a mergefrom and @a mergeto
178 * (either or both of which may be @c NULL meaning an empty mergeinfo).
179 * Place the result in @a *deleted and @a *added (neither output argument
180 * may be @c NULL), both allocated in @a result_pool. The resulting
181 * @a *deleted and @a *added will not be null.
183 * @a consider_inheritance determines how the rangelists in the two
184 * hashes are compared for equality. If @a consider_inheritance is FALSE,
185 * then the start and end revisions of the @c svn_merge_range_t's being
186 * compared are the only factors considered when determining equality.
188 * e.g. '/trunk: 1,3-4*,5' == '/trunk: 1,3-5'
190 * If @a consider_inheritance is TRUE, then the inheritability of the
191 * @c svn_merge_range_t's is also considered and must be the same for two
192 * otherwise identical ranges to be judged equal.
194 * e.g. '/trunk: 1,3-4*,5' != '/trunk: 1,3-5'
195 * '/trunk: 1,3-4*,5' == '/trunk: 1,3-4*,5'
196 * '/trunk: 1,3-4,5' == '/trunk: 1,3-4,5'
201 svn_mergeinfo_diff2(svn_mergeinfo_t *deleted, svn_mergeinfo_t *added,
202 svn_mergeinfo_t mergefrom, svn_mergeinfo_t mergeto,
203 svn_boolean_t consider_inheritance,
204 apr_pool_t *result_pool,
205 apr_pool_t *scratch_pool);
207 /** Similar to svn_mergeinfo_diff2(), but users only one pool.
209 * @deprecated Provided for backward compatibility with the 1.7 API.
214 svn_mergeinfo_diff(svn_mergeinfo_t *deleted, svn_mergeinfo_t *added,
215 svn_mergeinfo_t mergefrom, svn_mergeinfo_t mergeto,
216 svn_boolean_t consider_inheritance,
219 /** Merge a shallow copy of one mergeinfo, @a changes, into another mergeinfo
222 * Rangelists for merge source paths common to @a changes and @a mergeinfo may
223 * result in new rangelists; these are allocated in @a result_pool.
224 * Temporary allocations are made in @a scratch_pool.
226 * When intersecting rangelists for a path are merged, the inheritability of
227 * the resulting svn_merge_range_t depends on the inheritability of the
228 * operands. If two non-inheritable ranges are merged the result is always
229 * non-inheritable, in all other cases the resulting range is inheritable.
231 * e.g. '/A: 1,3-4' merged with '/A: 1,3,4*,5' --> '/A: 1,3-5'
232 * '/A: 1,3-4*' merged with '/A: 1,3,4*,5' --> '/A: 1,3,4*,5'
237 svn_mergeinfo_merge2(svn_mergeinfo_t mergeinfo,
238 svn_mergeinfo_t changes,
239 apr_pool_t *result_pool,
240 apr_pool_t *scratch_pool);
242 /** Like svn_mergeinfo_merge2, but uses only one pool.
244 * @deprecated Provided for backward compatibility with the 1.5 API.
248 svn_mergeinfo_merge(svn_mergeinfo_t mergeinfo,
249 svn_mergeinfo_t changes,
252 /** Combine one mergeinfo catalog, @a changes_catalog, into another mergeinfo
253 * catalog @a mergeinfo_catalog. If both catalogs have mergeinfo for the same
254 * key, use svn_mergeinfo_merge() to combine the mergeinfos.
256 * Additions to @a mergeinfo_catalog are deep copies allocated in
257 * @a result_pool. Temporary allocations are made in @a scratch_pool.
262 svn_mergeinfo_catalog_merge(svn_mergeinfo_catalog_t mergeinfo_catalog,
263 svn_mergeinfo_catalog_t changes_catalog,
264 apr_pool_t *result_pool,
265 apr_pool_t *scratch_pool);
267 /** Like svn_mergeinfo_remove2, but always considers inheritance.
269 * @deprecated Provided for backward compatibility with the 1.6 API.
273 svn_mergeinfo_remove(svn_mergeinfo_t *mergeinfo, svn_mergeinfo_t eraser,
274 svn_mergeinfo_t whiteboard, apr_pool_t *pool);
276 /** Removes @a eraser (the subtrahend) from @a whiteboard (the
277 * minuend), and places the resulting difference in @a *mergeinfo.
278 * Allocates @a *mergeinfo in @a result_pool. Temporary allocations
279 * will be performed in @a scratch_pool.
281 * @a consider_inheritance determines how to account for the inheritability
282 * of the two mergeinfo's ranges when calculating the range equivalence,
283 * as described for svn_mergeinfo_diff().
288 svn_mergeinfo_remove2(svn_mergeinfo_t *mergeinfo,
289 svn_mergeinfo_t eraser,
290 svn_mergeinfo_t whiteboard,
291 svn_boolean_t consider_inheritance,
292 apr_pool_t *result_pool,
293 apr_pool_t *scratch_pool);
295 /** Calculate the delta between two rangelists consisting of @c
296 * svn_merge_range_t * elements (sorted in ascending order), @a from
297 * and @a to, and place the result in @a *deleted and @a *added
298 * (neither output argument will ever be @c NULL).
300 * @a consider_inheritance determines how to account for the inheritability
301 * of the two rangelist's ranges when calculating the diff,
302 * as described for svn_mergeinfo_diff().
307 svn_rangelist_diff(svn_rangelist_t **deleted, svn_rangelist_t **added,
308 const svn_rangelist_t *from, const svn_rangelist_t *to,
309 svn_boolean_t consider_inheritance,
312 /** Merge two rangelists consisting of @c svn_merge_range_t *
313 * elements, @a rangelist and @a changes, placing the results in
314 * @a rangelist. New elements added to @a rangelist are allocated
315 * in @a result_pool. Either rangelist may be empty.
317 * When intersecting rangelists are merged, the inheritability of
318 * the resulting svn_merge_range_t depends on the inheritability of the
319 * operands: see svn_mergeinfo_merge().
321 * Note: @a rangelist and @a changes must be sorted as said by @c
322 * svn_sort_compare_ranges(). @a rangelist is guaranteed to remain
323 * in sorted order and be compacted to the minimal number of ranges
324 * needed to represent the merged result.
326 * If the original rangelist contains non-collapsed adjacent ranges,
327 * the final result is not guaranteed to be compacted either.
329 * Use @a scratch_pool for temporary allocations.
334 svn_rangelist_merge2(svn_rangelist_t *rangelist,
335 const svn_rangelist_t *changes,
336 apr_pool_t *result_pool,
337 apr_pool_t *scratch_pool);
339 /** Like svn_rangelist_merge2(), but with @a rangelist as an input/output
340 * argument. This function always allocates a new rangelist in @a pool and
341 * returns its result in @a *rangelist. It does not modify @a *rangelist
342 * in place. If not used carefully, this function can use up a lot of memory
343 * if called in a loop.
345 * It performs an extra adjacent range compaction round to make sure non
346 * collapsed input ranges are compacted in the result.
349 * @deprecated Provided for backward compatibility with the 1.7 API.
353 svn_rangelist_merge(svn_rangelist_t **rangelist,
354 const svn_rangelist_t *changes,
357 /** Removes @a eraser (the subtrahend) from @a whiteboard (the
358 * minuend), and places the resulting difference in @a output.
360 * Note: @a eraser and @a whiteboard must be sorted as said by @c
361 * svn_sort_compare_ranges(). @a output is guaranteed to be in sorted
364 * @a consider_inheritance determines how to account for the
365 * @c svn_merge_range_t inheritable field when comparing @a whiteboard's
366 * and @a *eraser's rangelists for equality. @see svn_mergeinfo_diff().
368 * Allocate the entire output in @a pool.
373 svn_rangelist_remove(svn_rangelist_t **output, const svn_rangelist_t *eraser,
374 const svn_rangelist_t *whiteboard,
375 svn_boolean_t consider_inheritance,
378 /** Find the intersection of two mergeinfos, @a mergeinfo1 and @a
379 * mergeinfo2, and place the result in @a *mergeinfo, which is (deeply)
380 * allocated in @a result_pool. Temporary allocations will be performed
381 * in @a scratch_pool.
383 * @a consider_inheritance determines how to account for the inheritability
384 * of the two mergeinfo's ranges when calculating the range equivalence,
385 * @see svn_rangelist_intersect().
390 svn_mergeinfo_intersect2(svn_mergeinfo_t *mergeinfo,
391 svn_mergeinfo_t mergeinfo1,
392 svn_mergeinfo_t mergeinfo2,
393 svn_boolean_t consider_inheritance,
394 apr_pool_t *result_pool,
395 apr_pool_t *scratch_pool);
397 /** Like svn_mergeinfo_intersect2, but always considers inheritance.
399 * @deprecated Provided for backward compatibility with the 1.6 API.
403 svn_mergeinfo_intersect(svn_mergeinfo_t *mergeinfo,
404 svn_mergeinfo_t mergeinfo1,
405 svn_mergeinfo_t mergeinfo2,
408 /** Find the intersection of two rangelists consisting of @c
409 * svn_merge_range_t * elements, @a rangelist1 and @a rangelist2, and
410 * place the result in @a *rangelist (which is never @c NULL).
412 * @a consider_inheritance determines how to account for the inheritability
413 * of the two rangelist's ranges when calculating the intersection,
414 * @see svn_mergeinfo_diff(). If @a consider_inheritance is FALSE then
415 * ranges with different inheritance can intersect, but the resulting
416 * @a *rangelist is non-inheritable only if the corresponding ranges from
417 * both @a rangelist1 and @a rangelist2 are non-inheritable.
418 * If @a consider_inheritance is TRUE, then ranges with different
419 * inheritance can never intersect.
421 * Note: @a rangelist1 and @a rangelist2 must be sorted as said by @c
422 * svn_sort_compare_ranges(). @a *rangelist is guaranteed to be in sorted
425 * Allocate the entire output in @a pool.
430 svn_rangelist_intersect(svn_rangelist_t **rangelist,
431 const svn_rangelist_t *rangelist1,
432 const svn_rangelist_t *rangelist2,
433 svn_boolean_t consider_inheritance,
436 /** Reverse @a rangelist, and the @c start and @c end fields of each
437 * range in @a rangelist, in place.
439 * TODO(miapi): Is this really a valid function? Rangelists that
440 * aren't sorted, or rangelists containing reverse ranges, are
441 * generally not valid in mergeinfo code. Can we rewrite the two
442 * places where this is used?
447 svn_rangelist_reverse(svn_rangelist_t *rangelist, apr_pool_t *pool);
449 /** Take an array of svn_merge_range_t *'s in @a rangelist, and convert it
450 * back to a text format rangelist in @a output. If @a rangelist contains
451 * no elements, sets @a output to the empty string.
456 svn_rangelist_to_string(svn_string_t **output,
457 const svn_rangelist_t *rangelist,
460 /** Remove non-inheritable or inheritable revision ranges from a rangelist.
462 * Set @a *inheritable_rangelist to a deep copy of @a rangelist, excluding
463 * all non-inheritable @c svn_merge_range_t if @a inheritable is TRUE or
464 * excluding all inheritable @c svn_merge_range_t otherwise.
466 * If @a start and @a end are valid revisions and @a start is less than or
467 * equal to @a end, then exclude only the (non-inheritable or inheritable)
468 * revision ranges that intersect inclusively with the range defined by
469 * @a start and @a end.
471 * If there are no remaining ranges, return an empty array.
473 * Allocate the copy in @a result_pool, and use @a scratch_pool for
474 * temporary allocations.
479 svn_rangelist_inheritable2(svn_rangelist_t **inheritable_rangelist,
480 const svn_rangelist_t *rangelist,
483 svn_boolean_t inheritable,
484 apr_pool_t *result_pool,
485 apr_pool_t *scratch_pool);
487 /** Like svn_rangelist_inheritable2, but always finds inheritable ranges.
490 * @deprecated Provided for backward compatibility with the 1.6 API.
494 svn_rangelist_inheritable(svn_rangelist_t **inheritable_rangelist,
495 const svn_rangelist_t *rangelist,
500 /** Remove non-inheritable or inheritable revision ranges from mergeinfo.
502 * Set @a *inheritable_mergeinfo to a deep copy of @a mergeinfo, excluding
503 * all non-inheritable @c svn_merge_range_t if @a inheritable is TRUE or
504 * excluding all inheritable @c svn_merge_range_t otherwise.
506 * If @a start and @a end are valid revisions and @a start is less than or
507 * equal to @a end, then exclude only the (non-inheritable or inheritable)
508 * revisions that intersect inclusively with the range defined by @a start
511 * If @a path is not NULL remove (non-inheritable or inheritable) ranges
514 * If all ranges are removed for a given path then remove that path as well.
515 * If @a mergeinfo is initially empty or all paths are removed from it then
516 * set @a *inheritable_mergeinfo to an empty mergeinfo.
518 * Allocate the copy in @a result_pool, and use @a scratch_pool for
519 * temporary allocations.
524 svn_mergeinfo_inheritable2(svn_mergeinfo_t *inheritable_mergeinfo,
525 svn_mergeinfo_t mergeinfo,
529 svn_boolean_t inheritable,
530 apr_pool_t *result_pool,
531 apr_pool_t *scratch_pool);
533 /** Like svn_mergeinfo_inheritable2, but always finds inheritable mergeinfo.
536 * @deprecated Provided for backward compatibility with the 1.6 API.
540 svn_mergeinfo_inheritable(svn_mergeinfo_t *inheritable_mergeinfo,
541 svn_mergeinfo_t mergeinfo,
547 /** Take a mergeinfo in @a mergeinput, and convert it to unparsed
548 * mergeinfo. Set @a *output to the result, allocated in @a pool.
549 * If @a input contains no elements, set @a *output to the empty string.
551 * @a mergeinput may contain relative merge source paths, but these are
552 * converted to absolute paths in @a *output.
557 svn_mergeinfo_to_string(svn_string_t **output,
558 svn_mergeinfo_t mergeinput,
561 /** Take a hash of mergeinfo in @a mergeinfo, and sort the rangelists
562 * associated with each key (in place).
564 * TODO(miapi): mergeinfos should *always* be sorted. This should be
565 * a private function.
570 svn_mergeinfo_sort(svn_mergeinfo_t mergeinfo, apr_pool_t *pool);
572 /** Return a deep copy of @a mergeinfo_catalog, allocated in @a pool.
576 svn_mergeinfo_catalog_t
577 svn_mergeinfo_catalog_dup(svn_mergeinfo_catalog_t mergeinfo_catalog,
580 /** Return a deep copy of @a mergeinfo, allocated in @a pool.
585 svn_mergeinfo_dup(svn_mergeinfo_t mergeinfo, apr_pool_t *pool);
587 /** Return a deep copy of @a rangelist, allocated in @a pool.
592 svn_rangelist_dup(const svn_rangelist_t *rangelist, apr_pool_t *pool);
596 * The three ways to request mergeinfo affecting a given path.
600 typedef enum svn_mergeinfo_inheritance_t
602 /** Explicit mergeinfo only. */
603 svn_mergeinfo_explicit,
605 /** Explicit mergeinfo, or if that doesn't exist, the inherited
606 mergeinfo from a target's nearest (path-wise, not history-wise)
608 svn_mergeinfo_inherited,
610 /** Mergeinfo inherited from a target's nearest (path-wise, not
611 history-wise) ancestor, regardless of whether target has explicit
613 svn_mergeinfo_nearest_ancestor
614 } svn_mergeinfo_inheritance_t;
616 /** Return a constant string expressing @a inherit as an English word,
617 * i.e., "explicit" (default), "inherited", or "nearest_ancestor".
618 * The string is not localized, as it may be used for client<->server
624 svn_inheritance_to_word(svn_mergeinfo_inheritance_t inherit);
627 /** Return the appropriate @c svn_mergeinfo_inheritance_t for @a word.
628 * @a word is as returned from svn_inheritance_to_word(). Defaults to
629 * @c svn_mergeinfo_explicit.
633 svn_mergeinfo_inheritance_t
634 svn_inheritance_from_word(const char *word);
639 #endif /* __cplusplus */
641 #endif /* SVN_MERGEINFO_H */