00001 /** 00002 * @copyright 00003 * ==================================================================== 00004 * Copyright (c) 2006-2008 CollabNet. All rights reserved. 00005 * 00006 * This software is licensed as described in the file COPYING, which 00007 * you should have received as part of this distribution. The terms 00008 * are also available at http://subversion.tigris.org/license-1.html. 00009 * If newer versions of this license are posted there, you may use a 00010 * newer version instead, at your option. 00011 * 00012 * This software consists of voluntary contributions made by many 00013 * individuals. For exact contribution history, see the revision 00014 * history and logs, available at http://subversion.tigris.org/. 00015 * ==================================================================== 00016 * @endcopyright 00017 * 00018 * @file svn_mergeinfo.h 00019 * @brief mergeinfo handling and processing 00020 */ 00021 00022 00023 #ifndef SVN_MERGEINFO_H 00024 #define SVN_MERGEINFO_H 00025 00026 #include <apr_pools.h> 00027 #include <apr_tables.h> /* for apr_array_header_t */ 00028 #include <apr_hash.h> 00029 00030 #include "svn_error.h" 00031 00032 00033 #ifdef __cplusplus 00034 extern "C" { 00035 #endif /* __cplusplus */ 00036 00037 /** Overview of the @c SVN_PROP_MERGEINFO property. 00038 * 00039 * Merge history is stored in the @c SVN_PROP_MERGEINFO property of files 00040 * and directories. The @c SVN_PROP_MERGEINFO property on a path stores the 00041 * complete list of changes merged to that path, either directly or via the 00042 * path's parent, grand-parent, etc.. A path may have empty mergeinfo which 00043 * means that nothing has been merged to that path or all previous merges 00044 * to the path were reversed. Note that a path may have no mergeinfo, this 00045 * is not the same as empty mergeinfo. 00046 * 00047 * Every path in a tree may have @c SVN_PROP_MERGEINFO set, but if the 00048 * @c SVN_PROP_MERGEINFO for a path is equivalent to the 00049 * @c SVN_PROP_MERGEINFO for its parent, then the @c SVN_PROP_MERGEINFO on 00050 * the path will 'elide' (be removed) from the path as a post step to any 00051 * merge. If a path's parent does not have any @c SVN_PROP_MERGEINFO set, 00052 * the path's mergeinfo can elide to its nearest grand-parent, 00053 * great-grand-parent, etc. that has equivalent @c SVN_PROP_MERGEINFO set 00054 * on it. 00055 * 00056 * If a path has no @c SVN_PROP_MERGEINFO of its own, it inherits mergeinfo 00057 * from its nearest parent that has @c SVN_PROP_MERGEINFO set. The 00058 * exception to this is @c SVN_PROP_MERGEINFO with non-ineritable revision 00059 * ranges. These non-inheritable ranges apply only to the path which they 00060 * are set on. 00061 * 00062 * Due to Subversion's allowance for mixed revision working copies, both 00063 * elision and inheritance within the working copy presume the path 00064 * between a path and its nearest parent with mergeinfo is at the same 00065 * working revision. If this is not the case then neither inheritance nor 00066 * elision can occur. 00067 * 00068 * The value of the @c SVN_PROP_MERGEINFO property is either an empty string 00069 * (representing empty mergeinfo) or a non-empty string consisting of 00070 * a path, a colon, and comma separated revision list, containing one or more 00071 * revision or revision ranges. Revision range start and end points are 00072 * separated by "-". Revisions and revision ranges may have the optional 00073 * @c SVN_MERGEINFO_NONINHERITABLE_STR suffix to signify a non-inheritable 00074 * revision/revision range. 00075 * 00076 * @c SVN_PROP_MERGEINFO Value Grammar: 00077 * 00078 * Token Definition 00079 * ----- ---------- 00080 * revisionrange REVISION1 "-" REVISION2 00081 * revisioneelement (revisionrange | REVISION)"*"? 00082 * rangelist revisioneelement (COMMA revisioneelement)* 00083 * revisionline PATHNAME COLON rangelist 00084 * top "" | (revisionline (NEWLINE revisionline))* 00085 * 00086 * The PATHNAME is the source of a merge and the rangelist the revision(s) 00087 * merged to the path @c SVN_PROP_MERGEINFO is set on directly or indirectly 00088 * via inheritance. PATHNAME must always exist at the specified rangelist 00089 * and thus a single merge may result in multiple revisionlines if the source 00090 * was renamed. 00091 * 00092 * Rangelists must be sorted from lowest to highest revision and cannot 00093 * contain overlapping revisionlistelements. REVISION1 must be less than 00094 * REVISION2. Consecutive single revisions that can be represented by a 00095 * revisionrange are allowed however (e.g. '5,6,7,8,9-12' or '5-12' are 00096 * both acceptable). 00097 */ 00098 00099 /* Suffix for SVN_PROP_MERGEINFO revision ranges indicating a given 00100 range is non-inheritable. */ 00101 #define SVN_MERGEINFO_NONINHERITABLE_STR "*" 00102 00103 /** Terminology for data structures that contain mergeinfo. 00104 * 00105 * Subversion commonly uses several data structures to represent 00106 * mergeinfo in RAM: 00107 * 00108 * (a) Strings (@c svn_string_t *) containing "unparsed mergeinfo". 00109 * 00110 * (b) Hashes mapping merge source paths (@c const char *, starting 00111 * with slashes) to non-empty arrays (@c apr_array_header_t *) of 00112 * merge ranges (@c svn_merge_range_t *), ordered from smallest 00113 * revision range to largest. These hashes are called "mergeinfo" 00114 * and are represented by @c svn_mergeinfo_t. The sorted arrays 00115 * are called "rangelists". A @c NULL hash is used to represent 00116 * no mergeinfo and an empty hash is used to represent empty 00117 * mergeinfo. 00118 * 00119 * (c) Hashes mapping paths (@c const char *, starting with slashes) 00120 * to @c svn_mergeinfo_t. These hashes are called "mergeinfo 00121 * catalogs" and are represented by @c svn_mergeinfo_catalog_t. 00122 * 00123 * Both @c svn_mergeinfo_t and @c svn_mergeinfo_catalog_t are just 00124 * typedefs for @c apr_hash_t *; there is no static type-checking, and 00125 * you still use standard @c apr_hash_t functions to interact with 00126 * them. 00127 * 00128 * Note that while the keys of mergeinfos are always relative to the 00129 * repository root, the keys of a catalog may be relative to something 00130 * else, such as an RA session root. 00131 */ 00132 00133 typedef apr_hash_t *svn_mergeinfo_t; 00134 typedef apr_hash_t *svn_mergeinfo_catalog_t; 00135 00136 /** Parse the mergeinfo from @a input into @a *mergeinfo. If no 00137 * mergeinfo is available, return an empty mergeinfo (never @c NULL). 00138 * Perform temporary allocations in @a pool. 00139 * 00140 * If @a input is not a grammatically correct @c SVN_PROP_MERGEINFO 00141 * property, contains overlapping revision ranges of differing 00142 * inheritability, or revision ranges with a start revision greater 00143 * than or equal to its end revision, or contains paths mapped to empty 00144 * revision ranges, then return @c SVN_ERR_MERGEINFO_PARSE_ERROR. 00145 * Unordered revision ranges are allowed, but will be sorted when 00146 * placed into @a *mergeinfo. Overlapping revision ranges of the same 00147 * inheritability are also allowed, but will be combined into a single 00148 * range when placed into @a *mergeinfo. 00149 * 00150 * @since New in 1.5. 00151 */ 00152 svn_error_t * 00153 svn_mergeinfo_parse(svn_mergeinfo_t *mergeinfo, const char *input, 00154 apr_pool_t *pool); 00155 00156 /** Calculate the delta between two mergeinfos, @a mergefrom and @a mergeto 00157 * (which may be @c NULL), and place the result in @a *deleted and @a 00158 * *added (neither output argument may be @c NULL). 00159 * 00160 * @a consider_inheritance determines how the rangelists in the two 00161 * hashes are compared for equality. If @a consider_inheritance is FALSE, 00162 * then the start and end revisions of the @c svn_merge_range_t's being 00163 * compared are the only factors considered when determining equality. 00164 * 00165 * e.g. '/trunk: 1,3-4*,5' == '/trunk: 1,3-5' 00166 * 00167 * If @a consider_inheritance is TRUE, then the inheritability of the 00168 * @c svn_merge_range_t's is also considered and must be the same for two 00169 * otherwise identical ranges to be judged equal. 00170 * 00171 * e.g. '/trunk: 1,3-4*,5' != '/trunk: 1,3-5' 00172 * '/trunk: 1,3-4*,5' == '/trunk: 1,3-4*,5' 00173 * '/trunk: 1,3-4,5' == '/trunk: 1,3-4,5' 00174 * 00175 * @since New in 1.5. 00176 */ 00177 svn_error_t * 00178 svn_mergeinfo_diff(svn_mergeinfo_t *deleted, svn_mergeinfo_t *added, 00179 svn_mergeinfo_t mergefrom, svn_mergeinfo_t mergeto, 00180 svn_boolean_t consider_inheritance, 00181 apr_pool_t *pool); 00182 00183 /** Merge one mergeinfo, @a changes, into another mergeinfo @a 00184 * mergeinfo. 00185 * 00186 * When intersecting rangelists for a path are merged, the inheritability of 00187 * the resulting svn_merge_range_t depends on the inheritability of the 00188 * operands. If two non-inheritable ranges are merged the result is always 00189 * non-inheritable, in all other cases the resulting range is inheritable. 00190 * 00191 * e.g. '/A: 1,3-4' merged with '/A: 1,3,4*,5' --> '/A: 1,3-5' 00192 * '/A: 1,3-4*' merged with '/A: 1,3,4*,5' --> '/A: 1,3,4*,5' 00193 * 00194 * @since New in 1.5. 00195 */ 00196 svn_error_t * 00197 svn_mergeinfo_merge(svn_mergeinfo_t mergeinfo, svn_mergeinfo_t changes, 00198 apr_pool_t *pool); 00199 00200 /** Removes @a eraser (the subtrahend) from @a whiteboard (the 00201 * minuend), and places the resulting difference in @a *mergeinfo. 00202 * 00203 * @since New in 1.5. 00204 */ 00205 svn_error_t * 00206 svn_mergeinfo_remove(svn_mergeinfo_t *mergeinfo, svn_mergeinfo_t eraser, 00207 svn_mergeinfo_t whiteboard, apr_pool_t *pool); 00208 00209 /** Calculate the delta between two rangelists consisting of @c 00210 * svn_merge_range_t * elements (sorted in ascending order), @a from 00211 * and @a to, and place the result in @a deleted and @a added (neither 00212 * output argument will ever be @c NULL). 00213 * 00214 * @a consider_inheritance determines how to account for the inheritability 00215 * of the two rangelist's ranges when calculating the diff, 00216 * @see svn_mergeinfo_diff(). 00217 * 00218 * @since New in 1.5. 00219 */ 00220 svn_error_t * 00221 svn_rangelist_diff(apr_array_header_t **deleted, apr_array_header_t **added, 00222 apr_array_header_t *from, apr_array_header_t *to, 00223 svn_boolean_t consider_inheritance, 00224 apr_pool_t *pool); 00225 00226 /** Merge two rangelists consisting of @c svn_merge_range_t * 00227 * elements, @a *rangelist and @a changes, placing the results in 00228 * @a *rangelist. Either rangelist may be empty. 00229 * 00230 * When intersecting rangelists are merged, the inheritability of 00231 * the resulting svn_merge_range_t depends on the inheritability of the 00232 * operands, @see svn_mergeinfo_merge(). 00233 * 00234 * Note: @a *rangelist and @a changes must be sorted as said by @c 00235 * svn_sort_compare_ranges(). @a *rangelist is guaranteed to remain 00236 * in sorted order and be compacted to the minimal number of ranges 00237 * needed to represent the merged result. 00238 * 00239 * @since New in 1.5. 00240 */ 00241 svn_error_t * 00242 svn_rangelist_merge(apr_array_header_t **rangelist, 00243 apr_array_header_t *changes, 00244 apr_pool_t *pool); 00245 00246 /** Removes @a eraser (the subtrahend) from @a whiteboard (the 00247 * minuend), and places the resulting difference in @a output. 00248 * 00249 * Note: @a eraser and @a whiteboard must be sorted as said by @c 00250 * svn_sort_compare_ranges(). @a output is guaranteed to be in sorted 00251 * order. 00252 * 00253 * @a consider_inheritance determines how to account for the 00254 * @c svn_merge_range_t inheritable field when comparing @a whiteboard's 00255 * and @a *eraser's rangelists for equality. @See svn_mergeinfo_diff(). 00256 * 00257 * @since New in 1.5. 00258 */ 00259 svn_error_t * 00260 svn_rangelist_remove(apr_array_header_t **output, apr_array_header_t *eraser, 00261 apr_array_header_t *whiteboard, 00262 svn_boolean_t consider_inheritance, 00263 apr_pool_t *pool); 00264 00265 /** Find the intersection of two mergeinfos, @a mergeinfo1 and @a 00266 * mergeinfo2, and place the result in @a *mergeinfo, which is (deeply) 00267 * allocated in @a pool. 00268 * 00269 * @since New in 1.5. 00270 */ 00271 svn_error_t * 00272 svn_mergeinfo_intersect(svn_mergeinfo_t *mergeinfo, 00273 svn_mergeinfo_t mergeinfo1, 00274 svn_mergeinfo_t mergeinfo2, 00275 apr_pool_t *pool); 00276 00277 /** Find the intersection of two rangelists consisting of @c 00278 * svn_merge_range_t * elements, @a rangelist1 and @a rangelist2, and 00279 * place the result in @a *rangelist (which is never @c NULL). 00280 * 00281 * @a consider_inheritance determines how to account for the inheritability 00282 * of the two rangelist's ranges when calculating the intersection, 00283 * @see svn_mergeinfo_diff(). 00284 * 00285 * Note: @a rangelist1 and @a rangelist2 must be sorted as said by @c 00286 * svn_sort_compare_ranges(). @a *rangelist is guaranteed to be in sorted 00287 * order. 00288 * @since New in 1.5. 00289 */ 00290 svn_error_t * 00291 svn_rangelist_intersect(apr_array_header_t **rangelist, 00292 apr_array_header_t *rangelist1, 00293 apr_array_header_t *rangelist2, 00294 svn_boolean_t consider_inheritance, 00295 apr_pool_t *pool); 00296 00297 /** Reverse @a rangelist, and the @c start and @c end fields of each 00298 * range in @a rangelist, in place. 00299 * 00300 * TODO(miapi): Is this really a valid function? Rangelists that 00301 * aren't sorted, or rangelists containing reverse ranges, are 00302 * generally not valid in mergeinfo code. Can we rewrite the two 00303 * places where this is used? 00304 * 00305 * @since New in 1.5. 00306 */ 00307 svn_error_t * 00308 svn_rangelist_reverse(apr_array_header_t *rangelist, apr_pool_t *pool); 00309 00310 /** Take an array of svn_merge_range_t *'s in @a rangelist, and convert it 00311 * back to a text format rangelist in @a output. If @a rangelist contains 00312 * no elements, sets @a output to the empty string. 00313 * 00314 * @since New in 1.5. 00315 */ 00316 svn_error_t * 00317 svn_rangelist_to_string(svn_string_t **output, 00318 const apr_array_header_t *rangelist, 00319 apr_pool_t *pool); 00320 00321 /** Return a deep copy of @c svn_merge_range_t *'s in @a rangelist excluding 00322 * all non-inheritable @c svn_merge_range_t. If @a start and @a end are valid 00323 * revisions and @a start is less than or equal to @a end, then exclude only the 00324 * non-inheritable revision ranges that intersect inclusively with the range 00325 * defined by @a start and @a end. If @a rangelist contains no elements, return 00326 * an empty array. Allocate the copy in @a pool. 00327 * 00328 * @since New in 1.5. 00329 */ 00330 svn_error_t * 00331 svn_rangelist_inheritable(apr_array_header_t **inheritable_rangelist, 00332 apr_array_header_t *rangelist, 00333 svn_revnum_t start, 00334 svn_revnum_t end, 00335 apr_pool_t *pool); 00336 00337 /** Return a deep copy of @a mergeinfo, excluding all non-inheritable 00338 * @c svn_merge_range_t. If @a start and @a end are valid revisions 00339 * and @a start is less than or equal to @a end, then exclude only the 00340 * non-inheritable revisions that intersect inclusively with the range 00341 * defined by @a start and @a end. If @a path is not NULL remove 00342 * non-inheritable ranges only for @a path. If all ranges are removed 00343 * for a given path then remove that path as well. If all paths are 00344 * removed or @a rangelist is empty then set @a *inheritable_rangelist 00345 * to an empty array. Allocate the copy in @a pool. 00346 * 00347 * @since New in 1.5. 00348 */ 00349 svn_error_t * 00350 svn_mergeinfo_inheritable(svn_mergeinfo_t *inheritable_mergeinfo, 00351 svn_mergeinfo_t mergeinfo, 00352 const char *path, 00353 svn_revnum_t start, 00354 svn_revnum_t end, 00355 apr_pool_t *pool); 00356 00357 /** Take a mergeinfo in MERGEINPUT, and convert it back to unparsed 00358 * mergeinfo in *OUTPUT. If INPUT contains no elements, return the 00359 * empty string. 00360 * 00361 * @since New in 1.5. 00362 */ 00363 svn_error_t * 00364 svn_mergeinfo_to_string(svn_string_t **output, 00365 svn_mergeinfo_t mergeinput, 00366 apr_pool_t *pool); 00367 00368 /** Take a hash of mergeinfo in @a mergeinfo, and sort the rangelists 00369 * associated with each key (in place). 00370 * 00371 * TODO(miapi): mergeinfos should *always* be sorted. This should be 00372 * a private function. 00373 * 00374 * @since New in 1.5 00375 */ 00376 svn_error_t * 00377 svn_mergeinfo_sort(svn_mergeinfo_t mergeinfo, apr_pool_t *pool); 00378 00379 /** Return a deep copy of @a mergeinfo, allocated in @a pool. 00380 * 00381 * @since New in 1.5. 00382 */ 00383 svn_mergeinfo_t 00384 svn_mergeinfo_dup(svn_mergeinfo_t mergeinfo, apr_pool_t *pool); 00385 00386 /** Return a deep copy of @a rangelist, allocated in @a pool. 00387 * 00388 * @since New in 1.5. 00389 */ 00390 apr_array_header_t * 00391 svn_rangelist_dup(apr_array_header_t *rangelist, apr_pool_t *pool); 00392 00393 00394 /** 00395 * The three ways to request mergeinfo affecting a given path. 00396 * 00397 * @since New in 1.5. 00398 */ 00399 typedef enum 00400 { 00401 /** Explicit mergeinfo only. */ 00402 svn_mergeinfo_explicit, 00403 00404 /** Explicit mergeinfo, or if that doesn't exist, the inherited 00405 mergeinfo from a target's nearest (path-wise, not history-wise) 00406 ancestor. */ 00407 svn_mergeinfo_inherited, 00408 00409 /** Mergeinfo on target's nearest (path-wise, not history-wise) 00410 ancestor, regardless of whether target has explict mergeinfo. */ 00411 svn_mergeinfo_nearest_ancestor 00412 } svn_mergeinfo_inheritance_t; 00413 00414 /** Return a constant string expressing @a inherit as an English word, 00415 * i.e., "explicit" (default), "inherited", or "nearest_ancestor". 00416 * The string is not localized, as it may be used for client<->server 00417 * communications. 00418 * 00419 * @since New in 1.5. 00420 */ 00421 const char * 00422 svn_inheritance_to_word(svn_mergeinfo_inheritance_t inherit); 00423 00424 00425 /** Return the appropriate @c svn_mergeinfo_inheritance_t for @a word. 00426 * @a word is as returned from svn_inheritance_to_word(). Defaults to 00427 * @c svn_mergeinfo_explicit. 00428 * 00429 * @since New in 1.5. 00430 */ 00431 svn_mergeinfo_inheritance_t 00432 svn_inheritance_from_word(const char *word); 00433 00434 00435 #ifdef __cplusplus 00436 } 00437 #endif /* __cplusplus */ 00438 00439 #endif /* SVN_MERGEINFO_H */