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) A "rangelist". An array (@c apr_array_header_t *) of non-overlapping 00111 * merge ranges (@c svn_merge_range_t *), sorted as said by 00112 * @c svn_sort_compare_ranges(). An empty range list is represented by 00113 * an empty array. Unless specifically noted otherwise, all APIs require 00114 * rangelists that describe only forward ranges, i.e. the range's start 00115 * revision is less than its end revision. 00116 * 00117 * (c) @c svn_mergeinfo_t, called "mergeinfo". A hash mapping merge 00118 * source paths (@c const char *, starting with slashes) to 00119 * non-empty rangelist arrays. A @c NULL hash is used to represent 00120 * no mergeinfo and an empty hash is used to represent empty 00121 * mergeinfo. 00122 * 00123 * (d) @c svn_mergeinfo_catalog_t, called a "mergeinfo catalog". A hash 00124 * mapping paths (@c const char *, starting with slashes) to 00125 * @c svn_mergeinfo_t. 00126 * 00127 * Both @c svn_mergeinfo_t and @c svn_mergeinfo_catalog_t are just 00128 * typedefs for @c apr_hash_t *; there is no static type-checking, and 00129 * you still use standard @c apr_hash_t functions to interact with 00130 * them. 00131 * 00132 * Note that while the keys of mergeinfos are always relative to the 00133 * repository root, the keys of a catalog may be relative to something 00134 * else, such as an RA session root. 00135 */ 00136 00137 typedef apr_hash_t *svn_mergeinfo_t; 00138 typedef apr_hash_t *svn_mergeinfo_catalog_t; 00139 00140 /** Parse the mergeinfo from @a input into @a *mergeinfo. If no 00141 * mergeinfo is available, return an empty mergeinfo (never @c NULL). 00142 * Perform temporary allocations in @a pool. 00143 * 00144 * If @a input is not a grammatically correct @c SVN_PROP_MERGEINFO 00145 * property, contains overlapping or unordered revision ranges, or revision 00146 * ranges with a start revision greater than or equal to its end revision, 00147 * or contains paths mapped to empty revision ranges, then return 00148 * @c SVN_ERR_MERGEINFO_PARSE_ERROR. 00149 * @since New in 1.5. 00150 */ 00151 svn_error_t * 00152 svn_mergeinfo_parse(svn_mergeinfo_t *mergeinfo, const char *input, 00153 apr_pool_t *pool); 00154 00155 /** Calculate the delta between two mergeinfos, @a mergefrom and @a mergeto 00156 * (which may be @c NULL), and place the result in @a *deleted and @a 00157 * *added (neither output argument may be @c NULL). 00158 * 00159 * @a consider_inheritance determines how the rangelists in the two 00160 * hashes are compared for equality. If @a consider_inheritance is FALSE, 00161 * then the start and end revisions of the @c svn_merge_range_t's being 00162 * compared are the only factors considered when determining equality. 00163 * 00164 * e.g. '/trunk: 1,3-4*,5' == '/trunk: 1,3-5' 00165 * 00166 * If @a consider_inheritance is TRUE, then the inheritability of the 00167 * @c svn_merge_range_t's is also considered and must be the same for two 00168 * otherwise identical ranges to be judged equal. 00169 * 00170 * e.g. '/trunk: 1,3-4*,5' != '/trunk: 1,3-5' 00171 * '/trunk: 1,3-4*,5' == '/trunk: 1,3-4*,5' 00172 * '/trunk: 1,3-4,5' == '/trunk: 1,3-4,5' 00173 * 00174 * @since New in 1.5. 00175 */ 00176 svn_error_t * 00177 svn_mergeinfo_diff(svn_mergeinfo_t *deleted, svn_mergeinfo_t *added, 00178 svn_mergeinfo_t mergefrom, svn_mergeinfo_t mergeto, 00179 svn_boolean_t consider_inheritance, 00180 apr_pool_t *pool); 00181 00182 /** Merge one mergeinfo, @a changes, into another mergeinfo @a 00183 * mergeinfo. 00184 * 00185 * When intersecting rangelists for a path are merged, the inheritability of 00186 * the resulting svn_merge_range_t depends on the inheritability of the 00187 * operands. If two non-inheritable ranges are merged the result is always 00188 * non-inheritable, in all other cases the resulting range is inheritable. 00189 * 00190 * e.g. '/A: 1,3-4' merged with '/A: 1,3,4*,5' --> '/A: 1,3-5' 00191 * '/A: 1,3-4*' merged with '/A: 1,3,4*,5' --> '/A: 1,3,4*,5' 00192 * 00193 * @since New in 1.5. 00194 */ 00195 svn_error_t * 00196 svn_mergeinfo_merge(svn_mergeinfo_t mergeinfo, svn_mergeinfo_t changes, 00197 apr_pool_t *pool); 00198 00199 /** Removes @a eraser (the subtrahend) from @a whiteboard (the 00200 * minuend), and places the resulting difference in @a *mergeinfo. 00201 * 00202 * @since New in 1.5. 00203 */ 00204 svn_error_t * 00205 svn_mergeinfo_remove(svn_mergeinfo_t *mergeinfo, svn_mergeinfo_t eraser, 00206 svn_mergeinfo_t whiteboard, apr_pool_t *pool); 00207 00208 /** Calculate the delta between two rangelists consisting of @c 00209 * svn_merge_range_t * elements (sorted in ascending order), @a from 00210 * and @a to, and place the result in @a *deleted and @a *added 00211 * (neither output argument will ever be @c NULL). 00212 * 00213 * @a consider_inheritance determines how to account for the inheritability 00214 * of the two rangelist's ranges when calculating the diff, 00215 * @see svn_mergeinfo_diff(). 00216 * 00217 * @since New in 1.5. 00218 */ 00219 svn_error_t * 00220 svn_rangelist_diff(apr_array_header_t **deleted, apr_array_header_t **added, 00221 apr_array_header_t *from, apr_array_header_t *to, 00222 svn_boolean_t consider_inheritance, 00223 apr_pool_t *pool); 00224 00225 /** Merge two rangelists consisting of @c svn_merge_range_t * 00226 * elements, @a *rangelist and @a changes, placing the results in 00227 * @a *rangelist. Either rangelist may be empty. 00228 * 00229 * When intersecting rangelists are merged, the inheritability of 00230 * the resulting svn_merge_range_t depends on the inheritability of the 00231 * operands, @see svn_mergeinfo_merge(). 00232 * 00233 * Note: @a *rangelist and @a changes must be sorted as said by @c 00234 * svn_sort_compare_ranges(). @a *rangelist is guaranteed to remain 00235 * in sorted order and be compacted to the minimal number of ranges 00236 * needed to represent the merged result. 00237 * 00238 * @since New in 1.5. 00239 */ 00240 svn_error_t * 00241 svn_rangelist_merge(apr_array_header_t **rangelist, 00242 apr_array_header_t *changes, 00243 apr_pool_t *pool); 00244 00245 /** Removes @a eraser (the subtrahend) from @a whiteboard (the 00246 * minuend), and places the resulting difference in @a output. 00247 * 00248 * Note: @a eraser and @a whiteboard must be sorted as said by @c 00249 * svn_sort_compare_ranges(). @a output is guaranteed to be in sorted 00250 * order. 00251 * 00252 * @a consider_inheritance determines how to account for the 00253 * @c svn_merge_range_t inheritable field when comparing @a whiteboard's 00254 * and @a *eraser's rangelists for equality. @see svn_mergeinfo_diff(). 00255 * 00256 * @since New in 1.5. 00257 */ 00258 svn_error_t * 00259 svn_rangelist_remove(apr_array_header_t **output, apr_array_header_t *eraser, 00260 apr_array_header_t *whiteboard, 00261 svn_boolean_t consider_inheritance, 00262 apr_pool_t *pool); 00263 00264 /** Find the intersection of two mergeinfos, @a mergeinfo1 and @a 00265 * mergeinfo2, and place the result in @a *mergeinfo, which is (deeply) 00266 * allocated in @a pool. 00267 * 00268 * @since New in 1.5. 00269 */ 00270 svn_error_t * 00271 svn_mergeinfo_intersect(svn_mergeinfo_t *mergeinfo, 00272 svn_mergeinfo_t mergeinfo1, 00273 svn_mergeinfo_t mergeinfo2, 00274 apr_pool_t *pool); 00275 00276 /** Find the intersection of two rangelists consisting of @c 00277 * svn_merge_range_t * elements, @a rangelist1 and @a rangelist2, and 00278 * place the result in @a *rangelist (which is never @c NULL). 00279 * 00280 * @a consider_inheritance determines how to account for the inheritability 00281 * of the two rangelist's ranges when calculating the intersection, 00282 * @see svn_mergeinfo_diff(). 00283 * 00284 * Note: @a rangelist1 and @a rangelist2 must be sorted as said by @c 00285 * svn_sort_compare_ranges(). @a *rangelist is guaranteed to be in sorted 00286 * order. 00287 * @since New in 1.5. 00288 */ 00289 svn_error_t * 00290 svn_rangelist_intersect(apr_array_header_t **rangelist, 00291 apr_array_header_t *rangelist1, 00292 apr_array_header_t *rangelist2, 00293 svn_boolean_t consider_inheritance, 00294 apr_pool_t *pool); 00295 00296 /** Reverse @a rangelist, and the @c start and @c end fields of each 00297 * range in @a rangelist, in place. 00298 * 00299 * TODO(miapi): Is this really a valid function? Rangelists that 00300 * aren't sorted, or rangelists containing reverse ranges, are 00301 * generally not valid in mergeinfo code. Can we rewrite the two 00302 * places where this is used? 00303 * 00304 * @since New in 1.5. 00305 */ 00306 svn_error_t * 00307 svn_rangelist_reverse(apr_array_header_t *rangelist, apr_pool_t *pool); 00308 00309 /** Take an array of svn_merge_range_t *'s in @a rangelist, and convert it 00310 * back to a text format rangelist in @a output. If @a rangelist contains 00311 * no elements, sets @a output to the empty string. 00312 * 00313 * @since New in 1.5. 00314 */ 00315 svn_error_t * 00316 svn_rangelist_to_string(svn_string_t **output, 00317 const apr_array_header_t *rangelist, 00318 apr_pool_t *pool); 00319 00320 /** Return a deep copy of @c svn_merge_range_t *'s in @a rangelist excluding 00321 * all non-inheritable @c svn_merge_range_t. If @a start and @a end are valid 00322 * revisions and @a start is less than or equal to @a end, then exclude only the 00323 * non-inheritable revision ranges that intersect inclusively with the range 00324 * defined by @a start and @a end. If @a rangelist contains no elements, return 00325 * an empty array. Allocate the copy in @a pool. 00326 * 00327 * @since New in 1.5. 00328 */ 00329 svn_error_t * 00330 svn_rangelist_inheritable(apr_array_header_t **inheritable_rangelist, 00331 apr_array_header_t *rangelist, 00332 svn_revnum_t start, 00333 svn_revnum_t end, 00334 apr_pool_t *pool); 00335 00336 /** Return a deep copy of @a mergeinfo, excluding all non-inheritable 00337 * @c svn_merge_range_t. If @a start and @a end are valid revisions 00338 * and @a start is less than or equal to @a end, then exclude only the 00339 * non-inheritable revisions that intersect inclusively with the range 00340 * defined by @a start and @a end. If @a path is not NULL remove 00341 * non-inheritable ranges only for @a path. Allocate the copy in @a 00342 * pool. 00343 * 00344 * @since New in 1.5. 00345 */ 00346 svn_error_t * 00347 svn_mergeinfo_inheritable(svn_mergeinfo_t *inheritable_mergeinfo, 00348 svn_mergeinfo_t mergeinfo, 00349 const char *path, 00350 svn_revnum_t start, 00351 svn_revnum_t end, 00352 apr_pool_t *pool); 00353 00354 /** Take a mergeinfo in MERGEINPUT, and convert it back to unparsed 00355 * mergeinfo in *OUTPUT. If INPUT contains no elements, return the 00356 * empty string. 00357 * 00358 * @since New in 1.5. 00359 */ 00360 svn_error_t * 00361 svn_mergeinfo_to_string(svn_string_t **output, 00362 svn_mergeinfo_t mergeinput, 00363 apr_pool_t *pool); 00364 00365 /** Take a hash of mergeinfo in @a mergeinfo, and sort the rangelists 00366 * associated with each key (in place). 00367 * 00368 * TODO(miapi): mergeinfos should *always* be sorted. This should be 00369 * a private function. 00370 * 00371 * @since New in 1.5 00372 */ 00373 svn_error_t * 00374 svn_mergeinfo_sort(svn_mergeinfo_t mergeinfo, apr_pool_t *pool); 00375 00376 /** Return a deep copy of @a mergeinfo, allocated in @a pool. 00377 * 00378 * @since New in 1.5. 00379 */ 00380 svn_mergeinfo_t 00381 svn_mergeinfo_dup(svn_mergeinfo_t mergeinfo, apr_pool_t *pool); 00382 00383 /** Return a deep copy of @a rangelist, allocated in @a pool. 00384 * 00385 * @since New in 1.5. 00386 */ 00387 apr_array_header_t * 00388 svn_rangelist_dup(apr_array_header_t *rangelist, apr_pool_t *pool); 00389 00390 00391 /** 00392 * The three ways to request mergeinfo affecting a given path. 00393 * 00394 * @since New in 1.5. 00395 */ 00396 typedef enum 00397 { 00398 /** Explicit mergeinfo only. */ 00399 svn_mergeinfo_explicit, 00400 00401 /** Explicit mergeinfo, or if that doesn't exist, the inherited 00402 mergeinfo from a target's nearest (path-wise, not history-wise) 00403 ancestor. */ 00404 svn_mergeinfo_inherited, 00405 00406 /** Mergeinfo on target's nearest (path-wise, not history-wise) 00407 ancestor, regardless of whether target has explict mergeinfo. */ 00408 svn_mergeinfo_nearest_ancestor 00409 } svn_mergeinfo_inheritance_t; 00410 00411 /** Return a constant string expressing @a inherit as an English word, 00412 * i.e., "explicit" (default), "inherited", or "nearest_ancestor". 00413 * The string is not localized, as it may be used for client<->server 00414 * communications. 00415 * 00416 * @since New in 1.5. 00417 */ 00418 const char * 00419 svn_inheritance_to_word(svn_mergeinfo_inheritance_t inherit); 00420 00421 00422 /** Return the appropriate @c svn_mergeinfo_inheritance_t for @a word. 00423 * @a word is as returned from svn_inheritance_to_word(). Defaults to 00424 * @c svn_mergeinfo_explicit. 00425 * 00426 * @since New in 1.5. 00427 */ 00428 svn_mergeinfo_inheritance_t 00429 svn_inheritance_from_word(const char *word); 00430 00431 00432 #ifdef __cplusplus 00433 } 00434 #endif /* __cplusplus */ 00435 00436 #endif /* SVN_MERGEINFO_H */
1.3.9.1