Subversion
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
svn_diff.h
Go to the documentation of this file.
1 /**
2  * @copyright
3  * ====================================================================
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements. See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership. The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License. You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied. See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  * ====================================================================
21  * @endcopyright
22  *
23  * @file svn_diff.h
24  * @brief Contextual diffing.
25  *
26  * This is an internalized library for performing contextual diffs
27  * between sources of data.
28  *
29  * @note This is different than Subversion's binary-diffing engine.
30  * That API lives in @c svn_delta.h -- see the "text deltas" section. A
31  * "text delta" is way of representing precise binary diffs between
32  * strings of data. The Subversion client and server send text deltas
33  * to one another during updates and commits.
34  *
35  * This API, however, is (or will be) used for performing *contextual*
36  * merges between files in the working copy. During an update or
37  * merge, 3-way file merging is needed. And 'svn diff' needs to show
38  * the differences between 2 files.
39  *
40  * The nice thing about this API is that it's very general. It
41  * operates on any source of data (a "datasource") and calculates
42  * contextual differences on "tokens" within the data. In our
43  * particular usage, the datasources are files and the tokens are
44  * lines. But the possibilities are endless.
45  */
46 
47 
48 #ifndef SVN_DIFF_H
49 #define SVN_DIFF_H
50 
51 #include <apr.h>
52 #include <apr_pools.h>
53 #include <apr_tables.h> /* for apr_array_header_t */
54 
55 #include "svn_types.h"
56 #include "svn_io.h" /* for svn_stream_t */
57 #include "svn_string.h"
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif /* __cplusplus */
62 
63 
64 
65 /**
66  * Get libsvn_diff version information.
67  *
68  * @since New in 1.1.
69  */
70 const svn_version_t *
71 svn_diff_version(void);
72 
73 
74 /* Diffs. */
75 
76 /** An opaque type that represents a difference between either two or
77  * three datasources. This object is returned by svn_diff_diff(),
78  * svn_diff_diff3() and svn_diff_diff4(), and consumed by a number of
79  * other routines.
80  */
81 typedef struct svn_diff_t svn_diff_t;
82 
83 /**
84  * There are four types of datasources. In GNU diff3 terminology,
85  * the first three types correspond to the phrases "older", "mine",
86  * and "yours".
87  */
89 {
90  /** The oldest form of the data. */
92 
93  /** The same data, but potentially changed by the user. */
95 
96  /** The latest version of the data, possibly different than the
97  * user's modified version.
98  */
100 
101  /** The common ancestor of original and modified. */
103 
105 
106 
107 /** A vtable for reading data from the three datasources.
108  * @since New in 1.7. */
109 typedef struct svn_diff_fns2_t
110 {
111  /** Open the datasources of type @a datasources. */
112  svn_error_t *(*datasources_open)(void *diff_baton,
113  apr_off_t *prefix_lines,
114  apr_off_t *suffix_lines,
115  const svn_diff_datasource_e *datasources,
116  apr_size_t datasources_len);
117 
118  /** Close the datasource of type @a datasource. */
119  svn_error_t *(*datasource_close)(void *diff_baton,
120  svn_diff_datasource_e datasource);
121 
122  /** Get the next "token" from the datasource of type @a datasource.
123  * Return a "token" in @a *token. Return a hash of "token" in @a *hash.
124  * Leave @a token and @a hash untouched when the datasource is exhausted.
125  */
126  svn_error_t *(*datasource_get_next_token)(apr_uint32_t *hash, void **token,
127  void *diff_baton,
128  svn_diff_datasource_e datasource);
129 
130  /** A function for ordering the tokens, resembling 'strcmp' in functionality.
131  * @a compare should contain the return value of the comparison:
132  * If @a ltoken and @a rtoken are "equal", return 0. If @a ltoken is
133  * "less than" @a rtoken, return a number < 0. If @a ltoken is
134  * "greater than" @a rtoken, return a number > 0.
135  */
136  svn_error_t *(*token_compare)(void *diff_baton,
137  void *ltoken,
138  void *rtoken,
139  int *compare);
140 
141  /** Free @a token from memory, the diff algorithm is done with it. */
142  void (*token_discard)(void *diff_baton,
143  void *token);
144 
145  /** Free *all* tokens from memory, they're no longer needed. */
146  void (*token_discard_all)(void *diff_baton);
148 
149 
150 /** Like #svn_diff_fns2_t except with datasource_open() instead of
151  * datasources_open().
152  *
153  * @deprecated Provided for backward compatibility with the 1.6 API.
154  */
155 typedef struct svn_diff_fns_t
156 {
157  svn_error_t *(*datasource_open)(void *diff_baton,
158  svn_diff_datasource_e datasource);
159 
160  svn_error_t *(*datasource_close)(void *diff_baton,
161  svn_diff_datasource_e datasource);
162 
163  svn_error_t *(*datasource_get_next_token)(apr_uint32_t *hash, void **token,
164  void *diff_baton,
165  svn_diff_datasource_e datasource);
166 
167  svn_error_t *(*token_compare)(void *diff_baton,
168  void *ltoken,
169  void *rtoken,
170  int *compare);
171 
172  void (*token_discard)(void *diff_baton,
173  void *token);
174 
175  void (*token_discard_all)(void *diff_baton);
177 
178 
179 /* The Main Events */
180 
181 /** Given a vtable of @a diff_fns/@a diff_baton for reading datasources,
182  * return a diff object in @a *diff that represents a difference between
183  * an "original" and "modified" datasource. Do all allocation in @a pool.
184  *
185  * @since New in 1.7.
186  */
187 svn_error_t *
189  void *diff_baton,
190  const svn_diff_fns2_t *diff_fns,
191  apr_pool_t *pool);
192 
193 /** Like svn_diff_diff_2() but using #svn_diff_fns_t instead of
194  * #svn_diff_fns2_t.
195  *
196  * @deprecated Provided for backward compatibility with the 1.6 API.
197  */
199 svn_error_t *
201  void *diff_baton,
202  const svn_diff_fns_t *diff_fns,
203  apr_pool_t *pool);
204 
205 /** Given a vtable of @a diff_fns/@a diff_baton for reading datasources,
206  * return a diff object in @a *diff that represents a difference between
207  * three datasources: "original", "modified", and "latest". Do all
208  * allocation in @a pool.
209  *
210  * @since New in 1.7.
211  */
212 svn_error_t *
214  void *diff_baton,
215  const svn_diff_fns2_t *diff_fns,
216  apr_pool_t *pool);
217 
218 /** Like svn_diff_diff3_2() but using #svn_diff_fns_t instead of
219  * #svn_diff_fns2_t.
220  *
221  * @deprecated Provided for backward compatibility with the 1.6 API.
222  */
224 svn_error_t *
226  void *diff_baton,
227  const svn_diff_fns_t *diff_fns,
228  apr_pool_t *pool);
229 
230 /** Given a vtable of @a diff_fns/@a diff_baton for reading datasources,
231  * return a diff object in @a *diff that represents a difference between
232  * two datasources: "original" and "latest", adjusted to become a full
233  * difference between "original", "modified" and "latest" using "ancestor".
234  * Do all allocation in @a pool.
235  *
236  * @since New in 1.7.
237  */
238 svn_error_t *
240  void *diff_baton,
241  const svn_diff_fns2_t *diff_fns,
242  apr_pool_t *pool);
243 
244 /** Like svn_diff_diff4_2() but using #svn_diff_fns_t instead of
245  * #svn_diff_fns2_t.
246  *
247  * @deprecated Provided for backward compatibility with the 1.6 API.
248  */
250 svn_error_t *
252  void *diff_baton,
253  const svn_diff_fns_t *diff_fns,
254  apr_pool_t *pool);
255 
256 
257 /* Utility functions */
258 
259 /** Determine if a diff object contains conflicts. If it does, return
260  * @c TRUE, else return @c FALSE.
261  */
264 
265 
266 /** Determine if a diff object contains actual differences between the
267  * datasources. If so, return @c TRUE, else return @c FALSE.
268  */
271 
272 
273 
274 
275 /* Displaying Diffs */
276 
277 /** A vtable for displaying (or consuming) differences between datasources.
278  *
279  * Differences, similarities, and conflicts are described by lining up
280  * "ranges" of data.
281  *
282  * @note These callbacks describe data ranges in units of "tokens".
283  * A "token" is whatever you've defined it to be in your datasource
284  * @c svn_diff_fns_t vtable.
285  */
286 typedef struct svn_diff_output_fns_t
287 {
288  /* Two-way and three-way diffs both call the first two output functions: */
289 
290  /**
291  * If doing a two-way diff, then an *identical* data range was found
292  * between the "original" and "modified" datasources. Specifically,
293  * the match starts at @a original_start and goes for @a original_length
294  * tokens in the original data, and at @a modified_start for
295  * @a modified_length tokens in the modified data.
296  *
297  * If doing a three-way diff, then all three datasources have
298  * matching data ranges. The range @a latest_start, @a latest_length in
299  * the "latest" datasource is identical to the range @a original_start,
300  * @a original_length in the original data, and is also identical to
301  * the range @a modified_start, @a modified_length in the modified data.
302  */
303  svn_error_t *(*output_common)(void *output_baton,
304  apr_off_t original_start,
305  apr_off_t original_length,
306  apr_off_t modified_start,
307  apr_off_t modified_length,
308  apr_off_t latest_start,
309  apr_off_t latest_length);
310 
311  /**
312  * If doing a two-way diff, then an *conflicting* data range was found
313  * between the "original" and "modified" datasources. Specifically,
314  * the conflict starts at @a original_start and goes for @a original_length
315  * tokens in the original data, and at @a modified_start for
316  * @a modified_length tokens in the modified data.
317  *
318  * If doing a three-way diff, then an identical data range was discovered
319  * between the "original" and "latest" datasources, but this conflicts with
320  * a range in the "modified" datasource.
321  */
322  svn_error_t *(*output_diff_modified)(void *output_baton,
323  apr_off_t original_start,
324  apr_off_t original_length,
325  apr_off_t modified_start,
326  apr_off_t modified_length,
327  apr_off_t latest_start,
328  apr_off_t latest_length);
329 
330  /* ------ The following callbacks are used by three-way diffs only --- */
331 
332  /** An identical data range was discovered between the "original" and
333  * "modified" datasources, but this conflicts with a range in the
334  * "latest" datasource.
335  */
336  svn_error_t *(*output_diff_latest)(void *output_baton,
337  apr_off_t original_start,
338  apr_off_t original_length,
339  apr_off_t modified_start,
340  apr_off_t modified_length,
341  apr_off_t latest_start,
342  apr_off_t latest_length);
343 
344  /** An identical data range was discovered between the "modified" and
345  * "latest" datasources, but this conflicts with a range in the
346  * "original" datasource.
347  */
348  svn_error_t *(*output_diff_common)(void *output_baton,
349  apr_off_t original_start,
350  apr_off_t original_length,
351  apr_off_t modified_start,
352  apr_off_t modified_length,
353  apr_off_t latest_start,
354  apr_off_t latest_length);
355 
356  /** All three datasources have conflicting data ranges. The range
357  * @a latest_start, @a latest_length in the "latest" datasource conflicts
358  * with the range @a original_start, @a original_length in the "original"
359  * datasource, and also conflicts with the range @a modified_start,
360  * @a modified_length in the "modified" datasource.
361  * If there are common ranges in the "modified" and "latest" datasources
362  * in this conflicting range, @a resolved_diff will contain a diff
363  * which can be used to retrieve the common and conflicting ranges.
364  */
365  svn_error_t *(*output_conflict)(void *output_baton,
366  apr_off_t original_start,
367  apr_off_t original_length,
368  apr_off_t modified_start,
369  apr_off_t modified_length,
370  apr_off_t latest_start,
371  apr_off_t latest_length,
372  svn_diff_t *resolved_diff);
374 
375 /** Style for displaying conflicts during diff3 output.
376  *
377  * @since New in 1.6.
378  */
380 {
381  /** Display modified and latest, with conflict markers. */
383 
384  /** Like svn_diff_conflict_display_modified_latest, but with an
385  extra effort to identify common sequences between modified and
386  latest. */
388 
389  /** Display modified, original, and latest, with conflict
390  markers. */
392 
393  /** Just display modified, with no markers. */
395 
396  /** Just display latest, with no markers. */
398 
399  /** Like svn_diff_conflict_display_modified_original_latest, but
400  *only* showing conflicts. */
403 
404 
405 /** Given a vtable of @a output_fns/@a output_baton for consuming
406  * differences, output the differences in @a diff.
407  */
408 svn_error_t *
410  void *output_baton,
411  const svn_diff_output_fns_t *output_fns);
412 
413 
414 
415 /* Diffs on files */
416 
417 /** To what extent whitespace should be ignored when comparing lines.
418  *
419  * @since New in 1.4.
420  */
422 {
423  /** Ignore no whitespace. */
425 
426  /** Ignore changes in sequences of whitespace characters, treating each
427  * sequence of whitespace characters as a single space. */
429 
430  /** Ignore all whitespace characters. */
433 
434 /** Options to control the behaviour of the file diff routines.
435  *
436  * @since New in 1.4.
437  *
438  * @note This structure may be extended in the future, so to preserve binary
439  * compatibility, users must not allocate structs of this type themselves.
440  * @see svn_diff_file_options_create().
441  *
442  * @note Although its name suggests otherwise, this structure is used to
443  * pass options to file as well as in-memory diff functions.
444  */
446 {
447  /** To what extent whitespace should be ignored when comparing lines.
448  * The default is @c svn_diff_file_ignore_space_none. */
450  /** Whether to treat all end-of-line markers the same when comparing lines.
451  * The default is @c FALSE. */
453  /** Whether the "@@" lines of the unified diff output should include a prefix
454  * of the nearest preceding line that starts with a character that might be
455  * the initial character of a C language identifier. The default is
456  * @c FALSE.
457  */
460 
461 /** Allocate a @c svn_diff_file_options_t structure in @a pool, initializing
462  * it with default values.
463  *
464  * @since New in 1.4.
465  */
467 svn_diff_file_options_create(apr_pool_t *pool);
468 
469 /**
470  * Parse @a args, an array of <tt>const char *</tt> command line switches
471  * and adjust @a options accordingly. @a options is assumed to be initialized
472  * with default values. @a pool is used for temporary allocation.
473  *
474  * @since New in 1.4.
475  *
476  * The following options are supported:
477  * - --ignore-space-change, -b
478  * - --ignore-all-space, -w
479  * - --ignore-eol-style
480  * - --unified, -u (for compatibility, does nothing).
481  */
482 svn_error_t *
484  const apr_array_header_t *args,
485  apr_pool_t *pool);
486 
487 
488 /** A convenience function to produce a diff between two files.
489  *
490  * @since New in 1.4.
491  *
492  * Return a diff object in @a *diff (allocated from @a pool) that represents
493  * the difference between an @a original file and @a modified file.
494  * (The file arguments must be full paths to the files.)
495  *
496  * Compare lines according to the relevant fields of @a options.
497  */
498 svn_error_t *
500  const char *original,
501  const char *modified,
502  const svn_diff_file_options_t *options,
503  apr_pool_t *pool);
504 
505 /** Similar to svn_file_diff_2(), but with @a options set to a struct with
506  * default options.
507  *
508  * @deprecated Provided for backwards compatibility with the 1.3 API.
509  */
511 svn_error_t *
513  const char *original,
514  const char *modified,
515  apr_pool_t *pool);
516 
517 /** A convenience function to produce a diff between three files.
518  *
519  * @since New in 1.4.
520  *
521  * Return a diff object in @a *diff (allocated from @a pool) that represents
522  * the difference between an @a original file, @a modified file, and @a latest
523  * file.
524  *
525  * Compare lines according to the relevant fields of @a options.
526  */
527 svn_error_t *
529  const char *original,
530  const char *modified,
531  const char *latest,
532  const svn_diff_file_options_t *options,
533  apr_pool_t *pool);
534 
535 /** Similar to svn_diff_file_diff3_2(), but with @a options set to a struct
536  * with default options.
537  *
538  * @deprecated Provided for backwards compatibility with the 1.3 API.
539  */
541 svn_error_t *
543  const char *original,
544  const char *modified,
545  const char *latest,
546  apr_pool_t *pool);
547 
548 /** A convenience function to produce a diff between four files.
549  *
550  * @since New in 1.4.
551  *
552  * Return a diff object in @a *diff (allocated from @a pool) that represents
553  * the difference between an @a original file, @a modified file, @a latest
554  * and @a ancestor file. (The file arguments must be full paths to the files.)
555  *
556  * Compare lines according to the relevant fields of @a options.
557  */
558 svn_error_t *
560  const char *original,
561  const char *modified,
562  const char *latest,
563  const char *ancestor,
564  const svn_diff_file_options_t *options,
565  apr_pool_t *pool);
566 
567 /** Similar to svn_file_diff4_2(), but with @a options set to a struct with
568  * default options.
569  *
570  * @deprecated Provided for backwards compatibility with the 1.3 API.
571  */
573 svn_error_t *
575  const char *original,
576  const char *modified,
577  const char *latest,
578  const char *ancestor,
579  apr_pool_t *pool);
580 
581 /** A convenience function to produce unified diff output from the
582  * diff generated by svn_diff_file_diff().
583  *
584  * @since New in 1.5.
585  *
586  * Output a @a diff between @a original_path and @a modified_path in unified
587  * context diff format to @a output_stream. Optionally supply
588  * @a original_header and/or @a modified_header to be displayed in the header
589  * of the output. If @a original_header or @a modified_header is @c NULL, a
590  * default header will be displayed, consisting of path and last modified time.
591  * Output all headers and markers in @a header_encoding. If @a relative_to_dir
592  * is not @c NULL, the @a original_path and @a modified_path will have the
593  * @a relative_to_dir stripped from the front of the respective paths. If
594  * @a relative_to_dir is @c NULL, paths will be not be modified. If
595  * @a relative_to_dir is not @c NULL but @a relative_to_dir is not a parent
596  * path of the target, an error is returned. Finally, if @a relative_to_dir
597  * is a URL, an error will be returned.
598  */
599 svn_error_t *
601  svn_diff_t *diff,
602  const char *original_path,
603  const char *modified_path,
604  const char *original_header,
605  const char *modified_header,
606  const char *header_encoding,
607  const char *relative_to_dir,
608  svn_boolean_t show_c_function,
609  apr_pool_t *pool);
610 
611 /** Similar to svn_diff_file_output_unified3(), but with @a relative_to_dir
612  * set to NULL and @a show_c_function to false.
613  *
614  * @deprecated Provided for backwards compatibility with the 1.4 API.
615  */
617 svn_error_t *
619  svn_diff_t *diff,
620  const char *original_path,
621  const char *modified_path,
622  const char *original_header,
623  const char *modified_header,
624  const char *header_encoding,
625  apr_pool_t *pool);
626 
627 /** Similar to svn_diff_file_output_unified2(), but with @a header_encoding
628  * set to @c APR_LOCALE_CHARSET.
629  *
630  * @deprecated Provided for backward compatibility with the 1.2 API.
631  */
633 svn_error_t *
635  svn_diff_t *diff,
636  const char *original_path,
637  const char *modified_path,
638  const char *original_header,
639  const char *modified_header,
640  apr_pool_t *pool);
641 
642 
643 /** A convenience function to produce diff3 output from the
644  * diff generated by svn_diff_file_diff3().
645  *
646  * Output a @a diff between @a original_path, @a modified_path and
647  * @a latest_path in merged format to @a output_stream. Optionally supply
648  * @a conflict_modified, @a conflict_original, @a conflict_separator and/or
649  * @a conflict_latest to be displayed as conflict markers in the output.
650  * If @a conflict_original, @a conflict_modified, @a conflict_latest and/or
651  * @a conflict_separator is @c NULL, a default marker will be displayed.
652  * @a conflict_style dictates how conflicts are displayed.
653  *
654  * @since New in 1.6.
655  */
656 svn_error_t *
658  svn_diff_t *diff,
659  const char *original_path,
660  const char *modified_path,
661  const char *latest_path,
662  const char *conflict_original,
663  const char *conflict_modified,
664  const char *conflict_latest,
665  const char *conflict_separator,
666  svn_diff_conflict_display_style_t conflict_style,
667  apr_pool_t *pool);
668 
669 
670 /** Similar to svn_diff_file_output_merge2, but with @a
671  * display_original_in_conflict and @a display_resolved_conflicts
672  * booleans instead of the @a conflict_style enum.
673  *
674  * If both booleans are false, acts like
675  * svn_diff_conflict_display_modified_latest; if @a
676  * display_original_in_conflict is true, acts like
677  * svn_diff_conflict_display_modified_original_latest; if @a
678  * display_resolved_conflicts is true, acts like
679  * svn_diff_conflict_display_resolved_modified_latest. The booleans
680  * may not both be true.
681  *
682  * @deprecated Provided for backward compatibility with the 1.5 API.
683  */
685 svn_error_t *
687  svn_diff_t *diff,
688  const char *original_path,
689  const char *modified_path,
690  const char *latest_path,
691  const char *conflict_original,
692  const char *conflict_modified,
693  const char *conflict_latest,
694  const char *conflict_separator,
695  svn_boolean_t display_original_in_conflict,
696  svn_boolean_t display_resolved_conflicts,
697  apr_pool_t *pool);
698 
699 
700 
701 /* Diffs on in-memory structures */
702 
703 /** Generate @a diff output from the @a original and @a modified
704  * in-memory strings. @a diff will be allocated from @a pool.
705  *
706  * @since New in 1.5.
707  */
708 svn_error_t *
710  const svn_string_t *original,
711  const svn_string_t *modified,
712  const svn_diff_file_options_t *options,
713  apr_pool_t *pool);
714 
715 
716 /** Generate @a diff output from the @a original, @a modified and @a latest
717  * in-memory strings. @a diff will be allocated in @a pool.
718  *
719  * @since New in 1.5.
720  */
721 svn_error_t *
723  const svn_string_t *original,
724  const svn_string_t *modified,
725  const svn_string_t *latest,
726  const svn_diff_file_options_t *options,
727  apr_pool_t *pool);
728 
729 
730 /** Generate @a diff output from the @a original, @a modified and @a latest
731  * in-memory strings, using @a ancestor. @a diff will be allocated in @a pool.
732  *
733  * @since New in 1.5.
734  */
735 svn_error_t *
737  const svn_string_t *original,
738  const svn_string_t *modified,
739  const svn_string_t *latest,
740  const svn_string_t *ancestor,
741  const svn_diff_file_options_t *options,
742  apr_pool_t *pool);
743 
744 /** Outputs the @a diff object generated by svn_diff_mem_string_diff()
745  * in unified diff format on @a output_stream, using @a original
746  * and @a modified for the text in the output.
747  * A diff header is only written to the output if @a with_diff_header
748  * is TRUE.
749  *
750  * Outputs the header and hunk delimiters in @a header_encoding.
751  * A @a hunk_delimiter can optionally be specified.
752  * If @a hunk_delimiter is NULL, use the default hunk delimiter "@@".
753  *
754  * @a original_header and @a modified header are
755  * used to fill the field after the "---" and "+++" header markers.
756  *
757  * @since New in 1.7.
758  */
759 svn_error_t *
761  svn_diff_t *diff,
762  svn_boolean_t with_diff_header,
763  const char *hunk_delimiter,
764  const char *original_header,
765  const char *modified_header,
766  const char *header_encoding,
767  const svn_string_t *original,
768  const svn_string_t *modified,
769  apr_pool_t *pool);
770 
771 /** Similar to svn_diff_mem_string_output_unified2() but with
772  * @a with_diff_header always set to TRUE and @a hunk_delimiter always
773  * set to NULL.
774  *
775  * @since New in 1.5.
776  */
777 svn_error_t *
779  svn_diff_t *diff,
780  const char *original_header,
781  const char *modified_header,
782  const char *header_encoding,
783  const svn_string_t *original,
784  const svn_string_t *modified,
785  apr_pool_t *pool);
786 
787 /** Output the @a diff generated by svn_diff_mem_string_diff3() in diff3
788  * format on @a output_stream, using @a original, @a modified and @a latest
789  * for content changes.
790  *
791  * Use the conflict markers @a conflict_original, @a conflict_modified,
792  * @a conflict_latest and @a conflict_separator or the default one for
793  * each of these if @c NULL is passed.
794  *
795  * @a conflict_style dictates how conflicts are displayed.
796  *
797  * @since New in 1.6.
798  */
799 svn_error_t *
801  svn_diff_t *diff,
802  const svn_string_t *original,
803  const svn_string_t *modified,
804  const svn_string_t *latest,
805  const char *conflict_original,
806  const char *conflict_modified,
807  const char *conflict_latest,
808  const char *conflict_separator,
810  apr_pool_t *pool);
811 
812 /** Similar to svn_diff_mem_string_output_merge2, but with @a
813  * display_original_in_conflict and @a display_resolved_conflicts
814  * booleans instead of the @a conflict_style enum.
815  *
816  * If both booleans are false, acts like
817  * svn_diff_conflict_display_modified_latest; if @a
818  * display_original_in_conflict is true, acts like
819  * svn_diff_conflict_display_modified_original_latest; if @a
820  * display_resolved_conflicts is true, acts like
821  * svn_diff_conflict_display_resolved_modified_latest. The booleans
822  * may not both be true.
823  *
824  * @deprecated Provided for backward compatibility with the 1.5 API.
825  */
827 svn_error_t *
829  svn_diff_t *diff,
830  const svn_string_t *original,
831  const svn_string_t *modified,
832  const svn_string_t *latest,
833  const char *conflict_original,
834  const char *conflict_modified,
835  const char *conflict_latest,
836  const char *conflict_separator,
837  svn_boolean_t display_original_in_conflict,
838  svn_boolean_t display_resolved_conflicts,
839  apr_pool_t *pool);
840 
841 
842 
843 
844 /* Diff parsing. If you want to apply a patch to a working copy
845  * rather than parse it, see svn_client_patch(). */
846 
847 /**
848  * Describes what operation has been performed on a file.
849  *
850  * @since New in 1.7.
851  */
853 {
854  svn_diff_op_unchanged,
855  svn_diff_op_added,
856  svn_diff_op_deleted,
857  svn_diff_op_copied,
858  svn_diff_op_moved,
859  /* There's no tree changes, just text modifications. */
860  svn_diff_op_modified
862 
863 /**
864  * A single hunk inside a patch.
865  *
866  * The lines of text comprising the hunk can be interpreted in three ways:
867  * - diff text The hunk as it appears in the unidiff patch file,
868  * including the hunk header line ("@@ ... @@")
869  * - original text The text the patch was based on.
870  * - modified text The result of patching the original text.
871  *
872  * For example, consider a hunk with the following diff text:
873  *
874  * @verbatim
875  @@ -1,5 +1,5 @@
876  #include <stdio.h>
877  int main(int argc, char *argv[]) {
878  - printf("Hello World!\n");
879  + printf("I like Subversion!\n");
880  } @endverbatim
881  *
882  * The original text of this hunk is:
883  *
884  * @verbatim
885  #include <stdio.h>
886  int main(int argc, char *argv[]) {
887  printf("Hello World!\n");
888  } @endverbatim
889  *
890  * And the modified text is:
891  *
892  * @verbatim
893  #include <stdio.h>
894  int main(int argc, char *argv[]) {
895  printf("I like Subversion!\n");
896  } @endverbatim
897  *
898  * @see svn_diff_hunk_readline_diff_text()
899  * @see svn_diff_hunk_readline_original_text()
900  * @see svn_diff_hunk_readline_modified_text()
901  *
902  * @since New in 1.7. */
904 
905 /**
906  * Allocate @a *stringbuf in @a result_pool, and read into it one line
907  * of the diff text of @a hunk. The first line returned is the hunk header.
908  * Any subsequent lines are unidiff data (starting with '+', '-', or ' ').
909  * If the @a hunk is being interpreted in reverse (i.e. the reverse
910  * parameter of svn_diff_parse_next_patch() was @c TRUE), the diff
911  * text will be returned in reversed form.
912  * The line-terminator is detected automatically and stored in @a *eol
913  * if @a eol is not NULL.
914  * If EOF is reached, set @a *eof to TRUE, and set @a *eol to NULL if the
915  * hunk does not end with a newline character and @a eol is not NULL.
916  * Temporary allocations will be performed in @a scratch_pool.
917  *
918  * @since New in 1.7.
919  */
920 svn_error_t *
922  svn_stringbuf_t **stringbuf,
923  const char **eol,
924  svn_boolean_t *eof,
925  apr_pool_t *result_pool,
926  apr_pool_t *scratch_pool);
927 
928 /**
929  * Allocate @a *stringbuf in @a result_pool, and read into it one line
930  * of the original text of @a hunk.
931  * The line-terminator is detected automatically and stored in @a *eol
932  * if @a eol is not NULL.
933  * If EOF is reached, set @a *eof to TRUE, and set @a *eol to NULL if the
934  * hunk text does not end with a newline character and @a eol is not NULL.
935  * Temporary allocations will be performed in @a scratch_pool.
936  *
937  * @see svn_diff_hunk_t
938  * @since New in 1.7.
939  */
940 svn_error_t *
942  svn_stringbuf_t **stringbuf,
943  const char **eol,
944  svn_boolean_t *eof,
945  apr_pool_t *result_pool,
946  apr_pool_t *scratch_pool);
947 
948 /**
949  * Like svn_diff_hunk_readline_original_text(), but it returns lines from
950  * the modified text of the hunk.
951  *
952  * @see svn_diff_hunk_t
953  * @since New in 1.7.
954  */
955 svn_error_t *
957  svn_stringbuf_t **stringbuf,
958  const char **eol,
959  svn_boolean_t *eof,
960  apr_pool_t *result_pool,
961  apr_pool_t *scratch_pool);
962 
963 /** Reset the diff text of @a hunk so it can be read again from the start.
964  * @since New in 1.7. */
965 void
967 
968 /** Reset the original text of @a hunk so it can be read again from the start.
969  * @since New in 1.7. */
970 void
972 
973 /** Reset the modified text of @a hunk so it can be read again from the start.
974  * @since New in 1.7. */
975 void
977 
978 /** Return the line offset of the original hunk text,
979  * as parsed from the hunk header.
980  * @since New in 1.7. */
983 
984 /** Return the number of lines in the original @a hunk text,
985  * as parsed from the hunk header.
986  * @since New in 1.7. */
989 
990 /** Return the line offset of the modified @a hunk text,
991  * as parsed from the hunk header.
992  * @since New in 1.7. */
995 
996 /** Return the number of lines in the modified @a hunk text,
997  * as parsed from the hunk header.
998  * @since New in 1.7. */
1001 
1002 /** Return the number of lines of leading context of @a hunk,
1003  * i.e. the number of lines starting with ' ' before the first line
1004  * that starts with a '+' or '-'.
1005  * @since New in 1.7. */
1008 
1009 /** Return the number of lines of trailing context of @a hunk,
1010  * i.e. the number of lines starting with ' ' after the last line
1011  * that starts with a '+' or '-'.
1012  * @since New in 1.7. */
1015 
1016 /**
1017  * Data type to manage parsing of properties in patches.
1018  * API users should not allocate structures of this type directly.
1019  *
1020  * @since New in 1.7. */
1021 typedef struct svn_prop_patch_t {
1022  const char *name;
1023 
1024  /** Represents the operation performed on the property */
1026 
1027  /**
1028  * An array containing an svn_diff_hunk_t object for each hunk parsed
1029  * from the patch associated with our property name */
1030  apr_array_header_t *hunks;
1032 
1033 /**
1034  * Data type to manage parsing of patches.
1035  * API users should not allocate structures of this type directly.
1036  *
1037  * @since New in 1.7. */
1038 typedef struct svn_patch_t {
1039  /**
1040  * The old and new file names as retrieved from the patch file.
1041  * These paths are UTF-8 encoded and canonicalized, but otherwise
1042  * left unchanged from how they appeared in the patch file. */
1043  const char *old_filename;
1044  const char *new_filename;
1045 
1046  /**
1047  * An array containing an svn_diff_hunk_t object for each hunk parsed
1048  * from the patch. */
1049  apr_array_header_t *hunks;
1050 
1051  /**
1052  * A hash table keyed by property names containing svn_prop_patch_t
1053  * object for each property parsed from the patch. */
1054  apr_hash_t *prop_patches;
1055 
1056  /**
1057  * Represents the operation performed on the file. */
1059 
1060  /**
1061  * Indicates whether the patch is being interpreted in reverse. */
1063 } svn_patch_t;
1064 
1065 /* An opaque type representing an open patch file.
1066  *
1067  * @since New in 1.7. */
1068 typedef struct svn_patch_file_t svn_patch_file_t;
1069 
1070 /* Open @a patch_file at @a local_abspath.
1071  * Allocate @a patch_file in @a result_pool.
1072  *
1073  * @since New in 1.7. */
1074 svn_error_t *
1075 svn_diff_open_patch_file(svn_patch_file_t **patch_file,
1076  const char *local_abspath,
1077  apr_pool_t *result_pool);
1078 
1079 /**
1080  * Return the next @a *patch in @a patch_file.
1081  * If no patch can be found, set @a *patch to NULL.
1082  * If @a reverse is TRUE, invert the patch while parsing it.
1083  * If @a ignore_whitespace is TRUE, allow patches with no leading
1084  * whitespace to be parsed.
1085  * Allocate results in @a result_pool.
1086  * Use @a scratch_pool for all other allocations.
1087  *
1088  * @since New in 1.7. */
1089 svn_error_t *
1091  svn_patch_file_t *patch_file,
1092  svn_boolean_t reverse,
1093  svn_boolean_t ignore_whitespace,
1094  apr_pool_t *result_pool,
1095  apr_pool_t *scratch_pool);
1096 
1097 /**
1098  * Dispose of @a patch_file.
1099  * Use @a scratch_pool for all temporary allocations.
1100  *
1101  * @since New in 1.7.
1102  */
1103 svn_error_t *
1104 svn_diff_close_patch_file(svn_patch_file_t *patch_file,
1105  apr_pool_t *scratch_pool);
1106 
1107 #ifdef __cplusplus
1108 }
1109 #endif /* __cplusplus */
1110 
1111 #endif /* SVN_DIFF_H */