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 * @since New in 1.9. 00412 */ 00413 svn_error_t * 00414 svn_diff_output2(svn_diff_t *diff, 00415 void *output_baton, 00416 const svn_diff_output_fns_t *output_fns, 00417 svn_cancel_func_t cancel_func, 00418 void *cancel_baton); 00419 00420 /** Similar to svn_diff_output2(), but without cancel support. 00421 * 00422 * @deprecated Provided for backwards compatibility with the 1.8 API. 00423 */ 00424 SVN_DEPRECATED 00425 svn_error_t * 00426 svn_diff_output(svn_diff_t *diff, 00427 void *output_baton, 00428 const svn_diff_output_fns_t *output_fns); 00429 00430 00431 00432 /* Diffs on files */ 00433 00434 /** To what extent whitespace should be ignored when comparing lines. 00435 * 00436 * @since New in 1.4. 00437 */ 00438 typedef enum svn_diff_file_ignore_space_t 00439 { 00440 /** Ignore no whitespace. */ 00441 svn_diff_file_ignore_space_none, 00442 00443 /** Ignore changes in sequences of whitespace characters, treating each 00444 * sequence of whitespace characters as a single space. */ 00445 svn_diff_file_ignore_space_change, 00446 00447 /** Ignore all whitespace characters. */ 00448 svn_diff_file_ignore_space_all 00449 } svn_diff_file_ignore_space_t; 00450 00451 /** Options to control the behaviour of the file diff routines. 00452 * 00453 * @since New in 1.4. 00454 * 00455 * @note This structure may be extended in the future, so to preserve binary 00456 * compatibility, users must not allocate structs of this type themselves. 00457 * @see svn_diff_file_options_create(). 00458 * 00459 * @note Although its name suggests otherwise, this structure is used to 00460 * pass options to file as well as in-memory diff functions. 00461 */ 00462 typedef struct svn_diff_file_options_t 00463 { 00464 /** To what extent whitespace should be ignored when comparing lines. 00465 * The default is @c svn_diff_file_ignore_space_none. */ 00466 svn_diff_file_ignore_space_t ignore_space; 00467 /** Whether to treat all end-of-line markers the same when comparing lines. 00468 * The default is @c FALSE. */ 00469 svn_boolean_t ignore_eol_style; 00470 /** Whether the "@@" lines of the unified diff output should include a prefix 00471 * of the nearest preceding line that starts with a character that might be 00472 * the initial character of a C language identifier. The default is 00473 * @c FALSE. 00474 */ 00475 svn_boolean_t show_c_function; 00476 } svn_diff_file_options_t; 00477 00478 /** Allocate a @c svn_diff_file_options_t structure in @a pool, initializing 00479 * it with default values. 00480 * 00481 * @since New in 1.4. 00482 */ 00483 svn_diff_file_options_t * 00484 svn_diff_file_options_create(apr_pool_t *pool); 00485 00486 /** 00487 * Parse @a args, an array of <tt>const char *</tt> command line switches 00488 * and adjust @a options accordingly. @a options is assumed to be initialized 00489 * with default values. @a pool is used for temporary allocation. 00490 * 00491 * @since New in 1.4. 00492 * 00493 * The following options are supported: 00494 * - --ignore-space-change, -b 00495 * - --ignore-all-space, -w 00496 * - --ignore-eol-style 00497 * - --show-c-function, -p @since New in 1.5. 00498 * - --unified, -u (for compatibility, does nothing). 00499 */ 00500 svn_error_t * 00501 svn_diff_file_options_parse(svn_diff_file_options_t *options, 00502 const apr_array_header_t *args, 00503 apr_pool_t *pool); 00504 00505 00506 /** A convenience function to produce a diff between two files. 00507 * 00508 * @since New in 1.4. 00509 * 00510 * Return a diff object in @a *diff (allocated from @a pool) that represents 00511 * the difference between an @a original file and @a modified file. 00512 * (The file arguments must be full paths to the files.) 00513 * 00514 * Compare lines according to the relevant fields of @a options. 00515 */ 00516 svn_error_t * 00517 svn_diff_file_diff_2(svn_diff_t **diff, 00518 const char *original, 00519 const char *modified, 00520 const svn_diff_file_options_t *options, 00521 apr_pool_t *pool); 00522 00523 /** Similar to svn_file_diff_2(), but with @a options set to a struct with 00524 * default options. 00525 * 00526 * @deprecated Provided for backwards compatibility with the 1.3 API. 00527 */ 00528 SVN_DEPRECATED 00529 svn_error_t * 00530 svn_diff_file_diff(svn_diff_t **diff, 00531 const char *original, 00532 const char *modified, 00533 apr_pool_t *pool); 00534 00535 /** A convenience function to produce a diff between three files. 00536 * 00537 * @since New in 1.4. 00538 * 00539 * Return a diff object in @a *diff (allocated from @a pool) that represents 00540 * the difference between an @a original file, @a modified file, and @a latest 00541 * file. 00542 * 00543 * Compare lines according to the relevant fields of @a options. 00544 */ 00545 svn_error_t * 00546 svn_diff_file_diff3_2(svn_diff_t **diff, 00547 const char *original, 00548 const char *modified, 00549 const char *latest, 00550 const svn_diff_file_options_t *options, 00551 apr_pool_t *pool); 00552 00553 /** Similar to svn_diff_file_diff3_2(), but with @a options set to a struct 00554 * with default options. 00555 * 00556 * @deprecated Provided for backwards compatibility with the 1.3 API. 00557 */ 00558 SVN_DEPRECATED 00559 svn_error_t * 00560 svn_diff_file_diff3(svn_diff_t **diff, 00561 const char *original, 00562 const char *modified, 00563 const char *latest, 00564 apr_pool_t *pool); 00565 00566 /** A convenience function to produce a diff between four files. 00567 * 00568 * @since New in 1.4. 00569 * 00570 * Return a diff object in @a *diff (allocated from @a pool) that represents 00571 * the difference between an @a original file, @a modified file, @a latest 00572 * and @a ancestor file. (The file arguments must be full paths to the files.) 00573 * 00574 * Compare lines according to the relevant fields of @a options. 00575 */ 00576 svn_error_t * 00577 svn_diff_file_diff4_2(svn_diff_t **diff, 00578 const char *original, 00579 const char *modified, 00580 const char *latest, 00581 const char *ancestor, 00582 const svn_diff_file_options_t *options, 00583 apr_pool_t *pool); 00584 00585 /** Similar to svn_file_diff4_2(), but with @a options set to a struct with 00586 * default options. 00587 * 00588 * @deprecated Provided for backwards compatibility with the 1.3 API. 00589 */ 00590 SVN_DEPRECATED 00591 svn_error_t * 00592 svn_diff_file_diff4(svn_diff_t **diff, 00593 const char *original, 00594 const char *modified, 00595 const char *latest, 00596 const char *ancestor, 00597 apr_pool_t *pool); 00598 00599 /** A convenience function to produce unified diff output from the 00600 * diff generated by svn_diff_file_diff(). 00601 * 00602 * Output a @a diff between @a original_path and @a modified_path in unified 00603 * context diff format to @a output_stream. Optionally supply 00604 * @a original_header and/or @a modified_header to be displayed in the header 00605 * of the output. If @a original_header or @a modified_header is @c NULL, a 00606 * default header will be displayed, consisting of path and last modified time. 00607 * Output all headers and markers in @a header_encoding. If @a relative_to_dir 00608 * is not @c NULL, the @a original_path and @a modified_path will have the 00609 * @a relative_to_dir stripped from the front of the respective paths. If 00610 * @a relative_to_dir is @c NULL, paths will be not be modified. If 00611 * @a relative_to_dir is not @c NULL but @a relative_to_dir is not a parent 00612 * path of the target, an error is returned. Finally, if @a relative_to_dir 00613 * is a URL, an error will be returned. 00614 * 00615 * @since New in 1.9. 00616 */ 00617 svn_error_t * 00618 svn_diff_file_output_unified4(svn_stream_t *output_stream, 00619 svn_diff_t *diff, 00620 const char *original_path, 00621 const char *modified_path, 00622 const char *original_header, 00623 const char *modified_header, 00624 const char *header_encoding, 00625 const char *relative_to_dir, 00626 svn_boolean_t show_c_function, 00627 svn_cancel_func_t cancel_func, 00628 void *cancel_baton, 00629 apr_pool_t *scratch_pool); 00630 00631 /** Similar to svn_diff_file_output_unified3(), but without cancel 00632 * support. 00633 * 00634 * @since New in 1.5. 00635 * @deprecated Provided for backwards compatibility with the 1.8 API. 00636 */ 00637 SVN_DEPRECATED 00638 svn_error_t * 00639 svn_diff_file_output_unified3(svn_stream_t *output_stream, 00640 svn_diff_t *diff, 00641 const char *original_path, 00642 const char *modified_path, 00643 const char *original_header, 00644 const char *modified_header, 00645 const char *header_encoding, 00646 const char *relative_to_dir, 00647 svn_boolean_t show_c_function, 00648 apr_pool_t *pool); 00649 00650 /** Similar to svn_diff_file_output_unified3(), but with @a relative_to_dir 00651 * set to NULL and @a show_c_function to false. 00652 * 00653 * @deprecated Provided for backwards compatibility with the 1.4 API. 00654 */ 00655 SVN_DEPRECATED 00656 svn_error_t * 00657 svn_diff_file_output_unified2(svn_stream_t *output_stream, 00658 svn_diff_t *diff, 00659 const char *original_path, 00660 const char *modified_path, 00661 const char *original_header, 00662 const char *modified_header, 00663 const char *header_encoding, 00664 apr_pool_t *pool); 00665 00666 /** Similar to svn_diff_file_output_unified2(), but with @a header_encoding 00667 * set to @c APR_LOCALE_CHARSET. 00668 * 00669 * @deprecated Provided for backward compatibility with the 1.2 API. 00670 */ 00671 SVN_DEPRECATED 00672 svn_error_t * 00673 svn_diff_file_output_unified(svn_stream_t *output_stream, 00674 svn_diff_t *diff, 00675 const char *original_path, 00676 const char *modified_path, 00677 const char *original_header, 00678 const char *modified_header, 00679 apr_pool_t *pool); 00680 00681 00682 /** A convenience function to produce diff3 output from the 00683 * diff generated by svn_diff_file_diff3(). 00684 * 00685 * Output a @a diff between @a original_path, @a modified_path and 00686 * @a latest_path in merged format to @a output_stream. Optionally supply 00687 * @a conflict_modified, @a conflict_original, @a conflict_separator and/or 00688 * @a conflict_latest to be displayed as conflict markers in the output. 00689 * If @a conflict_original, @a conflict_modified, @a conflict_latest and/or 00690 * @a conflict_separator is @c NULL, a default marker will be displayed. 00691 * @a conflict_style dictates how conflicts are displayed. 00692 * 00693 * @since New in 1.6. 00694 */ 00695 svn_error_t * 00696 svn_diff_file_output_merge2(svn_stream_t *output_stream, 00697 svn_diff_t *diff, 00698 const char *original_path, 00699 const char *modified_path, 00700 const char *latest_path, 00701 const char *conflict_original, 00702 const char *conflict_modified, 00703 const char *conflict_latest, 00704 const char *conflict_separator, 00705 svn_diff_conflict_display_style_t conflict_style, 00706 apr_pool_t *pool); 00707 00708 00709 /** Similar to svn_diff_file_output_merge2, but with @a 00710 * display_original_in_conflict and @a display_resolved_conflicts 00711 * booleans instead of the @a conflict_style enum. 00712 * 00713 * If both booleans are false, acts like 00714 * svn_diff_conflict_display_modified_latest; if @a 00715 * display_original_in_conflict is true, acts like 00716 * svn_diff_conflict_display_modified_original_latest; if @a 00717 * display_resolved_conflicts is true, acts like 00718 * svn_diff_conflict_display_resolved_modified_latest. The booleans 00719 * may not both be true. 00720 * 00721 * @deprecated Provided for backward compatibility with the 1.5 API. 00722 */ 00723 SVN_DEPRECATED 00724 svn_error_t * 00725 svn_diff_file_output_merge(svn_stream_t *output_stream, 00726 svn_diff_t *diff, 00727 const char *original_path, 00728 const char *modified_path, 00729 const char *latest_path, 00730 const char *conflict_original, 00731 const char *conflict_modified, 00732 const char *conflict_latest, 00733 const char *conflict_separator, 00734 svn_boolean_t display_original_in_conflict, 00735 svn_boolean_t display_resolved_conflicts, 00736 apr_pool_t *pool); 00737 00738 00739 00740 /* Diffs on in-memory structures */ 00741 00742 /** Generate @a diff output from the @a original and @a modified 00743 * in-memory strings. @a diff will be allocated from @a pool. 00744 * 00745 * @since New in 1.5. 00746 */ 00747 svn_error_t * 00748 svn_diff_mem_string_diff(svn_diff_t **diff, 00749 const svn_string_t *original, 00750 const svn_string_t *modified, 00751 const svn_diff_file_options_t *options, 00752 apr_pool_t *pool); 00753 00754 00755 /** Generate @a diff output from the @a original, @a modified and @a latest 00756 * in-memory strings. @a diff will be allocated in @a pool. 00757 * 00758 * @since New in 1.5. 00759 */ 00760 svn_error_t * 00761 svn_diff_mem_string_diff3(svn_diff_t **diff, 00762 const svn_string_t *original, 00763 const svn_string_t *modified, 00764 const svn_string_t *latest, 00765 const svn_diff_file_options_t *options, 00766 apr_pool_t *pool); 00767 00768 00769 /** Generate @a diff output from the @a original, @a modified and @a latest 00770 * in-memory strings, using @a ancestor. @a diff will be allocated in @a pool. 00771 * 00772 * @since New in 1.5. 00773 */ 00774 svn_error_t * 00775 svn_diff_mem_string_diff4(svn_diff_t **diff, 00776 const svn_string_t *original, 00777 const svn_string_t *modified, 00778 const svn_string_t *latest, 00779 const svn_string_t *ancestor, 00780 const svn_diff_file_options_t *options, 00781 apr_pool_t *pool); 00782 00783 /** Outputs the @a diff object generated by svn_diff_mem_string_diff() 00784 * in unified diff format on @a output_stream, using @a original 00785 * and @a modified for the text in the output. 00786 * 00787 * If @a with_diff_header is TRUE, write a diff header ("---" and "+++" 00788 * lines), using @a original_header and @a modified_header to fill the field 00789 * after the "---" and "+++" markers; otherwise @a original_header and 00790 * @a modified_header are ignored and may be NULL. 00791 * 00792 * Outputs the header and hunk delimiters in @a header_encoding. 00793 * A @a hunk_delimiter can optionally be specified. 00794 * If @a hunk_delimiter is NULL, use the default hunk delimiter "@@". 00795 * 00796 * As a special case, if the hunk delimiter is "##", then for an incomplete 00797 * final line use the text "\ No newline at end of property" instead of 00798 * "\ No newline at end of file". 00799 * 00800 * @since New in 1.7. Hunk delimiter "##" has the special meaning since 1.8. 00801 */ 00802 svn_error_t * 00803 svn_diff_mem_string_output_unified2(svn_stream_t *output_stream, 00804 svn_diff_t *diff, 00805 svn_boolean_t with_diff_header, 00806 const char *hunk_delimiter, 00807 const char *original_header, 00808 const char *modified_header, 00809 const char *header_encoding, 00810 const svn_string_t *original, 00811 const svn_string_t *modified, 00812 apr_pool_t *pool); 00813 00814 /** Similar to svn_diff_mem_string_output_unified2() but with 00815 * @a with_diff_header always set to TRUE and @a hunk_delimiter always 00816 * set to NULL. 00817 * 00818 * @since New in 1.5. 00819 */ 00820 svn_error_t * 00821 svn_diff_mem_string_output_unified(svn_stream_t *output_stream, 00822 svn_diff_t *diff, 00823 const char *original_header, 00824 const char *modified_header, 00825 const char *header_encoding, 00826 const svn_string_t *original, 00827 const svn_string_t *modified, 00828 apr_pool_t *pool); 00829 00830 /** Output the @a diff generated by svn_diff_mem_string_diff3() in diff3 00831 * format on @a output_stream, using @a original, @a modified and @a latest 00832 * for content changes. 00833 * 00834 * Use the conflict markers @a conflict_original, @a conflict_modified, 00835 * @a conflict_latest and @a conflict_separator or the default one for 00836 * each of these if @c NULL is passed. 00837 * 00838 * @a conflict_style dictates how conflicts are displayed. 00839 * 00840 * @since New in 1.6. 00841 */ 00842 svn_error_t * 00843 svn_diff_mem_string_output_merge2(svn_stream_t *output_stream, 00844 svn_diff_t *diff, 00845 const svn_string_t *original, 00846 const svn_string_t *modified, 00847 const svn_string_t *latest, 00848 const char *conflict_original, 00849 const char *conflict_modified, 00850 const char *conflict_latest, 00851 const char *conflict_separator, 00852 svn_diff_conflict_display_style_t style, 00853 apr_pool_t *pool); 00854 00855 /** Similar to svn_diff_mem_string_output_merge2, but with @a 00856 * display_original_in_conflict and @a display_resolved_conflicts 00857 * booleans instead of the @a conflict_style enum. 00858 * 00859 * If both booleans are false, acts like 00860 * svn_diff_conflict_display_modified_latest; if @a 00861 * display_original_in_conflict is true, acts like 00862 * svn_diff_conflict_display_modified_original_latest; if @a 00863 * display_resolved_conflicts is true, acts like 00864 * svn_diff_conflict_display_resolved_modified_latest. The booleans 00865 * may not both be true. 00866 * 00867 * @deprecated Provided for backward compatibility with the 1.5 API. 00868 */ 00869 SVN_DEPRECATED 00870 svn_error_t * 00871 svn_diff_mem_string_output_merge(svn_stream_t *output_stream, 00872 svn_diff_t *diff, 00873 const svn_string_t *original, 00874 const svn_string_t *modified, 00875 const svn_string_t *latest, 00876 const char *conflict_original, 00877 const char *conflict_modified, 00878 const char *conflict_latest, 00879 const char *conflict_separator, 00880 svn_boolean_t display_original_in_conflict, 00881 svn_boolean_t display_resolved_conflicts, 00882 apr_pool_t *pool); 00883 00884 00885 00886 /* Diff parsing. If you want to apply a patch to a working copy 00887 * rather than parse it, see svn_client_patch(). */ 00888 00889 /** 00890 * Describes what operation has been performed on a file. 00891 * 00892 * @since New in 1.7. 00893 */ 00894 typedef enum svn_diff_operation_kind_e 00895 { 00896 svn_diff_op_unchanged, 00897 svn_diff_op_added, 00898 svn_diff_op_deleted, 00899 svn_diff_op_copied, 00900 svn_diff_op_moved, 00901 /* There's no tree changes, just text modifications. */ 00902 svn_diff_op_modified 00903 } svn_diff_operation_kind_t; 00904 00905 /** 00906 * A single hunk inside a patch. 00907 * 00908 * The lines of text comprising the hunk can be interpreted in three ways: 00909 * - diff text The hunk as it appears in the unidiff patch file, 00910 * including the hunk header line ("@@ ... @@") 00911 * - original text The text the patch was based on. 00912 * - modified text The result of patching the original text. 00913 * 00914 * For example, consider a hunk with the following diff text: 00915 * 00916 * @verbatim 00917 @@ -1,5 +1,5 @@ 00918 #include <stdio.h> 00919 int main(int argc, char *argv[]) { 00920 - printf("Hello World!\n"); 00921 + printf("I like Subversion!\n"); 00922 } @endverbatim 00923 * 00924 * The original text of this hunk is: 00925 * 00926 * @verbatim 00927 #include <stdio.h> 00928 int main(int argc, char *argv[]) { 00929 printf("Hello World!\n"); 00930 } @endverbatim 00931 * 00932 * And the modified text is: 00933 * 00934 * @verbatim 00935 #include <stdio.h> 00936 int main(int argc, char *argv[]) { 00937 printf("I like Subversion!\n"); 00938 } @endverbatim 00939 * 00940 * @see svn_diff_hunk_readline_diff_text() 00941 * @see svn_diff_hunk_readline_original_text() 00942 * @see svn_diff_hunk_readline_modified_text() 00943 * 00944 * @since New in 1.7. */ 00945 typedef struct svn_diff_hunk_t svn_diff_hunk_t; 00946 00947 /** 00948 * Allocate @a *stringbuf in @a result_pool, and read into it one line 00949 * of the diff text of @a hunk. The hunk header is not returned only the 00950 * unidiff data lines (starting with '+', '-', or ' ') are returned. 00951 * If the @a hunk is being interpreted in reverse (i.e. the reverse 00952 * parameter of svn_diff_parse_next_patch() was @c TRUE), the diff 00953 * text will be returned in reversed form. 00954 * The line-terminator is detected automatically and stored in @a *eol 00955 * if @a eol is not NULL. 00956 * If EOF is reached, set @a *eof to TRUE, and set @a *eol to NULL if the 00957 * hunk does not end with a newline character and @a eol is not NULL. 00958 * Temporary allocations will be performed in @a scratch_pool. 00959 * 00960 * @note The hunk header information can be retrieved with the following 00961 * functions: 00962 * @see svn_diff_hunk_get_original_start() 00963 * @see svn_diff_hunk_get_original_length() 00964 * @see svn_diff_hunk_get_modified_start() 00965 * @see svn_diff_hunk_get_modified_length() 00966 * 00967 * @since New in 1.7. 00968 */ 00969 svn_error_t * 00970 svn_diff_hunk_readline_diff_text(svn_diff_hunk_t *hunk, 00971 svn_stringbuf_t **stringbuf, 00972 const char **eol, 00973 svn_boolean_t *eof, 00974 apr_pool_t *result_pool, 00975 apr_pool_t *scratch_pool); 00976 00977 /** 00978 * Allocate @a *stringbuf in @a result_pool, and read into it one line 00979 * of the original text of @a hunk. 00980 * The line-terminator is detected automatically and stored in @a *eol 00981 * if @a eol is not NULL. 00982 * If EOF is reached, set @a *eof to TRUE, and set @a *eol to NULL if the 00983 * hunk text does not end with a newline character and @a eol is not NULL. 00984 * Temporary allocations will be performed in @a scratch_pool. 00985 * 00986 * @see svn_diff_hunk_t 00987 * @since New in 1.7. 00988 */ 00989 svn_error_t * 00990 svn_diff_hunk_readline_original_text(svn_diff_hunk_t *hunk, 00991 svn_stringbuf_t **stringbuf, 00992 const char **eol, 00993 svn_boolean_t *eof, 00994 apr_pool_t *result_pool, 00995 apr_pool_t *scratch_pool); 00996 00997 /** 00998 * Like svn_diff_hunk_readline_original_text(), but it returns lines from 00999 * the modified text of the hunk. 01000 * 01001 * @see svn_diff_hunk_t 01002 * @since New in 1.7. 01003 */ 01004 svn_error_t * 01005 svn_diff_hunk_readline_modified_text(svn_diff_hunk_t *hunk, 01006 svn_stringbuf_t **stringbuf, 01007 const char **eol, 01008 svn_boolean_t *eof, 01009 apr_pool_t *result_pool, 01010 apr_pool_t *scratch_pool); 01011 01012 /** Reset the diff text of @a hunk so it can be read again from the start. 01013 * @since New in 1.7. */ 01014 void 01015 svn_diff_hunk_reset_diff_text(svn_diff_hunk_t *hunk); 01016 01017 /** Reset the original text of @a hunk so it can be read again from the start. 01018 * @since New in 1.7. */ 01019 void 01020 svn_diff_hunk_reset_original_text(svn_diff_hunk_t *hunk); 01021 01022 /** Reset the modified text of @a hunk so it can be read again from the start. 01023 * @since New in 1.7. */ 01024 void 01025 svn_diff_hunk_reset_modified_text(svn_diff_hunk_t *hunk); 01026 01027 /** Return the line offset of the original hunk text, 01028 * as parsed from the hunk header. 01029 * @since New in 1.7. */ 01030 svn_linenum_t 01031 svn_diff_hunk_get_original_start(const svn_diff_hunk_t *hunk); 01032 01033 /** Return the number of lines in the original @a hunk text, 01034 * as parsed from the hunk header. 01035 * @since New in 1.7. */ 01036 svn_linenum_t 01037 svn_diff_hunk_get_original_length(const svn_diff_hunk_t *hunk); 01038 01039 /** Return the line offset of the modified @a hunk text, 01040 * as parsed from the hunk header. 01041 * @since New in 1.7. */ 01042 svn_linenum_t 01043 svn_diff_hunk_get_modified_start(const svn_diff_hunk_t *hunk); 01044 01045 /** Return the number of lines in the modified @a hunk text, 01046 * as parsed from the hunk header. 01047 * @since New in 1.7. */ 01048 svn_linenum_t 01049 svn_diff_hunk_get_modified_length(const svn_diff_hunk_t *hunk); 01050 01051 /** Return the number of lines of leading context of @a hunk, 01052 * i.e. the number of lines starting with ' ' before the first line 01053 * that starts with a '+' or '-'. 01054 * @since New in 1.7. */ 01055 svn_linenum_t 01056 svn_diff_hunk_get_leading_context(const svn_diff_hunk_t *hunk); 01057 01058 /** Return the number of lines of trailing context of @a hunk, 01059 * i.e. the number of lines starting with ' ' after the last line 01060 * that starts with a '+' or '-'. 01061 * @since New in 1.7. */ 01062 svn_linenum_t 01063 svn_diff_hunk_get_trailing_context(const svn_diff_hunk_t *hunk); 01064 01065 /** 01066 * Data type to manage parsing of properties in patches. 01067 * API users should not allocate structures of this type directly. 01068 * 01069 * @since New in 1.7. */ 01070 typedef struct svn_prop_patch_t { 01071 const char *name; 01072 01073 /** Represents the operation performed on the property */ 01074 svn_diff_operation_kind_t operation; 01075 01076 /** 01077 * An array containing an svn_diff_hunk_t object for each hunk parsed 01078 * from the patch associated with our property name */ 01079 apr_array_header_t *hunks; 01080 } svn_prop_patch_t; 01081 01082 /** 01083 * Data type to manage parsing of patches. 01084 * API users should not allocate structures of this type directly. 01085 * 01086 * @since New in 1.7. */ 01087 typedef struct svn_patch_t { 01088 /** 01089 * The old and new file names as retrieved from the patch file. 01090 * These paths are UTF-8 encoded and canonicalized, but otherwise 01091 * left unchanged from how they appeared in the patch file. */ 01092 const char *old_filename; 01093 const char *new_filename; 01094 01095 /** 01096 * An array containing an svn_diff_hunk_t * for each hunk parsed 01097 * from the patch. */ 01098 apr_array_header_t *hunks; 01099 01100 /** 01101 * A hash table keyed by property names containing svn_prop_patch_t 01102 * object for each property parsed from the patch. */ 01103 apr_hash_t *prop_patches; 01104 01105 /** 01106 * Represents the operation performed on the file. */ 01107 svn_diff_operation_kind_t operation; 01108 01109 /** 01110 * Indicates whether the patch is being interpreted in reverse. */ 01111 svn_boolean_t reverse; 01112 } svn_patch_t; 01113 01114 /** An opaque type representing an open patch file. 01115 * 01116 * @since New in 1.7. */ 01117 typedef struct svn_patch_file_t svn_patch_file_t; 01118 01119 /** Open @a patch_file at @a local_abspath. 01120 * Allocate @a patch_file in @a result_pool. 01121 * 01122 * @since New in 1.7. */ 01123 svn_error_t * 01124 svn_diff_open_patch_file(svn_patch_file_t **patch_file, 01125 const char *local_abspath, 01126 apr_pool_t *result_pool); 01127 01128 /** 01129 * Return the next @a *patch in @a patch_file. 01130 * If no patch can be found, set @a *patch to NULL. 01131 * If @a reverse is TRUE, invert the patch while parsing it. 01132 * If @a ignore_whitespace is TRUE, allow patches with no leading 01133 * whitespace to be parsed. 01134 * Allocate results in @a result_pool. 01135 * Use @a scratch_pool for all other allocations. 01136 * 01137 * @since New in 1.7. */ 01138 svn_error_t * 01139 svn_diff_parse_next_patch(svn_patch_t **patch, 01140 svn_patch_file_t *patch_file, 01141 svn_boolean_t reverse, 01142 svn_boolean_t ignore_whitespace, 01143 apr_pool_t *result_pool, 01144 apr_pool_t *scratch_pool); 01145 01146 /** 01147 * Dispose of @a patch_file. 01148 * Use @a scratch_pool for all temporary allocations. 01149 * 01150 * @since New in 1.7. 01151 */ 01152 svn_error_t * 01153 svn_diff_close_patch_file(svn_patch_file_t *patch_file, 01154 apr_pool_t *scratch_pool); 01155 01156 #ifdef __cplusplus 01157 } 01158 #endif /* __cplusplus */ 01159 01160 #endif /* SVN_DIFF_H */
1.4.7