00001 /** 00002 * @copyright 00003 * ==================================================================== 00004 * Licensed to the Apache Software Foundation (ASF) under one 00005 * or more contributor license agreements. See the NOTICE file 00006 * distributed with this work for additional information 00007 * regarding copyright ownership. The ASF licenses this file 00008 * to you under the Apache License, Version 2.0 (the 00009 * "License"); you may not use this file except in compliance 00010 * with the License. You may obtain a copy of the License at 00011 * 00012 * http://www.apache.org/licenses/LICENSE-2.0 00013 * 00014 * Unless required by applicable law or agreed to in writing, 00015 * software distributed under the License is distributed on an 00016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 00017 * KIND, either express or implied. See the License for the 00018 * specific language governing permissions and limitations 00019 * under the License. 00020 * ==================================================================== 00021 * @endcopyright 00022 * 00023 * @file svn_diff.h 00024 * @brief Contextual diffing. 00025 * 00026 * This is an internalized library for performing contextual diffs 00027 * between sources of data. 00028 * 00029 * @note This is different than Subversion's binary-diffing engine. 00030 * That API lives in @c svn_delta.h -- see the "text deltas" section. A 00031 * "text delta" is way of representing precise binary diffs between 00032 * strings of data. The Subversion client and server send text deltas 00033 * to one another during updates and commits. 00034 * 00035 * This API, however, is (or will be) used for performing *contextual* 00036 * merges between files in the working copy. During an update or 00037 * merge, 3-way file merging is needed. And 'svn diff' needs to show 00038 * the differences between 2 files. 00039 * 00040 * The nice thing about this API is that it's very general. It 00041 * operates on any source of data (a "datasource") and calculates 00042 * contextual differences on "tokens" within the data. In our 00043 * particular usage, the datasources are files and the tokens are 00044 * lines. But the possibilities are endless. 00045 */ 00046 00047 00048 #ifndef SVN_DIFF_H 00049 #define SVN_DIFF_H 00050 00051 #include <apr.h> 00052 #include <apr_pools.h> 00053 #include <apr_tables.h> /* for apr_array_header_t */ 00054 00055 #include "svn_types.h" 00056 #include "svn_io.h" /* for svn_stream_t */ 00057 #include "svn_string.h" 00058 00059 #ifdef __cplusplus 00060 extern "C" { 00061 #endif /* __cplusplus */ 00062 00063 00064 00065 /** 00066 * Get libsvn_diff version information. 00067 * 00068 * @since New in 1.1. 00069 */ 00070 const svn_version_t * 00071 svn_diff_version(void); 00072 00073 00074 /* Diffs. */ 00075 00076 /** An opaque type that represents a difference between either two or 00077 * three datasources. This object is returned by svn_diff_diff(), 00078 * svn_diff_diff3() and svn_diff_diff4(), and consumed by a number of 00079 * other routines. 00080 */ 00081 typedef struct svn_diff_t svn_diff_t; 00082 00083 /** 00084 * There are four types of datasources. In GNU diff3 terminology, 00085 * the first three types correspond to the phrases "older", "mine", 00086 * and "yours". 00087 */ 00088 typedef enum svn_diff_datasource_e 00089 { 00090 /** The oldest form of the data. */ 00091 svn_diff_datasource_original, 00092 00093 /** The same data, but potentially changed by the user. */ 00094 svn_diff_datasource_modified, 00095 00096 /** The latest version of the data, possibly different than the 00097 * user's modified version. 00098 */ 00099 svn_diff_datasource_latest, 00100 00101 /** The common ancestor of original and modified. */ 00102 svn_diff_datasource_ancestor 00103 00104 } svn_diff_datasource_e; 00105 00106 00107 /** A vtable for reading data from the three datasources. 00108 * @since New in 1.7. */ 00109 typedef struct svn_diff_fns2_t 00110 { 00111 /** Open the datasources of type @a datasources. */ 00112 svn_error_t *(*datasources_open)(void *diff_baton, 00113 apr_off_t *prefix_lines, 00114 apr_off_t *suffix_lines, 00115 const svn_diff_datasource_e *datasources, 00116 apr_size_t datasources_len); 00117 00118 /** Close the datasource of type @a datasource. */ 00119 svn_error_t *(*datasource_close)(void *diff_baton, 00120 svn_diff_datasource_e datasource); 00121 00122 /** Get the next "token" from the datasource of type @a datasource. 00123 * Return a "token" in @a *token. Return a hash of "token" in @a *hash. 00124 * Leave @a token and @a hash untouched when the datasource is exhausted. 00125 */ 00126 svn_error_t *(*datasource_get_next_token)(apr_uint32_t *hash, void **token, 00127 void *diff_baton, 00128 svn_diff_datasource_e datasource); 00129 00130 /** A function for ordering the tokens, resembling 'strcmp' in functionality. 00131 * @a compare should contain the return value of the comparison: 00132 * If @a ltoken and @a rtoken are "equal", return 0. If @a ltoken is 00133 * "less than" @a rtoken, return a number < 0. If @a ltoken is 00134 * "greater than" @a rtoken, return a number > 0. 00135 */ 00136 svn_error_t *(*token_compare)(void *diff_baton, 00137 void *ltoken, 00138 void *rtoken, 00139 int *compare); 00140 00141 /** Free @a token from memory, the diff algorithm is done with it. */ 00142 void (*token_discard)(void *diff_baton, 00143 void *token); 00144 00145 /** Free *all* tokens from memory, they're no longer needed. */ 00146 void (*token_discard_all)(void *diff_baton); 00147 } svn_diff_fns2_t; 00148 00149 00150 /** Like #svn_diff_fns2_t except with datasource_open() instead of 00151 * datasources_open(). 00152 * 00153 * @deprecated Provided for backward compatibility with the 1.6 API. 00154 */ 00155 typedef struct svn_diff_fns_t 00156 { 00157 svn_error_t *(*datasource_open)(void *diff_baton, 00158 svn_diff_datasource_e datasource); 00159 00160 svn_error_t *(*datasource_close)(void *diff_baton, 00161 svn_diff_datasource_e datasource); 00162 00163 svn_error_t *(*datasource_get_next_token)(apr_uint32_t *hash, void **token, 00164 void *diff_baton, 00165 svn_diff_datasource_e datasource); 00166 00167 svn_error_t *(*token_compare)(void *diff_baton, 00168 void *ltoken, 00169 void *rtoken, 00170 int *compare); 00171 00172 void (*token_discard)(void *diff_baton, 00173 void *token); 00174 00175 void (*token_discard_all)(void *diff_baton); 00176 } svn_diff_fns_t; 00177 00178 00179 /* The Main Events */ 00180 00181 /** Given a vtable of @a diff_fns/@a diff_baton for reading datasources, 00182 * return a diff object in @a *diff that represents a difference between 00183 * an "original" and "modified" datasource. Do all allocation in @a pool. 00184 * 00185 * @since New in 1.7. 00186 */ 00187 svn_error_t * 00188 svn_diff_diff_2(svn_diff_t **diff, 00189 void *diff_baton, 00190 const svn_diff_fns2_t *diff_fns, 00191 apr_pool_t *pool); 00192 00193 /** Like svn_diff_diff_2() but using #svn_diff_fns_t instead of 00194 * #svn_diff_fns2_t. 00195 * 00196 * @deprecated Provided for backward compatibility with the 1.6 API. 00197 */ 00198 SVN_DEPRECATED 00199 svn_error_t * 00200 svn_diff_diff(svn_diff_t **diff, 00201 void *diff_baton, 00202 const svn_diff_fns_t *diff_fns, 00203 apr_pool_t *pool); 00204 00205 /** Given a vtable of @a diff_fns/@a diff_baton for reading datasources, 00206 * return a diff object in @a *diff that represents a difference between 00207 * three datasources: "original", "modified", and "latest". Do all 00208 * allocation in @a pool. 00209 * 00210 * @since New in 1.7. 00211 */ 00212 svn_error_t * 00213 svn_diff_diff3_2(svn_diff_t **diff, 00214 void *diff_baton, 00215 const svn_diff_fns2_t *diff_fns, 00216 apr_pool_t *pool); 00217 00218 /** Like svn_diff_diff3_2() but using #svn_diff_fns_t instead of 00219 * #svn_diff_fns2_t. 00220 * 00221 * @deprecated Provided for backward compatibility with the 1.6 API. 00222 */ 00223 SVN_DEPRECATED 00224 svn_error_t * 00225 svn_diff_diff3(svn_diff_t **diff, 00226 void *diff_baton, 00227 const svn_diff_fns_t *diff_fns, 00228 apr_pool_t *pool); 00229 00230 /** Given a vtable of @a diff_fns/@a diff_baton for reading datasources, 00231 * return a diff object in @a *diff that represents a difference between 00232 * two datasources: "original" and "latest", adjusted to become a full 00233 * difference between "original", "modified" and "latest" using "ancestor". 00234 * Do all allocation in @a pool. 00235 * 00236 * @since New in 1.7. 00237 */ 00238 svn_error_t * 00239 svn_diff_diff4_2(svn_diff_t **diff, 00240 void *diff_baton, 00241 const svn_diff_fns2_t *diff_fns, 00242 apr_pool_t *pool); 00243 00244 /** Like svn_diff_diff4_2() but using #svn_diff_fns_t instead of 00245 * #svn_diff_fns2_t. 00246 * 00247 * @deprecated Provided for backward compatibility with the 1.6 API. 00248 */ 00249 SVN_DEPRECATED 00250 svn_error_t * 00251 svn_diff_diff4(svn_diff_t **diff, 00252 void *diff_baton, 00253 const svn_diff_fns_t *diff_fns, 00254 apr_pool_t *pool); 00255 00256 00257 /* Utility functions */ 00258 00259 /** Determine if a diff object contains conflicts. If it does, return 00260 * @c TRUE, else return @c FALSE. 00261 */ 00262 svn_boolean_t 00263 svn_diff_contains_conflicts(svn_diff_t *diff); 00264 00265 00266 /** Determine if a diff object contains actual differences between the 00267 * datasources. If so, return @c TRUE, else return @c FALSE. 00268 */ 00269 svn_boolean_t 00270 svn_diff_contains_diffs(svn_diff_t *diff); 00271 00272 00273 00274 00275 /* Displaying Diffs */ 00276 00277 /** A vtable for displaying (or consuming) differences between datasources. 00278 * 00279 * Differences, similarities, and conflicts are described by lining up 00280 * "ranges" of data. 00281 * 00282 * Any of the function pointers in this vtable may be NULL to ignore the 00283 * corresponding kinds of output. 00284 * 00285 * @note These callbacks describe data ranges in units of "tokens". 00286 * A "token" is whatever you've defined it to be in your datasource 00287 * @c svn_diff_fns_t vtable. 00288 */ 00289 typedef struct svn_diff_output_fns_t 00290 { 00291 /* Two-way and three-way diffs both call the first two output functions: */ 00292 00293 /** 00294 * If doing a two-way diff, then an *identical* data range was found 00295 * between the "original" and "modified" datasources. Specifically, 00296 * the match starts at @a original_start and goes for @a original_length 00297 * tokens in the original data, and at @a modified_start for 00298 * @a modified_length tokens in the modified data. 00299 * 00300 * If doing a three-way diff, then all three datasources have 00301 * matching data ranges. The range @a latest_start, @a latest_length in 00302 * the "latest" datasource is identical to the range @a original_start, 00303 * @a original_length in the original data, and is also identical to 00304 * the range @a modified_start, @a modified_length in the modified data. 00305 */ 00306 svn_error_t *(*output_common)(void *output_baton, 00307 apr_off_t original_start, 00308 apr_off_t original_length, 00309 apr_off_t modified_start, 00310 apr_off_t modified_length, 00311 apr_off_t latest_start, 00312 apr_off_t latest_length); 00313 00314 /** 00315 * If doing a two-way diff, then an *conflicting* data range was found 00316 * between the "original" and "modified" datasources. Specifically, 00317 * the conflict starts at @a original_start and goes for @a original_length 00318 * tokens in the original data, and at @a modified_start for 00319 * @a modified_length tokens in the modified data. 00320 * 00321 * If doing a three-way diff, then an identical data range was discovered 00322 * between the "original" and "latest" datasources, but this conflicts with 00323 * a range in the "modified" datasource. 00324 */ 00325 svn_error_t *(*output_diff_modified)(void *output_baton, 00326 apr_off_t original_start, 00327 apr_off_t original_length, 00328 apr_off_t modified_start, 00329 apr_off_t modified_length, 00330 apr_off_t latest_start, 00331 apr_off_t latest_length); 00332 00333 /* ------ The following callbacks are used by three-way diffs only --- */ 00334 00335 /** An identical data range was discovered between the "original" and 00336 * "modified" datasources, but this conflicts with a range in the 00337 * "latest" datasource. 00338 */ 00339 svn_error_t *(*output_diff_latest)(void *output_baton, 00340 apr_off_t original_start, 00341 apr_off_t original_length, 00342 apr_off_t modified_start, 00343 apr_off_t modified_length, 00344 apr_off_t latest_start, 00345 apr_off_t latest_length); 00346 00347 /** An identical data range was discovered between the "modified" and 00348 * "latest" datasources, but this conflicts with a range in the 00349 * "original" datasource. 00350 */ 00351 svn_error_t *(*output_diff_common)(void *output_baton, 00352 apr_off_t original_start, 00353 apr_off_t original_length, 00354 apr_off_t modified_start, 00355 apr_off_t modified_length, 00356 apr_off_t latest_start, 00357 apr_off_t latest_length); 00358 00359 /** All three datasources have conflicting data ranges. The range 00360 * @a latest_start, @a latest_length in the "latest" datasource conflicts 00361 * with the range @a original_start, @a original_length in the "original" 00362 * datasource, and also conflicts with the range @a modified_start, 00363 * @a modified_length in the "modified" datasource. 00364 * If there are common ranges in the "modified" and "latest" datasources 00365 * in this conflicting range, @a resolved_diff will contain a diff 00366 * which can be used to retrieve the common and conflicting ranges. 00367 */ 00368 svn_error_t *(*output_conflict)(void *output_baton, 00369 apr_off_t original_start, 00370 apr_off_t original_length, 00371 apr_off_t modified_start, 00372 apr_off_t modified_length, 00373 apr_off_t latest_start, 00374 apr_off_t latest_length, 00375 svn_diff_t *resolved_diff); 00376 } svn_diff_output_fns_t; 00377 00378 /** Style for displaying conflicts during diff3 output. 00379 * 00380 * @since New in 1.6. 00381 */ 00382 typedef enum svn_diff_conflict_display_style_t 00383 { 00384 /** Display modified and latest, with conflict markers. */ 00385 svn_diff_conflict_display_modified_latest, 00386 00387 /** Like svn_diff_conflict_display_modified_latest, but with an 00388 extra effort to identify common sequences between modified and 00389 latest. */ 00390 svn_diff_conflict_display_resolved_modified_latest, 00391 00392 /** Display modified, original, and latest, with conflict 00393 markers. */ 00394 svn_diff_conflict_display_modified_original_latest, 00395 00396 /** Just display modified, with no markers. */ 00397 svn_diff_conflict_display_modified, 00398 00399 /** Just display latest, with no markers. */ 00400 svn_diff_conflict_display_latest, 00401 00402 /** Like svn_diff_conflict_display_modified_original_latest, but 00403 *only* showing conflicts. */ 00404 svn_diff_conflict_display_only_conflicts 00405 } svn_diff_conflict_display_style_t; 00406 00407 00408 /** Given a vtable of @a output_fns/@a output_baton for consuming 00409 * differences, output the differences in @a diff. 00410 */ 00411 svn_error_t * 00412 svn_diff_output(svn_diff_t *diff, 00413 void *output_baton, 00414 const svn_diff_output_fns_t *output_fns); 00415 00416 00417 00418 /* Diffs on files */ 00419 00420 /** To what extent whitespace should be ignored when comparing lines. 00421 * 00422 * @since New in 1.4. 00423 */ 00424 typedef enum svn_diff_file_ignore_space_t 00425 { 00426 /** Ignore no whitespace. */ 00427 svn_diff_file_ignore_space_none, 00428 00429 /** Ignore changes in sequences of whitespace characters, treating each 00430 * sequence of whitespace characters as a single space. */ 00431 svn_diff_file_ignore_space_change, 00432 00433 /** Ignore all whitespace characters. */ 00434 svn_diff_file_ignore_space_all 00435 } svn_diff_file_ignore_space_t; 00436 00437 /** Options to control the behaviour of the file diff routines. 00438 * 00439 * @since New in 1.4. 00440 * 00441 * @note This structure may be extended in the future, so to preserve binary 00442 * compatibility, users must not allocate structs of this type themselves. 00443 * @see svn_diff_file_options_create(). 00444 * 00445 * @note Although its name suggests otherwise, this structure is used to 00446 * pass options to file as well as in-memory diff functions. 00447 */ 00448 typedef struct svn_diff_file_options_t 00449 { 00450 /** To what extent whitespace should be ignored when comparing lines. 00451 * The default is @c svn_diff_file_ignore_space_none. */ 00452 svn_diff_file_ignore_space_t ignore_space; 00453 /** Whether to treat all end-of-line markers the same when comparing lines. 00454 * The default is @c FALSE. */ 00455 svn_boolean_t ignore_eol_style; 00456 /** Whether the "@@" lines of the unified diff output should include a prefix 00457 * of the nearest preceding line that starts with a character that might be 00458 * the initial character of a C language identifier. The default is 00459 * @c FALSE. 00460 */ 00461 svn_boolean_t show_c_function; 00462 } svn_diff_file_options_t; 00463 00464 /** Allocate a @c svn_diff_file_options_t structure in @a pool, initializing 00465 * it with default values. 00466 * 00467 * @since New in 1.4. 00468 */ 00469 svn_diff_file_options_t * 00470 svn_diff_file_options_create(apr_pool_t *pool); 00471 00472 /** 00473 * Parse @a args, an array of <tt>const char *</tt> command line switches 00474 * and adjust @a options accordingly. @a options is assumed to be initialized 00475 * with default values. @a pool is used for temporary allocation. 00476 * 00477 * @since New in 1.4. 00478 * 00479 * The following options are supported: 00480 * - --ignore-space-change, -b 00481 * - --ignore-all-space, -w 00482 * - --ignore-eol-style 00483 * - --show-c-function, -p @since New in 1.5. 00484 * - --unified, -u (for compatibility, does nothing). 00485 */ 00486 svn_error_t * 00487 svn_diff_file_options_parse(svn_diff_file_options_t *options, 00488 const apr_array_header_t *args, 00489 apr_pool_t *pool); 00490 00491 00492 /** A convenience function to produce a diff between two files. 00493 * 00494 * @since New in 1.4. 00495 * 00496 * Return a diff object in @a *diff (allocated from @a pool) that represents 00497 * the difference between an @a original file and @a modified file. 00498 * (The file arguments must be full paths to the files.) 00499 * 00500 * Compare lines according to the relevant fields of @a options. 00501 */ 00502 svn_error_t * 00503 svn_diff_file_diff_2(svn_diff_t **diff, 00504 const char *original, 00505 const char *modified, 00506 const svn_diff_file_options_t *options, 00507 apr_pool_t *pool); 00508 00509 /** Similar to svn_file_diff_2(), but with @a options set to a struct with 00510 * default options. 00511 * 00512 * @deprecated Provided for backwards compatibility with the 1.3 API. 00513 */ 00514 SVN_DEPRECATED 00515 svn_error_t * 00516 svn_diff_file_diff(svn_diff_t **diff, 00517 const char *original, 00518 const char *modified, 00519 apr_pool_t *pool); 00520 00521 /** A convenience function to produce a diff between three files. 00522 * 00523 * @since New in 1.4. 00524 * 00525 * Return a diff object in @a *diff (allocated from @a pool) that represents 00526 * the difference between an @a original file, @a modified file, and @a latest 00527 * file. 00528 * 00529 * Compare lines according to the relevant fields of @a options. 00530 */ 00531 svn_error_t * 00532 svn_diff_file_diff3_2(svn_diff_t **diff, 00533 const char *original, 00534 const char *modified, 00535 const char *latest, 00536 const svn_diff_file_options_t *options, 00537 apr_pool_t *pool); 00538 00539 /** Similar to svn_diff_file_diff3_2(), but with @a options set to a struct 00540 * with default options. 00541 * 00542 * @deprecated Provided for backwards compatibility with the 1.3 API. 00543 */ 00544 SVN_DEPRECATED 00545 svn_error_t * 00546 svn_diff_file_diff3(svn_diff_t **diff, 00547 const char *original, 00548 const char *modified, 00549 const char *latest, 00550 apr_pool_t *pool); 00551 00552 /** A convenience function to produce a diff between four files. 00553 * 00554 * @since New in 1.4. 00555 * 00556 * Return a diff object in @a *diff (allocated from @a pool) that represents 00557 * the difference between an @a original file, @a modified file, @a latest 00558 * and @a ancestor file. (The file arguments must be full paths to the files.) 00559 * 00560 * Compare lines according to the relevant fields of @a options. 00561 */ 00562 svn_error_t * 00563 svn_diff_file_diff4_2(svn_diff_t **diff, 00564 const char *original, 00565 const char *modified, 00566 const char *latest, 00567 const char *ancestor, 00568 const svn_diff_file_options_t *options, 00569 apr_pool_t *pool); 00570 00571 /** Similar to svn_file_diff4_2(), but with @a options set to a struct with 00572 * default options. 00573 * 00574 * @deprecated Provided for backwards compatibility with the 1.3 API. 00575 */ 00576 SVN_DEPRECATED 00577 svn_error_t * 00578 svn_diff_file_diff4(svn_diff_t **diff, 00579 const char *original, 00580 const char *modified, 00581 const char *latest, 00582 const char *ancestor, 00583 apr_pool_t *pool); 00584 00585 /** A convenience function to produce unified diff output from the 00586 * diff generated by svn_diff_file_diff(). 00587 * 00588 * @since New in 1.5. 00589 * 00590 * Output a @a diff between @a original_path and @a modified_path in unified 00591 * context diff format to @a output_stream. Optionally supply 00592 * @a original_header and/or @a modified_header to be displayed in the header 00593 * of the output. If @a original_header or @a modified_header is @c NULL, a 00594 * default header will be displayed, consisting of path and last modified time. 00595 * Output all headers and markers in @a header_encoding. If @a relative_to_dir 00596 * is not @c NULL, the @a original_path and @a modified_path will have the 00597 * @a relative_to_dir stripped from the front of the respective paths. If 00598 * @a relative_to_dir is @c NULL, paths will be not be modified. If 00599 * @a relative_to_dir is not @c NULL but @a relative_to_dir is not a parent 00600 * path of the target, an error is returned. Finally, if @a relative_to_dir 00601 * is a URL, an error will be returned. 00602 */ 00603 svn_error_t * 00604 svn_diff_file_output_unified3(svn_stream_t *output_stream, 00605 svn_diff_t *diff, 00606 const char *original_path, 00607 const char *modified_path, 00608 const char *original_header, 00609 const char *modified_header, 00610 const char *header_encoding, 00611 const char *relative_to_dir, 00612 svn_boolean_t show_c_function, 00613 apr_pool_t *pool); 00614 00615 /** Similar to svn_diff_file_output_unified3(), but with @a relative_to_dir 00616 * set to NULL and @a show_c_function to false. 00617 * 00618 * @deprecated Provided for backwards compatibility with the 1.4 API. 00619 */ 00620 SVN_DEPRECATED 00621 svn_error_t * 00622 svn_diff_file_output_unified2(svn_stream_t *output_stream, 00623 svn_diff_t *diff, 00624 const char *original_path, 00625 const char *modified_path, 00626 const char *original_header, 00627 const char *modified_header, 00628 const char *header_encoding, 00629 apr_pool_t *pool); 00630 00631 /** Similar to svn_diff_file_output_unified2(), but with @a header_encoding 00632 * set to @c APR_LOCALE_CHARSET. 00633 * 00634 * @deprecated Provided for backward compatibility with the 1.2 API. 00635 */ 00636 SVN_DEPRECATED 00637 svn_error_t * 00638 svn_diff_file_output_unified(svn_stream_t *output_stream, 00639 svn_diff_t *diff, 00640 const char *original_path, 00641 const char *modified_path, 00642 const char *original_header, 00643 const char *modified_header, 00644 apr_pool_t *pool); 00645 00646 00647 /** A convenience function to produce diff3 output from the 00648 * diff generated by svn_diff_file_diff3(). 00649 * 00650 * Output a @a diff between @a original_path, @a modified_path and 00651 * @a latest_path in merged format to @a output_stream. Optionally supply 00652 * @a conflict_modified, @a conflict_original, @a conflict_separator and/or 00653 * @a conflict_latest to be displayed as conflict markers in the output. 00654 * If @a conflict_original, @a conflict_modified, @a conflict_latest and/or 00655 * @a conflict_separator is @c NULL, a default marker will be displayed. 00656 * @a conflict_style dictates how conflicts are displayed. 00657 * 00658 * @since New in 1.6. 00659 */ 00660 svn_error_t * 00661 svn_diff_file_output_merge2(svn_stream_t *output_stream, 00662 svn_diff_t *diff, 00663 const char *original_path, 00664 const char *modified_path, 00665 const char *latest_path, 00666 const char *conflict_original, 00667 const char *conflict_modified, 00668 const char *conflict_latest, 00669 const char *conflict_separator, 00670 svn_diff_conflict_display_style_t conflict_style, 00671 apr_pool_t *pool); 00672 00673 00674 /** Similar to svn_diff_file_output_merge2, but with @a 00675 * display_original_in_conflict and @a display_resolved_conflicts 00676 * booleans instead of the @a conflict_style enum. 00677 * 00678 * If both booleans are false, acts like 00679 * svn_diff_conflict_display_modified_latest; if @a 00680 * display_original_in_conflict is true, acts like 00681 * svn_diff_conflict_display_modified_original_latest; if @a 00682 * display_resolved_conflicts is true, acts like 00683 * svn_diff_conflict_display_resolved_modified_latest. The booleans 00684 * may not both be true. 00685 * 00686 * @deprecated Provided for backward compatibility with the 1.5 API. 00687 */ 00688 SVN_DEPRECATED 00689 svn_error_t * 00690 svn_diff_file_output_merge(svn_stream_t *output_stream, 00691 svn_diff_t *diff, 00692 const char *original_path, 00693 const char *modified_path, 00694 const char *latest_path, 00695 const char *conflict_original, 00696 const char *conflict_modified, 00697 const char *conflict_latest, 00698 const char *conflict_separator, 00699 svn_boolean_t display_original_in_conflict, 00700 svn_boolean_t display_resolved_conflicts, 00701 apr_pool_t *pool); 00702 00703 00704 00705 /* Diffs on in-memory structures */ 00706 00707 /** Generate @a diff output from the @a original and @a modified 00708 * in-memory strings. @a diff will be allocated from @a pool. 00709 * 00710 * @since New in 1.5. 00711 */ 00712 svn_error_t * 00713 svn_diff_mem_string_diff(svn_diff_t **diff, 00714 const svn_string_t *original, 00715 const svn_string_t *modified, 00716 const svn_diff_file_options_t *options, 00717 apr_pool_t *pool); 00718 00719 00720 /** Generate @a diff output from the @a original, @a modified and @a latest 00721 * in-memory strings. @a diff will be allocated in @a pool. 00722 * 00723 * @since New in 1.5. 00724 */ 00725 svn_error_t * 00726 svn_diff_mem_string_diff3(svn_diff_t **diff, 00727 const svn_string_t *original, 00728 const svn_string_t *modified, 00729 const svn_string_t *latest, 00730 const svn_diff_file_options_t *options, 00731 apr_pool_t *pool); 00732 00733 00734 /** Generate @a diff output from the @a original, @a modified and @a latest 00735 * in-memory strings, using @a ancestor. @a diff will be allocated in @a pool. 00736 * 00737 * @since New in 1.5. 00738 */ 00739 svn_error_t * 00740 svn_diff_mem_string_diff4(svn_diff_t **diff, 00741 const svn_string_t *original, 00742 const svn_string_t *modified, 00743 const svn_string_t *latest, 00744 const svn_string_t *ancestor, 00745 const svn_diff_file_options_t *options, 00746 apr_pool_t *pool); 00747 00748 /** Outputs the @a diff object generated by svn_diff_mem_string_diff() 00749 * in unified diff format on @a output_stream, using @a original 00750 * and @a modified for the text in the output. 00751 * 00752 * If @a with_diff_header is TRUE, write a diff header ("---" and "+++" 00753 * lines), using @a original_header and @a modified_header to fill the field 00754 * after the "---" and "+++" markers; otherwise @a original_header and 00755 * @a modified_header are ignored and may be NULL. 00756 * 00757 * Outputs the header and hunk delimiters in @a header_encoding. 00758 * A @a hunk_delimiter can optionally be specified. 00759 * If @a hunk_delimiter is NULL, use the default hunk delimiter "@@". 00760 * 00761 * As a special case, if the hunk delimiter is "##", then for an incomplete 00762 * final line use the text "\ No newline at end of property" instead of 00763 * "\ No newline at end of file". 00764 * 00765 * @since New in 1.7. Hunk delimiter "##" has the special meaning since 1.8. 00766 */ 00767 svn_error_t * 00768 svn_diff_mem_string_output_unified2(svn_stream_t *output_stream, 00769 svn_diff_t *diff, 00770 svn_boolean_t with_diff_header, 00771 const char *hunk_delimiter, 00772 const char *original_header, 00773 const char *modified_header, 00774 const char *header_encoding, 00775 const svn_string_t *original, 00776 const svn_string_t *modified, 00777 apr_pool_t *pool); 00778 00779 /** Similar to svn_diff_mem_string_output_unified2() but with 00780 * @a with_diff_header always set to TRUE and @a hunk_delimiter always 00781 * set to NULL. 00782 * 00783 * @since New in 1.5. 00784 */ 00785 svn_error_t * 00786 svn_diff_mem_string_output_unified(svn_stream_t *output_stream, 00787 svn_diff_t *diff, 00788 const char *original_header, 00789 const char *modified_header, 00790 const char *header_encoding, 00791 const svn_string_t *original, 00792 const svn_string_t *modified, 00793 apr_pool_t *pool); 00794 00795 /** Output the @a diff generated by svn_diff_mem_string_diff3() in diff3 00796 * format on @a output_stream, using @a original, @a modified and @a latest 00797 * for content changes. 00798 * 00799 * Use the conflict markers @a conflict_original, @a conflict_modified, 00800 * @a conflict_latest and @a conflict_separator or the default one for 00801 * each of these if @c NULL is passed. 00802 * 00803 * @a conflict_style dictates how conflicts are displayed. 00804 * 00805 * @since New in 1.6. 00806 */ 00807 svn_error_t * 00808 svn_diff_mem_string_output_merge2(svn_stream_t *output_stream, 00809 svn_diff_t *diff, 00810 const svn_string_t *original, 00811 const svn_string_t *modified, 00812 const svn_string_t *latest, 00813 const char *conflict_original, 00814 const char *conflict_modified, 00815 const char *conflict_latest, 00816 const char *conflict_separator, 00817 svn_diff_conflict_display_style_t style, 00818 apr_pool_t *pool); 00819 00820 /** Similar to svn_diff_mem_string_output_merge2, but with @a 00821 * display_original_in_conflict and @a display_resolved_conflicts 00822 * booleans instead of the @a conflict_style enum. 00823 * 00824 * If both booleans are false, acts like 00825 * svn_diff_conflict_display_modified_latest; if @a 00826 * display_original_in_conflict is true, acts like 00827 * svn_diff_conflict_display_modified_original_latest; if @a 00828 * display_resolved_conflicts is true, acts like 00829 * svn_diff_conflict_display_resolved_modified_latest. The booleans 00830 * may not both be true. 00831 * 00832 * @deprecated Provided for backward compatibility with the 1.5 API. 00833 */ 00834 SVN_DEPRECATED 00835 svn_error_t * 00836 svn_diff_mem_string_output_merge(svn_stream_t *output_stream, 00837 svn_diff_t *diff, 00838 const svn_string_t *original, 00839 const svn_string_t *modified, 00840 const svn_string_t *latest, 00841 const char *conflict_original, 00842 const char *conflict_modified, 00843 const char *conflict_latest, 00844 const char *conflict_separator, 00845 svn_boolean_t display_original_in_conflict, 00846 svn_boolean_t display_resolved_conflicts, 00847 apr_pool_t *pool); 00848 00849 00850 00851 /* Diff parsing. If you want to apply a patch to a working copy 00852 * rather than parse it, see svn_client_patch(). */ 00853 00854 /** 00855 * Describes what operation has been performed on a file. 00856 * 00857 * @since New in 1.7. 00858 */ 00859 typedef enum svn_diff_operation_kind_e 00860 { 00861 svn_diff_op_unchanged, 00862 svn_diff_op_added, 00863 svn_diff_op_deleted, 00864 svn_diff_op_copied, 00865 svn_diff_op_moved, 00866 /* There's no tree changes, just text modifications. */ 00867 svn_diff_op_modified 00868 } svn_diff_operation_kind_t; 00869 00870 /** 00871 * A single hunk inside a patch. 00872 * 00873 * The lines of text comprising the hunk can be interpreted in three ways: 00874 * - diff text The hunk as it appears in the unidiff patch file, 00875 * including the hunk header line ("@@ ... @@") 00876 * - original text The text the patch was based on. 00877 * - modified text The result of patching the original text. 00878 * 00879 * For example, consider a hunk with the following diff text: 00880 * 00881 * @verbatim 00882 @@ -1,5 +1,5 @@ 00883 #include <stdio.h> 00884 int main(int argc, char *argv[]) { 00885 - printf("Hello World!\n"); 00886 + printf("I like Subversion!\n"); 00887 } @endverbatim 00888 * 00889 * The original text of this hunk is: 00890 * 00891 * @verbatim 00892 #include <stdio.h> 00893 int main(int argc, char *argv[]) { 00894 printf("Hello World!\n"); 00895 } @endverbatim 00896 * 00897 * And the modified text is: 00898 * 00899 * @verbatim 00900 #include <stdio.h> 00901 int main(int argc, char *argv[]) { 00902 printf("I like Subversion!\n"); 00903 } @endverbatim 00904 * 00905 * @see svn_diff_hunk_readline_diff_text() 00906 * @see svn_diff_hunk_readline_original_text() 00907 * @see svn_diff_hunk_readline_modified_text() 00908 * 00909 * @since New in 1.7. */ 00910 typedef struct svn_diff_hunk_t svn_diff_hunk_t; 00911 00912 /** 00913 * Allocate @a *stringbuf in @a result_pool, and read into it one line 00914 * of the diff text of @a hunk. The first line returned is the hunk header. 00915 * Any subsequent lines are unidiff data (starting with '+', '-', or ' '). 00916 * If the @a hunk is being interpreted in reverse (i.e. the reverse 00917 * parameter of svn_diff_parse_next_patch() was @c TRUE), the diff 00918 * text will be returned in reversed form. 00919 * The line-terminator is detected automatically and stored in @a *eol 00920 * if @a eol is not NULL. 00921 * If EOF is reached, set @a *eof to TRUE, and set @a *eol to NULL if the 00922 * hunk does not end with a newline character and @a eol is not NULL. 00923 * Temporary allocations will be performed in @a scratch_pool. 00924 * 00925 * @since New in 1.7. 00926 */ 00927 svn_error_t * 00928 svn_diff_hunk_readline_diff_text(svn_diff_hunk_t *hunk, 00929 svn_stringbuf_t **stringbuf, 00930 const char **eol, 00931 svn_boolean_t *eof, 00932 apr_pool_t *result_pool, 00933 apr_pool_t *scratch_pool); 00934 00935 /** 00936 * Allocate @a *stringbuf in @a result_pool, and read into it one line 00937 * of the original text of @a hunk. 00938 * The line-terminator is detected automatically and stored in @a *eol 00939 * if @a eol is not NULL. 00940 * If EOF is reached, set @a *eof to TRUE, and set @a *eol to NULL if the 00941 * hunk text does not end with a newline character and @a eol is not NULL. 00942 * Temporary allocations will be performed in @a scratch_pool. 00943 * 00944 * @see svn_diff_hunk_t 00945 * @since New in 1.7. 00946 */ 00947 svn_error_t * 00948 svn_diff_hunk_readline_original_text(svn_diff_hunk_t *hunk, 00949 svn_stringbuf_t **stringbuf, 00950 const char **eol, 00951 svn_boolean_t *eof, 00952 apr_pool_t *result_pool, 00953 apr_pool_t *scratch_pool); 00954 00955 /** 00956 * Like svn_diff_hunk_readline_original_text(), but it returns lines from 00957 * the modified text of the hunk. 00958 * 00959 * @see svn_diff_hunk_t 00960 * @since New in 1.7. 00961 */ 00962 svn_error_t * 00963 svn_diff_hunk_readline_modified_text(svn_diff_hunk_t *hunk, 00964 svn_stringbuf_t **stringbuf, 00965 const char **eol, 00966 svn_boolean_t *eof, 00967 apr_pool_t *result_pool, 00968 apr_pool_t *scratch_pool); 00969 00970 /** Reset the diff text of @a hunk so it can be read again from the start. 00971 * @since New in 1.7. */ 00972 void 00973 svn_diff_hunk_reset_diff_text(svn_diff_hunk_t *hunk); 00974 00975 /** Reset the original text of @a hunk so it can be read again from the start. 00976 * @since New in 1.7. */ 00977 void 00978 svn_diff_hunk_reset_original_text(svn_diff_hunk_t *hunk); 00979 00980 /** Reset the modified text of @a hunk so it can be read again from the start. 00981 * @since New in 1.7. */ 00982 void 00983 svn_diff_hunk_reset_modified_text(svn_diff_hunk_t *hunk); 00984 00985 /** Return the line offset of the original hunk text, 00986 * as parsed from the hunk header. 00987 * @since New in 1.7. */ 00988 svn_linenum_t 00989 svn_diff_hunk_get_original_start(const svn_diff_hunk_t *hunk); 00990 00991 /** Return the number of lines in the original @a hunk text, 00992 * as parsed from the hunk header. 00993 * @since New in 1.7. */ 00994 svn_linenum_t 00995 svn_diff_hunk_get_original_length(const svn_diff_hunk_t *hunk); 00996 00997 /** Return the line offset of the modified @a hunk text, 00998 * as parsed from the hunk header. 00999 * @since New in 1.7. */ 01000 svn_linenum_t 01001 svn_diff_hunk_get_modified_start(const svn_diff_hunk_t *hunk); 01002 01003 /** Return the number of lines in the modified @a hunk text, 01004 * as parsed from the hunk header. 01005 * @since New in 1.7. */ 01006 svn_linenum_t 01007 svn_diff_hunk_get_modified_length(const svn_diff_hunk_t *hunk); 01008 01009 /** Return the number of lines of leading context of @a hunk, 01010 * i.e. the number of lines starting with ' ' before the first line 01011 * that starts with a '+' or '-'. 01012 * @since New in 1.7. */ 01013 svn_linenum_t 01014 svn_diff_hunk_get_leading_context(const svn_diff_hunk_t *hunk); 01015 01016 /** Return the number of lines of trailing context of @a hunk, 01017 * i.e. the number of lines starting with ' ' after the last line 01018 * that starts with a '+' or '-'. 01019 * @since New in 1.7. */ 01020 svn_linenum_t 01021 svn_diff_hunk_get_trailing_context(const svn_diff_hunk_t *hunk); 01022 01023 /** 01024 * Data type to manage parsing of properties in patches. 01025 * API users should not allocate structures of this type directly. 01026 * 01027 * @since New in 1.7. */ 01028 typedef struct svn_prop_patch_t { 01029 const char *name; 01030 01031 /** Represents the operation performed on the property */ 01032 svn_diff_operation_kind_t operation; 01033 01034 /** 01035 * An array containing an svn_diff_hunk_t object for each hunk parsed 01036 * from the patch associated with our property name */ 01037 apr_array_header_t *hunks; 01038 } svn_prop_patch_t; 01039 01040 /** 01041 * Data type to manage parsing of patches. 01042 * API users should not allocate structures of this type directly. 01043 * 01044 * @since New in 1.7. */ 01045 typedef struct svn_patch_t { 01046 /** 01047 * The old and new file names as retrieved from the patch file. 01048 * These paths are UTF-8 encoded and canonicalized, but otherwise 01049 * left unchanged from how they appeared in the patch file. */ 01050 const char *old_filename; 01051 const char *new_filename; 01052 01053 /** 01054 * An array containing an svn_diff_hunk_t * for each hunk parsed 01055 * from the patch. */ 01056 apr_array_header_t *hunks; 01057 01058 /** 01059 * A hash table keyed by property names containing svn_prop_patch_t 01060 * object for each property parsed from the patch. */ 01061 apr_hash_t *prop_patches; 01062 01063 /** 01064 * Represents the operation performed on the file. */ 01065 svn_diff_operation_kind_t operation; 01066 01067 /** 01068 * Indicates whether the patch is being interpreted in reverse. */ 01069 svn_boolean_t reverse; 01070 } svn_patch_t; 01071 01072 /** An opaque type representing an open patch file. 01073 * 01074 * @since New in 1.7. */ 01075 typedef struct svn_patch_file_t svn_patch_file_t; 01076 01077 /** Open @a patch_file at @a local_abspath. 01078 * Allocate @a patch_file in @a result_pool. 01079 * 01080 * @since New in 1.7. */ 01081 svn_error_t * 01082 svn_diff_open_patch_file(svn_patch_file_t **patch_file, 01083 const char *local_abspath, 01084 apr_pool_t *result_pool); 01085 01086 /** 01087 * Return the next @a *patch in @a patch_file. 01088 * If no patch can be found, set @a *patch to NULL. 01089 * If @a reverse is TRUE, invert the patch while parsing it. 01090 * If @a ignore_whitespace is TRUE, allow patches with no leading 01091 * whitespace to be parsed. 01092 * Allocate results in @a result_pool. 01093 * Use @a scratch_pool for all other allocations. 01094 * 01095 * @since New in 1.7. */ 01096 svn_error_t * 01097 svn_diff_parse_next_patch(svn_patch_t **patch, 01098 svn_patch_file_t *patch_file, 01099 svn_boolean_t reverse, 01100 svn_boolean_t ignore_whitespace, 01101 apr_pool_t *result_pool, 01102 apr_pool_t *scratch_pool); 01103 01104 /** 01105 * Dispose of @a patch_file. 01106 * Use @a scratch_pool for all temporary allocations. 01107 * 01108 * @since New in 1.7. 01109 */ 01110 svn_error_t * 01111 svn_diff_close_patch_file(svn_patch_file_t *patch_file, 01112 apr_pool_t *scratch_pool); 01113 01114 #ifdef __cplusplus 01115 } 01116 #endif /* __cplusplus */ 01117 01118 #endif /* SVN_DIFF_H */