GME  13
svn_diff.h
Go to the documentation of this file.
00001 
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 
00070 const svn_version_t *
00071 svn_diff_version(void);
00072 
00073 
00074 /* Diffs. */
00075 
00081 typedef struct svn_diff_t svn_diff_t;
00082 
00088 typedef enum svn_diff_datasource_e
00089 {
00091   svn_diff_datasource_original,
00092 
00094   svn_diff_datasource_modified,
00095 
00099   svn_diff_datasource_latest,
00100 
00102   svn_diff_datasource_ancestor
00103 
00104 } svn_diff_datasource_e;
00105 
00106 
00109 typedef struct svn_diff_fns2_t
00110 {
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 
00119   svn_error_t *(*datasource_close)(void *diff_baton,
00120                                    svn_diff_datasource_e datasource);
00121 
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 
00136   svn_error_t *(*token_compare)(void *diff_baton,
00137                                 void *ltoken,
00138                                 void *rtoken,
00139                                 int *compare);
00140 
00142   void (*token_discard)(void *diff_baton,
00143                         void *token);
00144 
00146   void (*token_discard_all)(void *diff_baton);
00147 } svn_diff_fns2_t;
00148 
00149 
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 
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 
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 
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 
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 
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 
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 
00262 svn_boolean_t
00263 svn_diff_contains_conflicts(svn_diff_t *diff);
00264 
00265 
00269 svn_boolean_t
00270 svn_diff_contains_diffs(svn_diff_t *diff);
00271 
00272 
00273 
00274 
00275 /* Displaying Diffs */
00276 
00289 typedef struct svn_diff_output_fns_t
00290 {
00291   /* Two-way and three-way diffs both call the first two output functions: */
00292 
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 
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 
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 
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 
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 
00382 typedef enum svn_diff_conflict_display_style_t
00383 {
00385   svn_diff_conflict_display_modified_latest,
00386 
00390   svn_diff_conflict_display_resolved_modified_latest,
00391 
00394   svn_diff_conflict_display_modified_original_latest,
00395 
00397   svn_diff_conflict_display_modified,
00398 
00400   svn_diff_conflict_display_latest,
00401 
00404   svn_diff_conflict_display_only_conflicts
00405 } svn_diff_conflict_display_style_t;
00406 
00407 
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 
00424 typedef enum svn_diff_file_ignore_space_t
00425 {
00427   svn_diff_file_ignore_space_none,
00428 
00431   svn_diff_file_ignore_space_change,
00432 
00434   svn_diff_file_ignore_space_all
00435 } svn_diff_file_ignore_space_t;
00436 
00448 typedef struct svn_diff_file_options_t
00449 {
00452   svn_diff_file_ignore_space_t ignore_space;
00455   svn_boolean_t ignore_eol_style;
00461   svn_boolean_t show_c_function;
00462 } svn_diff_file_options_t;
00463 
00469 svn_diff_file_options_t *
00470 svn_diff_file_options_create(apr_pool_t *pool);
00471 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
00910 typedef struct svn_diff_hunk_t svn_diff_hunk_t;
00911 
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 
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 
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 
00972 void
00973 svn_diff_hunk_reset_diff_text(svn_diff_hunk_t *hunk);
00974 
00977 void
00978 svn_diff_hunk_reset_original_text(svn_diff_hunk_t *hunk);
00979 
00982 void
00983 svn_diff_hunk_reset_modified_text(svn_diff_hunk_t *hunk);
00984 
00988 svn_linenum_t
00989 svn_diff_hunk_get_original_start(const svn_diff_hunk_t *hunk);
00990 
00994 svn_linenum_t
00995 svn_diff_hunk_get_original_length(const svn_diff_hunk_t *hunk);
00996 
01000 svn_linenum_t
01001 svn_diff_hunk_get_modified_start(const svn_diff_hunk_t *hunk);
01002 
01006 svn_linenum_t
01007 svn_diff_hunk_get_modified_length(const svn_diff_hunk_t *hunk);
01008 
01013 svn_linenum_t
01014 svn_diff_hunk_get_leading_context(const svn_diff_hunk_t *hunk);
01015 
01020 svn_linenum_t
01021 svn_diff_hunk_get_trailing_context(const svn_diff_hunk_t *hunk);
01022 
01028 typedef struct svn_prop_patch_t {
01029   const char *name;
01030 
01032   svn_diff_operation_kind_t operation;
01033 
01037   apr_array_header_t *hunks;
01038 } svn_prop_patch_t;
01039 
01045 typedef struct svn_patch_t {
01050   const char *old_filename;
01051   const char *new_filename;
01052 
01056   apr_array_header_t *hunks;
01057 
01061   apr_hash_t *prop_patches;
01062 
01065   svn_diff_operation_kind_t operation;
01066 
01069   svn_boolean_t reverse;
01070 } svn_patch_t;
01071 
01075 typedef struct svn_patch_file_t svn_patch_file_t;
01076 
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 
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 
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 */