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