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". An array of non-
117 * overlapping merge ranges (@c svn_merge_range_t *), sorted as said by
118 * @c svn_sort_compare_ranges(). An empty range list is represented by
119 * an empty array. Unless specifically noted otherwise, all APIs require
120 * rangelists that describe only forward ranges, i.e. the range's start
121 * revision is less than its end revision.
123 * (c) @c svn_mergeinfo_t, called "mergeinfo". A hash mapping merge
124 * source paths (@c const char *, starting with slashes) to
125 * non-empty rangelist arrays. A @c NULL hash is used to represent
126 * no mergeinfo and an empty hash is used to represent empty
129 * (d) @c svn_mergeinfo_catalog_t, called a "mergeinfo catalog". A hash
130 * mapping paths (@c const char *) to @c svn_mergeinfo_t.
132 * Both @c svn_mergeinfo_t and @c svn_mergeinfo_catalog_t are just
133 * typedefs for @c apr_hash_t *; there is no static type-checking, and
134 * you still use standard @c apr_hash_t functions to interact with
137 * Note that while the keys of mergeinfos are always absolute from the
138 * repository root, the keys of a catalog may be relative to something
139 * else, such as an RA session root.
142 typedef apr_array_header_t svn_rangelist_t
;
143 typedef apr_hash_t
*svn_mergeinfo_t
;
144 typedef apr_hash_t
*svn_mergeinfo_catalog_t
;
146 /** Parse the mergeinfo from @a input into @a *mergeinfo. If no
147 * mergeinfo is available, return an empty mergeinfo (never @c NULL).
148 * Perform temporary allocations in @a pool.
150 * If @a input is not a grammatically correct @c SVN_PROP_MERGEINFO
151 * property, contains overlapping revision ranges of differing
152 * inheritability, or revision ranges with a start revision greater
153 * than or equal to its end revision, or contains paths mapped to empty
154 * revision ranges, then return @c SVN_ERR_MERGEINFO_PARSE_ERROR.
155 * Unordered revision ranges are allowed, but will be sorted when
156 * placed into @a *mergeinfo. Overlapping revision ranges of the same
157 * inheritability are also allowed, but will be combined into a single
158 * range when placed into @a *mergeinfo.
160 * @a input may contain relative merge source paths, but these are
161 * converted to absolute paths in @a *mergeinfo.
166 svn_mergeinfo_parse(svn_mergeinfo_t
*mergeinfo
, const char *input
,
169 /** Calculate the delta between two mergeinfos, @a mergefrom and @a mergeto
170 * (either or both of which may be @c NULL meaning an empty mergeinfo).
171 * Place the result in @a *deleted and @a *added (neither output argument
172 * may be @c NULL), both allocated in @a result_pool. The resulting
173 * @a *deleted and @a *added will not be null.
175 * @a consider_inheritance determines how the rangelists in the two
176 * hashes are compared for equality. If @a consider_inheritance is FALSE,
177 * then the start and end revisions of the @c svn_merge_range_t's being
178 * compared are the only factors considered when determining equality.
180 * e.g. '/trunk: 1,3-4*,5' == '/trunk: 1,3-5'
182 * If @a consider_inheritance is TRUE, then the inheritability of the
183 * @c svn_merge_range_t's is also considered and must be the same for two
184 * otherwise identical ranges to be judged equal.
186 * e.g. '/trunk: 1,3-4*,5' != '/trunk: 1,3-5'
187 * '/trunk: 1,3-4*,5' == '/trunk: 1,3-4*,5'
188 * '/trunk: 1,3-4,5' == '/trunk: 1,3-4,5'
193 svn_mergeinfo_diff2(svn_mergeinfo_t
*deleted
, svn_mergeinfo_t
*added
,
194 svn_mergeinfo_t mergefrom
, svn_mergeinfo_t mergeto
,
195 svn_boolean_t consider_inheritance
,
196 apr_pool_t
*result_pool
,
197 apr_pool_t
*scratch_pool
);
199 /** Similar to svn_mergeinfo_diff2(), but users only one pool.
201 * @deprecated Provided for backward compatibility with the 1.7 API.
206 svn_mergeinfo_diff(svn_mergeinfo_t
*deleted
, svn_mergeinfo_t
*added
,
207 svn_mergeinfo_t mergefrom
, svn_mergeinfo_t mergeto
,
208 svn_boolean_t consider_inheritance
,
211 /** Merge a shallow copy of one mergeinfo, @a changes, into another mergeinfo
214 * Rangelists for merge source paths common to @a changes and @a mergeinfo may
215 * result in new rangelists; these are allocated in @a result_pool.
216 * Temporary allocations are made in @a scratch_pool.
218 * When intersecting rangelists for a path are merged, the inheritability of
219 * the resulting svn_merge_range_t depends on the inheritability of the
220 * operands. If two non-inheritable ranges are merged the result is always
221 * non-inheritable, in all other cases the resulting range is inheritable.
223 * e.g. '/A: 1,3-4' merged with '/A: 1,3,4*,5' --> '/A: 1,3-5'
224 * '/A: 1,3-4*' merged with '/A: 1,3,4*,5' --> '/A: 1,3,4*,5'
229 svn_mergeinfo_merge2(svn_mergeinfo_t mergeinfo
,
230 svn_mergeinfo_t changes
,
231 apr_pool_t
*result_pool
,
232 apr_pool_t
*scratch_pool
);
234 /** Like svn_mergeinfo_merge2, but uses only one pool.
236 * @deprecated Provided for backward compatibility with the 1.5 API.
240 svn_mergeinfo_merge(svn_mergeinfo_t mergeinfo
,
241 svn_mergeinfo_t changes
,
244 /** Combine one mergeinfo catalog, @a changes_catalog, into another mergeinfo
245 * catalog @a mergeinfo_catalog. If both catalogs have mergeinfo for the same
246 * key, use svn_mergeinfo_merge() to combine the mergeinfos.
248 * Additions to @a mergeinfo_catalog are deep copies allocated in
249 * @a result_pool. Temporary allocations are made in @a scratch_pool.
254 svn_mergeinfo_catalog_merge(svn_mergeinfo_catalog_t mergeinfo_catalog
,
255 svn_mergeinfo_catalog_t changes_catalog
,
256 apr_pool_t
*result_pool
,
257 apr_pool_t
*scratch_pool
);
259 /** Like svn_mergeinfo_remove2, but always considers inheritance.
261 * @deprecated Provided for backward compatibility with the 1.6 API.
265 svn_mergeinfo_remove(svn_mergeinfo_t
*mergeinfo
, svn_mergeinfo_t eraser
,
266 svn_mergeinfo_t whiteboard
, apr_pool_t
*pool
);
268 /** Removes @a eraser (the subtrahend) from @a whiteboard (the
269 * minuend), and places the resulting difference in @a *mergeinfo.
270 * Allocates @a *mergeinfo in @a result_pool. Temporary allocations
271 * will be performed in @a scratch_pool.
273 * @a consider_inheritance determines how to account for the inheritability
274 * of the two mergeinfo's ranges when calculating the range equivalence,
275 * as described for svn_mergeinfo_diff().
280 svn_mergeinfo_remove2(svn_mergeinfo_t
*mergeinfo
,
281 svn_mergeinfo_t eraser
,
282 svn_mergeinfo_t whiteboard
,
283 svn_boolean_t consider_inheritance
,
284 apr_pool_t
*result_pool
,
285 apr_pool_t
*scratch_pool
);
287 /** Calculate the delta between two rangelists consisting of @c
288 * svn_merge_range_t * elements (sorted in ascending order), @a from
289 * and @a to, and place the result in @a *deleted and @a *added
290 * (neither output argument will ever be @c NULL).
292 * @a consider_inheritance determines how to account for the inheritability
293 * of the two rangelist's ranges when calculating the diff,
294 * as described for svn_mergeinfo_diff().
299 svn_rangelist_diff(svn_rangelist_t
**deleted
, svn_rangelist_t
**added
,
300 const svn_rangelist_t
*from
, const svn_rangelist_t
*to
,
301 svn_boolean_t consider_inheritance
,
304 /** Merge two rangelists consisting of @c svn_merge_range_t *
305 * elements, @a rangelist and @a changes, placing the results in
306 * @a rangelist. New elements added to @a rangelist are allocated
307 * in @a result_pool. Either rangelist may be empty.
309 * When intersecting rangelists are merged, the inheritability of
310 * the resulting svn_merge_range_t depends on the inheritability of the
311 * operands: see svn_mergeinfo_merge().
313 * Note: @a rangelist and @a changes must be sorted as said by @c
314 * svn_sort_compare_ranges(). @a rangelist is guaranteed to remain
315 * in sorted order and be compacted to the minimal number of ranges
316 * needed to represent the merged result.
318 * If the original rangelist contains non-collapsed adjacent ranges,
319 * the final result is not guaranteed to be compacted either.
321 * Use @a scratch_pool for temporary allocations.
326 svn_rangelist_merge2(svn_rangelist_t
*rangelist
,
327 const svn_rangelist_t
*changes
,
328 apr_pool_t
*result_pool
,
329 apr_pool_t
*scratch_pool
);
331 /** Like svn_rangelist_merge2(), but with @a rangelist as an input/output
332 * argument. This function always allocates a new rangelist in @a pool and
333 * returns its result in @a *rangelist. It does not modify @a *rangelist
334 * in place. If not used carefully, this function can use up a lot of memory
335 * if called in a loop.
337 * It performs an extra adjacent range compaction round to make sure non
338 * collapsed input ranges are compacted in the result.
341 * @deprecated Provided for backward compatibility with the 1.7 API.
345 svn_rangelist_merge(svn_rangelist_t
**rangelist
,
346 const svn_rangelist_t
*changes
,
349 /** Removes @a eraser (the subtrahend) from @a whiteboard (the
350 * minuend), and places the resulting difference in @a output.
352 * Note: @a eraser and @a whiteboard must be sorted as said by @c
353 * svn_sort_compare_ranges(). @a output is guaranteed to be in sorted
356 * @a consider_inheritance determines how to account for the
357 * @c svn_merge_range_t inheritable field when comparing @a whiteboard's
358 * and @a *eraser's rangelists for equality. @see svn_mergeinfo_diff().
363 svn_rangelist_remove(svn_rangelist_t
**output
, const svn_rangelist_t
*eraser
,
364 const svn_rangelist_t
*whiteboard
,
365 svn_boolean_t consider_inheritance
,
368 /** Find the intersection of two mergeinfos, @a mergeinfo1 and @a
369 * mergeinfo2, and place the result in @a *mergeinfo, which is (deeply)
370 * allocated in @a result_pool. Temporary allocations will be performed
371 * in @a scratch_pool.
373 * @a consider_inheritance determines how to account for the inheritability
374 * of the two mergeinfo's ranges when calculating the range equivalence,
375 * @see svn_rangelist_intersect().
380 svn_mergeinfo_intersect2(svn_mergeinfo_t
*mergeinfo
,
381 svn_mergeinfo_t mergeinfo1
,
382 svn_mergeinfo_t mergeinfo2
,
383 svn_boolean_t consider_inheritance
,
384 apr_pool_t
*result_pool
,
385 apr_pool_t
*scratch_pool
);
387 /** Like svn_mergeinfo_intersect2, but always considers inheritance.
389 * @deprecated Provided for backward compatibility with the 1.6 API.
393 svn_mergeinfo_intersect(svn_mergeinfo_t
*mergeinfo
,
394 svn_mergeinfo_t mergeinfo1
,
395 svn_mergeinfo_t mergeinfo2
,
398 /** Find the intersection of two rangelists consisting of @c
399 * svn_merge_range_t * elements, @a rangelist1 and @a rangelist2, and
400 * place the result in @a *rangelist (which is never @c NULL).
402 * @a consider_inheritance determines how to account for the inheritability
403 * of the two rangelist's ranges when calculating the intersection,
404 * @see svn_mergeinfo_diff(). If @a consider_inheritance is FALSE then
405 * ranges with different inheritance can intersect, but the resulting
406 * @a *rangelist is non-inheritable only if the corresponding ranges from
407 * both @a rangelist1 and @a rangelist2 are non-inheritable.
408 * If @a consider_inheritance is TRUE, then ranges with different
409 * inheritance can never intersect.
411 * Note: @a rangelist1 and @a rangelist2 must be sorted as said by @c
412 * svn_sort_compare_ranges(). @a *rangelist is guaranteed to be in sorted
417 svn_rangelist_intersect(svn_rangelist_t
**rangelist
,
418 const svn_rangelist_t
*rangelist1
,
419 const svn_rangelist_t
*rangelist2
,
420 svn_boolean_t consider_inheritance
,
423 /** Reverse @a rangelist, and the @c start and @c end fields of each
424 * range in @a rangelist, in place.
426 * TODO(miapi): Is this really a valid function? Rangelists that
427 * aren't sorted, or rangelists containing reverse ranges, are
428 * generally not valid in mergeinfo code. Can we rewrite the two
429 * places where this is used?
434 svn_rangelist_reverse(svn_rangelist_t
*rangelist
, apr_pool_t
*pool
);
436 /** Take an array of svn_merge_range_t *'s in @a rangelist, and convert it
437 * back to a text format rangelist in @a output. If @a rangelist contains
438 * no elements, sets @a output to the empty string.
443 svn_rangelist_to_string(svn_string_t
**output
,
444 const svn_rangelist_t
*rangelist
,
447 /** Return a deep copy of @c svn_merge_range_t *'s in @a rangelist excluding
448 * all non-inheritable @c svn_merge_range_t if @a inheritable is TRUE or
449 * excluding all inheritable @c svn_merge_range_t otherwise. If @a start and
450 * @a end are valid revisions and @a start is less than or equal to @a end,
451 * then exclude only the non-inheritable revision ranges that intersect
452 * inclusively with the range defined by @a start and @a end. If
453 * @a rangelist contains no elements, return an empty array. Allocate the
454 * copy in @a result_pool, use @a scratch_pool for temporary allocations.
459 svn_rangelist_inheritable2(svn_rangelist_t
**inheritable_rangelist
,
460 const svn_rangelist_t
*rangelist
,
463 svn_boolean_t inheritable
,
464 apr_pool_t
*result_pool
,
465 apr_pool_t
*scratch_pool
);
467 /** Like svn_rangelist_inheritable2, but always finds inheritable ranges.
470 * @deprecated Provided for backward compatibility with the 1.6 API.
474 svn_rangelist_inheritable(svn_rangelist_t
**inheritable_rangelist
,
475 const svn_rangelist_t
*rangelist
,
480 /** Return a deep copy of @a mergeinfo, excluding all non-inheritable
481 * @c svn_merge_range_t if @a inheritable is TRUE or excluding all
482 * inheritable @c svn_merge_range_t otherwise. If @a start and @a end
483 * are valid revisions and @a start is less than or equal to @a end,
484 * then exclude only the non-inheritable revisions that intersect
485 * inclusively with the range defined by @a start and @a end. If @a path
486 * is not NULL remove non-inheritable ranges only for @a path. If all
487 * ranges are removed for a given path then remove that path as well.
488 * If all paths are removed or @a rangelist is empty then set
489 * @a *inheritable_rangelist to an empty array. Allocate the copy in
490 * @a result_pool, use @a scratch_pool for temporary allocations.
495 svn_mergeinfo_inheritable2(svn_mergeinfo_t
*inheritable_mergeinfo
,
496 svn_mergeinfo_t mergeinfo
,
500 svn_boolean_t inheritable
,
501 apr_pool_t
*result_pool
,
502 apr_pool_t
*scratch_pool
);
504 /** Like svn_mergeinfo_inheritable2, but always finds inheritable mergeinfo.
507 * @deprecated Provided for backward compatibility with the 1.6 API.
511 svn_mergeinfo_inheritable(svn_mergeinfo_t
*inheritable_mergeinfo
,
512 svn_mergeinfo_t mergeinfo
,
518 /** Take a mergeinfo in @a mergeinput, and convert it to unparsed
519 * mergeinfo. Set @a *output to the result, allocated in @a pool.
520 * If @a input contains no elements, set @a *output to the empty string.
522 * @a mergeinput may contain relative merge source paths, but these are
523 * converted to absolute paths in @a *output.
528 svn_mergeinfo_to_string(svn_string_t
**output
,
529 svn_mergeinfo_t mergeinput
,
532 /** Take a hash of mergeinfo in @a mergeinfo, and sort the rangelists
533 * associated with each key (in place).
535 * TODO(miapi): mergeinfos should *always* be sorted. This should be
536 * a private function.
541 svn_mergeinfo_sort(svn_mergeinfo_t mergeinfo
, apr_pool_t
*pool
);
543 /** Return a deep copy of @a mergeinfo_catalog, allocated in @a pool.
547 svn_mergeinfo_catalog_t
548 svn_mergeinfo_catalog_dup(svn_mergeinfo_catalog_t mergeinfo_catalog
,
551 /** Return a deep copy of @a mergeinfo, allocated in @a pool.
556 svn_mergeinfo_dup(svn_mergeinfo_t mergeinfo
, apr_pool_t
*pool
);
558 /** Return a deep copy of @a rangelist, allocated in @a pool.
563 svn_rangelist_dup(const svn_rangelist_t
*rangelist
, apr_pool_t
*pool
);
567 * The three ways to request mergeinfo affecting a given path.
571 typedef enum svn_mergeinfo_inheritance_t
573 /** Explicit mergeinfo only. */
574 svn_mergeinfo_explicit
,
576 /** Explicit mergeinfo, or if that doesn't exist, the inherited
577 mergeinfo from a target's nearest (path-wise, not history-wise)
579 svn_mergeinfo_inherited
,
581 /** Mergeinfo inherited from a target's nearest (path-wise, not
582 history-wise) ancestor, regardless of whether target has explicit
584 svn_mergeinfo_nearest_ancestor
585 } svn_mergeinfo_inheritance_t
;
587 /** Return a constant string expressing @a inherit as an English word,
588 * i.e., "explicit" (default), "inherited", or "nearest_ancestor".
589 * The string is not localized, as it may be used for client<->server
595 svn_inheritance_to_word(svn_mergeinfo_inheritance_t inherit
);
598 /** Return the appropriate @c svn_mergeinfo_inheritance_t for @a word.
599 * @a word is as returned from svn_inheritance_to_word(). Defaults to
600 * @c svn_mergeinfo_explicit.
604 svn_mergeinfo_inheritance_t
605 svn_inheritance_from_word(const char *word
);
610 #endif /* __cplusplus */
612 #endif /* SVN_MERGEINFO_H */