1251881Speter/**
2251881Speter * @copyright
3251881Speter * ====================================================================
4251881Speter *    Licensed to the Apache Software Foundation (ASF) under one
5251881Speter *    or more contributor license agreements.  See the NOTICE file
6251881Speter *    distributed with this work for additional information
7251881Speter *    regarding copyright ownership.  The ASF licenses this file
8251881Speter *    to you under the Apache License, Version 2.0 (the
9251881Speter *    "License"); you may not use this file except in compliance
10251881Speter *    with the License.  You may obtain a copy of the License at
11251881Speter *
12251881Speter *      http://www.apache.org/licenses/LICENSE-2.0
13251881Speter *
14251881Speter *    Unless required by applicable law or agreed to in writing,
15251881Speter *    software distributed under the License is distributed on an
16251881Speter *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17251881Speter *    KIND, either express or implied.  See the License for the
18251881Speter *    specific language governing permissions and limitations
19251881Speter *    under the License.
20251881Speter * ====================================================================
21251881Speter * @endcopyright
22251881Speter *
23251881Speter * @file svn_diff.h
24251881Speter * @brief Contextual diffing.
25251881Speter *
26251881Speter * This is an internalized library for performing contextual diffs
27251881Speter * between sources of data.
28251881Speter *
29251881Speter * @note This is different than Subversion's binary-diffing engine.
30251881Speter * That API lives in @c svn_delta.h -- see the "text deltas" section.  A
31251881Speter * "text delta" is way of representing precise binary diffs between
32251881Speter * strings of data.  The Subversion client and server send text deltas
33251881Speter * to one another during updates and commits.
34251881Speter *
35251881Speter * This API, however, is (or will be) used for performing *contextual*
36251881Speter * merges between files in the working copy.  During an update or
37251881Speter * merge, 3-way file merging is needed.  And 'svn diff' needs to show
38251881Speter * the differences between 2 files.
39251881Speter *
40251881Speter * The nice thing about this API is that it's very general.  It
41251881Speter * operates on any source of data (a "datasource") and calculates
42251881Speter * contextual differences on "tokens" within the data.  In our
43251881Speter * particular usage, the datasources are files and the tokens are
44251881Speter * lines.  But the possibilities are endless.
45251881Speter */
46251881Speter
47251881Speter
48251881Speter#ifndef SVN_DIFF_H
49251881Speter#define SVN_DIFF_H
50251881Speter
51251881Speter#include <apr.h>
52251881Speter#include <apr_pools.h>
53251881Speter#include <apr_tables.h>   /* for apr_array_header_t */
54251881Speter
55251881Speter#include "svn_types.h"
56251881Speter#include "svn_io.h"       /* for svn_stream_t */
57251881Speter#include "svn_string.h"
58289180Speter#include "svn_mergeinfo.h"
59251881Speter
60251881Speter#ifdef __cplusplus
61251881Speterextern "C" {
62251881Speter#endif /* __cplusplus */
63251881Speter
64251881Speter
65251881Speter
66251881Speter/**
67251881Speter * Get libsvn_diff version information.
68251881Speter *
69251881Speter * @since New in 1.1.
70251881Speter */
71251881Speterconst svn_version_t *
72251881Spetersvn_diff_version(void);
73251881Speter
74251881Speter
75251881Speter/* Diffs. */
76251881Speter
77251881Speter/** An opaque type that represents a difference between either two or
78251881Speter * three datasources.   This object is returned by svn_diff_diff(),
79251881Speter * svn_diff_diff3() and svn_diff_diff4(), and consumed by a number of
80251881Speter * other routines.
81251881Speter */
82251881Spetertypedef struct svn_diff_t svn_diff_t;
83251881Speter
84251881Speter/**
85251881Speter * There are four types of datasources.  In GNU diff3 terminology,
86251881Speter * the first three types correspond to the phrases "older", "mine",
87251881Speter * and "yours".
88251881Speter */
89251881Spetertypedef enum svn_diff_datasource_e
90251881Speter{
91251881Speter  /** The oldest form of the data. */
92251881Speter  svn_diff_datasource_original,
93251881Speter
94251881Speter  /** The same data, but potentially changed by the user. */
95251881Speter  svn_diff_datasource_modified,
96251881Speter
97251881Speter  /** The latest version of the data, possibly different than the
98251881Speter   * user's modified version.
99251881Speter   */
100251881Speter  svn_diff_datasource_latest,
101251881Speter
102251881Speter  /** The common ancestor of original and modified. */
103251881Speter  svn_diff_datasource_ancestor
104251881Speter
105251881Speter} svn_diff_datasource_e;
106251881Speter
107251881Speter
108251881Speter/** A vtable for reading data from the three datasources.
109251881Speter * @since New in 1.7. */
110251881Spetertypedef struct svn_diff_fns2_t
111251881Speter{
112251881Speter  /** Open the datasources of type @a datasources. */
113251881Speter  svn_error_t *(*datasources_open)(void *diff_baton,
114251881Speter                                   apr_off_t *prefix_lines,
115251881Speter                                   apr_off_t *suffix_lines,
116251881Speter                                   const svn_diff_datasource_e *datasources,
117251881Speter                                   apr_size_t datasources_len);
118251881Speter
119251881Speter  /** Close the datasource of type @a datasource. */
120251881Speter  svn_error_t *(*datasource_close)(void *diff_baton,
121251881Speter                                   svn_diff_datasource_e datasource);
122251881Speter
123251881Speter  /** Get the next "token" from the datasource of type @a datasource.
124251881Speter   *  Return a "token" in @a *token.   Return a hash of "token" in @a *hash.
125251881Speter   *  Leave @a token and @a hash untouched when the datasource is exhausted.
126251881Speter   */
127251881Speter  svn_error_t *(*datasource_get_next_token)(apr_uint32_t *hash, void **token,
128251881Speter                                            void *diff_baton,
129251881Speter                                            svn_diff_datasource_e datasource);
130251881Speter
131251881Speter  /** A function for ordering the tokens, resembling 'strcmp' in functionality.
132251881Speter   * @a compare should contain the return value of the comparison:
133251881Speter   * If @a ltoken and @a rtoken are "equal", return 0.  If @a ltoken is
134251881Speter   * "less than" @a rtoken, return a number < 0.  If @a ltoken  is
135251881Speter   * "greater than" @a rtoken, return a number > 0.
136251881Speter   */
137251881Speter  svn_error_t *(*token_compare)(void *diff_baton,
138251881Speter                                void *ltoken,
139251881Speter                                void *rtoken,
140251881Speter                                int *compare);
141251881Speter
142251881Speter  /** Free @a token from memory, the diff algorithm is done with it. */
143251881Speter  void (*token_discard)(void *diff_baton,
144251881Speter                        void *token);
145251881Speter
146251881Speter  /** Free *all* tokens from memory, they're no longer needed. */
147251881Speter  void (*token_discard_all)(void *diff_baton);
148251881Speter} svn_diff_fns2_t;
149251881Speter
150251881Speter
151251881Speter/** Like #svn_diff_fns2_t except with datasource_open() instead of
152251881Speter * datasources_open().
153251881Speter *
154251881Speter * @deprecated Provided for backward compatibility with the 1.6 API.
155251881Speter */
156251881Spetertypedef struct svn_diff_fns_t
157251881Speter{
158251881Speter  svn_error_t *(*datasource_open)(void *diff_baton,
159251881Speter                                  svn_diff_datasource_e datasource);
160251881Speter
161251881Speter  svn_error_t *(*datasource_close)(void *diff_baton,
162251881Speter                                   svn_diff_datasource_e datasource);
163251881Speter
164251881Speter  svn_error_t *(*datasource_get_next_token)(apr_uint32_t *hash, void **token,
165251881Speter                                            void *diff_baton,
166251881Speter                                            svn_diff_datasource_e datasource);
167251881Speter
168251881Speter  svn_error_t *(*token_compare)(void *diff_baton,
169251881Speter                                void *ltoken,
170251881Speter                                void *rtoken,
171251881Speter                                int *compare);
172251881Speter
173251881Speter  void (*token_discard)(void *diff_baton,
174251881Speter                        void *token);
175251881Speter
176251881Speter  void (*token_discard_all)(void *diff_baton);
177251881Speter} svn_diff_fns_t;
178251881Speter
179251881Speter
180251881Speter/* The Main Events */
181251881Speter
182251881Speter/** Given a vtable of @a diff_fns/@a diff_baton for reading datasources,
183251881Speter * return a diff object in @a *diff that represents a difference between
184251881Speter * an "original" and "modified" datasource.  Do all allocation in @a pool.
185251881Speter *
186251881Speter * @since New in 1.7.
187251881Speter */
188251881Spetersvn_error_t *
189251881Spetersvn_diff_diff_2(svn_diff_t **diff,
190251881Speter                void *diff_baton,
191251881Speter                const svn_diff_fns2_t *diff_fns,
192251881Speter                apr_pool_t *pool);
193251881Speter
194251881Speter/** Like svn_diff_diff_2() but using #svn_diff_fns_t instead of
195251881Speter * #svn_diff_fns2_t.
196251881Speter *
197251881Speter * @deprecated Provided for backward compatibility with the 1.6 API.
198251881Speter */
199251881SpeterSVN_DEPRECATED
200251881Spetersvn_error_t *
201251881Spetersvn_diff_diff(svn_diff_t **diff,
202251881Speter              void *diff_baton,
203251881Speter              const svn_diff_fns_t *diff_fns,
204251881Speter              apr_pool_t *pool);
205251881Speter
206251881Speter/** Given a vtable of @a diff_fns/@a diff_baton for reading datasources,
207251881Speter * return a diff object in @a *diff that represents a difference between
208251881Speter * three datasources: "original", "modified", and "latest".  Do all
209251881Speter * allocation in @a pool.
210251881Speter *
211251881Speter * @since New in 1.7.
212251881Speter */
213251881Spetersvn_error_t *
214251881Spetersvn_diff_diff3_2(svn_diff_t **diff,
215251881Speter                 void *diff_baton,
216251881Speter                 const svn_diff_fns2_t *diff_fns,
217251881Speter                 apr_pool_t *pool);
218251881Speter
219251881Speter/** Like svn_diff_diff3_2() but using #svn_diff_fns_t instead of
220251881Speter * #svn_diff_fns2_t.
221251881Speter *
222251881Speter * @deprecated Provided for backward compatibility with the 1.6 API.
223251881Speter */
224251881SpeterSVN_DEPRECATED
225251881Spetersvn_error_t *
226251881Spetersvn_diff_diff3(svn_diff_t **diff,
227251881Speter               void *diff_baton,
228251881Speter               const svn_diff_fns_t *diff_fns,
229251881Speter               apr_pool_t *pool);
230251881Speter
231251881Speter/** Given a vtable of @a diff_fns/@a diff_baton for reading datasources,
232251881Speter * return a diff object in @a *diff that represents a difference between
233251881Speter * two datasources: "original" and "latest", adjusted to become a full
234251881Speter * difference between "original", "modified" and "latest" using "ancestor".
235251881Speter * Do all allocation in @a pool.
236251881Speter *
237251881Speter * @since New in 1.7.
238251881Speter */
239251881Spetersvn_error_t *
240251881Spetersvn_diff_diff4_2(svn_diff_t **diff,
241251881Speter                 void *diff_baton,
242251881Speter                 const svn_diff_fns2_t *diff_fns,
243251881Speter                 apr_pool_t *pool);
244251881Speter
245251881Speter/** Like svn_diff_diff4_2() but using #svn_diff_fns_t instead of
246251881Speter * #svn_diff_fns2_t.
247251881Speter *
248251881Speter * @deprecated Provided for backward compatibility with the 1.6 API.
249251881Speter */
250251881SpeterSVN_DEPRECATED
251251881Spetersvn_error_t *
252251881Spetersvn_diff_diff4(svn_diff_t **diff,
253251881Speter               void *diff_baton,
254251881Speter               const svn_diff_fns_t *diff_fns,
255251881Speter               apr_pool_t *pool);
256251881Speter
257251881Speter
258251881Speter/* Utility functions */
259251881Speter
260251881Speter/** Determine if a diff object contains conflicts.  If it does, return
261251881Speter * @c TRUE, else return @c FALSE.
262251881Speter */
263251881Spetersvn_boolean_t
264251881Spetersvn_diff_contains_conflicts(svn_diff_t *diff);
265251881Speter
266251881Speter
267251881Speter/** Determine if a diff object contains actual differences between the
268251881Speter * datasources.  If so, return @c TRUE, else return @c FALSE.
269251881Speter */
270251881Spetersvn_boolean_t
271251881Spetersvn_diff_contains_diffs(svn_diff_t *diff);
272251881Speter
273251881Speter
274251881Speter
275251881Speter
276251881Speter/* Displaying Diffs */
277251881Speter
278251881Speter/** A vtable for displaying (or consuming) differences between datasources.
279251881Speter *
280251881Speter * Differences, similarities, and conflicts are described by lining up
281251881Speter * "ranges" of data.
282251881Speter *
283251881Speter * Any of the function pointers in this vtable may be NULL to ignore the
284251881Speter * corresponding kinds of output.
285251881Speter *
286251881Speter * @note These callbacks describe data ranges in units of "tokens".
287251881Speter * A "token" is whatever you've defined it to be in your datasource
288251881Speter * @c svn_diff_fns_t vtable.
289251881Speter */
290251881Spetertypedef struct svn_diff_output_fns_t
291251881Speter{
292251881Speter  /* Two-way and three-way diffs both call the first two output functions: */
293251881Speter
294251881Speter  /**
295251881Speter   * If doing a two-way diff, then an *identical* data range was found
296251881Speter   * between the "original" and "modified" datasources.  Specifically,
297251881Speter   * the match starts at @a original_start and goes for @a original_length
298251881Speter   * tokens in the original data, and at @a modified_start for
299251881Speter   * @a modified_length tokens in the modified data.
300251881Speter   *
301251881Speter   * If doing a three-way diff, then all three datasources have
302251881Speter   * matching data ranges.  The range @a latest_start, @a latest_length in
303251881Speter   * the "latest" datasource is identical to the range @a original_start,
304251881Speter   * @a original_length in the original data, and is also identical to
305251881Speter   * the range @a modified_start, @a modified_length in the modified data.
306251881Speter   */
307251881Speter  svn_error_t *(*output_common)(void *output_baton,
308251881Speter                                apr_off_t original_start,
309251881Speter                                apr_off_t original_length,
310251881Speter                                apr_off_t modified_start,
311251881Speter                                apr_off_t modified_length,
312251881Speter                                apr_off_t latest_start,
313251881Speter                                apr_off_t latest_length);
314251881Speter
315251881Speter  /**
316251881Speter   * If doing a two-way diff, then an *conflicting* data range was found
317251881Speter   * between the "original" and "modified" datasources.  Specifically,
318251881Speter   * the conflict starts at @a original_start and goes for @a original_length
319251881Speter   * tokens in the original data, and at @a modified_start for
320251881Speter   * @a modified_length tokens in the modified data.
321251881Speter   *
322251881Speter   * If doing a three-way diff, then an identical data range was discovered
323251881Speter   * between the "original" and "latest" datasources, but this conflicts with
324251881Speter   * a range in the "modified" datasource.
325251881Speter   */
326251881Speter  svn_error_t *(*output_diff_modified)(void *output_baton,
327251881Speter                                       apr_off_t original_start,
328251881Speter                                       apr_off_t original_length,
329251881Speter                                       apr_off_t modified_start,
330251881Speter                                       apr_off_t modified_length,
331251881Speter                                       apr_off_t latest_start,
332251881Speter                                       apr_off_t latest_length);
333251881Speter
334251881Speter  /* ------ The following callbacks are used by three-way diffs only --- */
335251881Speter
336251881Speter  /** An identical data range was discovered between the "original" and
337251881Speter   * "modified" datasources, but this conflicts with a range in the
338251881Speter   * "latest" datasource.
339251881Speter   */
340251881Speter  svn_error_t *(*output_diff_latest)(void *output_baton,
341251881Speter                                     apr_off_t original_start,
342251881Speter                                     apr_off_t original_length,
343251881Speter                                     apr_off_t modified_start,
344251881Speter                                     apr_off_t modified_length,
345251881Speter                                     apr_off_t latest_start,
346251881Speter                                     apr_off_t latest_length);
347251881Speter
348251881Speter  /** An identical data range was discovered between the "modified" and
349251881Speter   * "latest" datasources, but this conflicts with a range in the
350251881Speter   * "original" datasource.
351251881Speter   */
352251881Speter  svn_error_t *(*output_diff_common)(void *output_baton,
353251881Speter                                     apr_off_t original_start,
354251881Speter                                     apr_off_t original_length,
355251881Speter                                     apr_off_t modified_start,
356251881Speter                                     apr_off_t modified_length,
357251881Speter                                     apr_off_t latest_start,
358251881Speter                                     apr_off_t latest_length);
359251881Speter
360251881Speter  /** All three datasources have conflicting data ranges.  The range
361251881Speter   * @a latest_start, @a latest_length in the "latest" datasource conflicts
362251881Speter   * with the range @a original_start, @a original_length in the "original"
363251881Speter   * datasource, and also conflicts with the range @a modified_start,
364251881Speter   * @a modified_length in the "modified" datasource.
365251881Speter   * If there are common ranges in the "modified" and "latest" datasources
366251881Speter   * in this conflicting range, @a resolved_diff will contain a diff
367251881Speter   * which can be used to retrieve the common and conflicting ranges.
368251881Speter   */
369251881Speter  svn_error_t *(*output_conflict)(void *output_baton,
370251881Speter                                  apr_off_t original_start,
371251881Speter                                  apr_off_t original_length,
372251881Speter                                  apr_off_t modified_start,
373251881Speter                                  apr_off_t modified_length,
374251881Speter                                  apr_off_t latest_start,
375251881Speter                                  apr_off_t latest_length,
376251881Speter                                  svn_diff_t *resolved_diff);
377251881Speter} svn_diff_output_fns_t;
378251881Speter
379251881Speter/** Style for displaying conflicts during diff3 output.
380251881Speter *
381251881Speter * @since New in 1.6.
382251881Speter */
383251881Spetertypedef enum svn_diff_conflict_display_style_t
384251881Speter{
385251881Speter  /** Display modified and latest, with conflict markers. */
386251881Speter  svn_diff_conflict_display_modified_latest,
387251881Speter
388251881Speter  /** Like svn_diff_conflict_display_modified_latest, but with an
389251881Speter      extra effort to identify common sequences between modified and
390251881Speter      latest. */
391251881Speter  svn_diff_conflict_display_resolved_modified_latest,
392251881Speter
393251881Speter  /** Display modified, original, and latest, with conflict
394251881Speter      markers. */
395251881Speter  svn_diff_conflict_display_modified_original_latest,
396251881Speter
397251881Speter  /** Just display modified, with no markers. */
398251881Speter  svn_diff_conflict_display_modified,
399251881Speter
400251881Speter  /** Just display latest, with no markers. */
401251881Speter  svn_diff_conflict_display_latest,
402251881Speter
403251881Speter  /** Like svn_diff_conflict_display_modified_original_latest, but
404251881Speter      *only* showing conflicts. */
405251881Speter  svn_diff_conflict_display_only_conflicts
406289180Speter
407289180Speter  /* IMPORTANT: If you extend this enum note that it is mapped in
408289180Speter     tools/diff/diff3.c. */
409251881Speter} svn_diff_conflict_display_style_t;
410251881Speter
411251881Speter
412251881Speter/** Given a vtable of @a output_fns/@a output_baton for consuming
413251881Speter * differences, output the differences in @a diff.
414289180Speter *
415289180Speter * If not @c NULL, call @a cancel_func with @a cancel_baton once or multiple
416289180Speter * times while processing larger diffs.
417289180Speter *
418289180Speter * @since New in 1.9.
419251881Speter */
420251881Spetersvn_error_t *
421289180Spetersvn_diff_output2(svn_diff_t *diff,
422289180Speter                 void *output_baton,
423289180Speter                 const svn_diff_output_fns_t *output_fns,
424289180Speter                 svn_cancel_func_t cancel_func,
425289180Speter                 void *cancel_baton);
426289180Speter
427289180Speter/** Similar to svn_diff_output2(), but without cancel support.
428289180Speter *
429289180Speter * @deprecated Provided for backwards compatibility with the 1.8 API.
430289180Speter */
431289180SpeterSVN_DEPRECATED
432289180Spetersvn_error_t *
433251881Spetersvn_diff_output(svn_diff_t *diff,
434251881Speter                void *output_baton,
435251881Speter                const svn_diff_output_fns_t *output_fns);
436251881Speter
437251881Speter
438251881Speter
439251881Speter/* Diffs on files */
440251881Speter
441251881Speter/** To what extent whitespace should be ignored when comparing lines.
442251881Speter *
443251881Speter * @since New in 1.4.
444251881Speter */
445251881Spetertypedef enum svn_diff_file_ignore_space_t
446251881Speter{
447251881Speter  /** Ignore no whitespace. */
448251881Speter  svn_diff_file_ignore_space_none,
449251881Speter
450251881Speter  /** Ignore changes in sequences of whitespace characters, treating each
451251881Speter   * sequence of whitespace characters as a single space. */
452251881Speter  svn_diff_file_ignore_space_change,
453251881Speter
454251881Speter  /** Ignore all whitespace characters. */
455251881Speter  svn_diff_file_ignore_space_all
456251881Speter} svn_diff_file_ignore_space_t;
457251881Speter
458251881Speter/** Options to control the behaviour of the file diff routines.
459251881Speter *
460251881Speter * @since New in 1.4.
461251881Speter *
462251881Speter * @note This structure may be extended in the future, so to preserve binary
463251881Speter * compatibility, users must not allocate structs of this type themselves.
464251881Speter * @see svn_diff_file_options_create().
465251881Speter *
466251881Speter * @note Although its name suggests otherwise, this structure is used to
467251881Speter *       pass options to file as well as in-memory diff functions.
468251881Speter */
469251881Spetertypedef struct svn_diff_file_options_t
470251881Speter{
471251881Speter  /** To what extent whitespace should be ignored when comparing lines.
472251881Speter   * The default is @c svn_diff_file_ignore_space_none. */
473251881Speter  svn_diff_file_ignore_space_t ignore_space;
474251881Speter  /** Whether to treat all end-of-line markers the same when comparing lines.
475251881Speter   * The default is @c FALSE. */
476251881Speter  svn_boolean_t ignore_eol_style;
477251881Speter  /** Whether the "@@" lines of the unified diff output should include a prefix
478251881Speter    * of the nearest preceding line that starts with a character that might be
479251881Speter    * the initial character of a C language identifier.  The default is
480251881Speter    * @c FALSE.
481289180Speter    * @since New in 1.5.
482251881Speter    */
483251881Speter  svn_boolean_t show_c_function;
484289180Speter
485289180Speter  /** The number of context lines produced above and below modifications, if
486289180Speter   * available. The number of context lines must be >= 0.
487289180Speter   *
488289180Speter   * @since New in 1.9 */
489289180Speter  int context_size;
490251881Speter} svn_diff_file_options_t;
491251881Speter
492251881Speter/** Allocate a @c svn_diff_file_options_t structure in @a pool, initializing
493251881Speter * it with default values.
494251881Speter *
495251881Speter * @since New in 1.4.
496251881Speter */
497251881Spetersvn_diff_file_options_t *
498251881Spetersvn_diff_file_options_create(apr_pool_t *pool);
499251881Speter
500251881Speter/**
501251881Speter * Parse @a args, an array of <tt>const char *</tt> command line switches
502251881Speter * and adjust @a options accordingly.  @a options is assumed to be initialized
503251881Speter * with default values.  @a pool is used for temporary allocation.
504251881Speter *
505251881Speter * @since New in 1.4.
506251881Speter *
507251881Speter * The following options are supported:
508251881Speter * - --ignore-space-change, -b
509251881Speter * - --ignore-all-space, -w
510251881Speter * - --ignore-eol-style
511251881Speter * - --show-c-function, -p @since New in 1.5.
512289180Speter * - --context, -U ARG @since New in 1.9.
513251881Speter * - --unified, -u (for compatibility, does nothing).
514251881Speter */
515251881Spetersvn_error_t *
516251881Spetersvn_diff_file_options_parse(svn_diff_file_options_t *options,
517251881Speter                            const apr_array_header_t *args,
518251881Speter                            apr_pool_t *pool);
519251881Speter
520251881Speter
521251881Speter/** A convenience function to produce a diff between two files.
522251881Speter *
523251881Speter * @since New in 1.4.
524251881Speter *
525251881Speter * Return a diff object in @a *diff (allocated from @a pool) that represents
526251881Speter * the difference between an @a original file and @a modified file.
527251881Speter * (The file arguments must be full paths to the files.)
528251881Speter *
529251881Speter * Compare lines according to the relevant fields of @a options.
530251881Speter */
531251881Spetersvn_error_t *
532251881Spetersvn_diff_file_diff_2(svn_diff_t **diff,
533251881Speter                     const char *original,
534251881Speter                     const char *modified,
535251881Speter                     const svn_diff_file_options_t *options,
536251881Speter                     apr_pool_t *pool);
537251881Speter
538251881Speter/** Similar to svn_file_diff_2(), but with @a options set to a struct with
539251881Speter * default options.
540251881Speter *
541251881Speter * @deprecated Provided for backwards compatibility with the 1.3 API.
542251881Speter */
543251881SpeterSVN_DEPRECATED
544251881Spetersvn_error_t *
545251881Spetersvn_diff_file_diff(svn_diff_t **diff,
546251881Speter                   const char *original,
547251881Speter                   const char *modified,
548251881Speter                   apr_pool_t *pool);
549251881Speter
550251881Speter/** A convenience function to produce a diff between three files.
551251881Speter *
552251881Speter * @since New in 1.4.
553251881Speter *
554251881Speter * Return a diff object in @a *diff (allocated from @a pool) that represents
555251881Speter * the difference between an @a original file, @a modified file, and @a latest
556251881Speter * file.
557251881Speter *
558251881Speter * Compare lines according to the relevant fields of @a options.
559251881Speter */
560251881Spetersvn_error_t *
561251881Spetersvn_diff_file_diff3_2(svn_diff_t **diff,
562251881Speter                      const char *original,
563251881Speter                      const char *modified,
564251881Speter                      const char *latest,
565251881Speter                      const svn_diff_file_options_t *options,
566251881Speter                      apr_pool_t *pool);
567251881Speter
568251881Speter/** Similar to svn_diff_file_diff3_2(), but with @a options set to a struct
569251881Speter * with default options.
570251881Speter *
571251881Speter * @deprecated Provided for backwards compatibility with the 1.3 API.
572251881Speter */
573251881SpeterSVN_DEPRECATED
574251881Spetersvn_error_t *
575251881Spetersvn_diff_file_diff3(svn_diff_t **diff,
576251881Speter                    const char *original,
577251881Speter                    const char *modified,
578251881Speter                    const char *latest,
579251881Speter                    apr_pool_t *pool);
580251881Speter
581251881Speter/** A convenience function to produce a diff between four files.
582251881Speter *
583251881Speter * @since New in 1.4.
584251881Speter *
585251881Speter * Return a diff object in @a *diff (allocated from @a pool) that represents
586251881Speter * the difference between an @a original file, @a modified file, @a latest
587251881Speter * and @a ancestor file. (The file arguments must be full paths to the files.)
588251881Speter *
589251881Speter * Compare lines according to the relevant fields of @a options.
590251881Speter */
591251881Spetersvn_error_t *
592251881Spetersvn_diff_file_diff4_2(svn_diff_t **diff,
593251881Speter                      const char *original,
594251881Speter                      const char *modified,
595251881Speter                      const char *latest,
596251881Speter                      const char *ancestor,
597251881Speter                      const svn_diff_file_options_t *options,
598251881Speter                      apr_pool_t *pool);
599251881Speter
600251881Speter/** Similar to svn_file_diff4_2(), but with @a options set to a struct with
601251881Speter * default options.
602251881Speter *
603251881Speter * @deprecated Provided for backwards compatibility with the 1.3 API.
604251881Speter */
605251881SpeterSVN_DEPRECATED
606251881Spetersvn_error_t *
607251881Spetersvn_diff_file_diff4(svn_diff_t **diff,
608251881Speter                    const char *original,
609251881Speter                    const char *modified,
610251881Speter                    const char *latest,
611251881Speter                    const char *ancestor,
612251881Speter                    apr_pool_t *pool);
613251881Speter
614251881Speter/** A convenience function to produce unified diff output from the
615251881Speter * diff generated by svn_diff_file_diff().
616251881Speter *
617251881Speter * Output a @a diff between @a original_path and @a modified_path in unified
618251881Speter * context diff format to @a output_stream.  Optionally supply
619251881Speter * @a original_header and/or @a modified_header to be displayed in the header
620251881Speter * of the output.  If @a original_header or @a modified_header is @c NULL, a
621251881Speter * default header will be displayed, consisting of path and last modified time.
622251881Speter * Output all headers and markers in @a header_encoding.  If @a relative_to_dir
623251881Speter * is not @c NULL, the @a original_path and @a modified_path will have the
624251881Speter * @a relative_to_dir stripped from the front of the respective paths.  If
625251881Speter * @a relative_to_dir is @c NULL, paths will be not be modified.  If
626251881Speter * @a relative_to_dir is not @c NULL but @a relative_to_dir is not a parent
627251881Speter * path of the target, an error is returned. Finally, if @a relative_to_dir
628251881Speter * is a URL, an error will be returned.
629289180Speter *
630289180Speter * If @a context_size is not negative, then this number of context lines
631289180Speter * will be used in the generated diff output. Otherwise the legacy compile
632289180Speter * time default will be used.
633289180Speter *
634289180Speter * If not @c NULL, call @a cancel_func with @a cancel_baton once or multiple
635289180Speter * times while processing larger diffs.
636289180Speter *
637289180Speter * @since New in 1.9.
638251881Speter */
639251881Spetersvn_error_t *
640289180Spetersvn_diff_file_output_unified4(svn_stream_t *output_stream,
641289180Speter                              svn_diff_t *diff,
642289180Speter                              const char *original_path,
643289180Speter                              const char *modified_path,
644289180Speter                              const char *original_header,
645289180Speter                              const char *modified_header,
646289180Speter                              const char *header_encoding,
647289180Speter                              const char *relative_to_dir,
648289180Speter                              svn_boolean_t show_c_function,
649289180Speter                              int context_size,
650289180Speter                              svn_cancel_func_t cancel_func,
651289180Speter                              void *cancel_baton,
652289180Speter                              apr_pool_t *scratch_pool);
653289180Speter
654289180Speter/** Similar to svn_diff_file_output_unified4(), but without cancel
655289180Speter * support and with @a context_size set to -1.
656289180Speter *
657289180Speter * @since New in 1.5.
658289180Speter * @deprecated Provided for backwards compatibility with the 1.8 API.
659289180Speter */
660289180SpeterSVN_DEPRECATED
661289180Spetersvn_error_t *
662251881Spetersvn_diff_file_output_unified3(svn_stream_t *output_stream,
663251881Speter                              svn_diff_t *diff,
664251881Speter                              const char *original_path,
665251881Speter                              const char *modified_path,
666251881Speter                              const char *original_header,
667251881Speter                              const char *modified_header,
668251881Speter                              const char *header_encoding,
669251881Speter                              const char *relative_to_dir,
670251881Speter                              svn_boolean_t show_c_function,
671251881Speter                              apr_pool_t *pool);
672251881Speter
673251881Speter/** Similar to svn_diff_file_output_unified3(), but with @a relative_to_dir
674251881Speter * set to NULL and @a show_c_function to false.
675251881Speter *
676251881Speter * @deprecated Provided for backwards compatibility with the 1.4 API.
677251881Speter */
678251881SpeterSVN_DEPRECATED
679251881Spetersvn_error_t *
680251881Spetersvn_diff_file_output_unified2(svn_stream_t *output_stream,
681251881Speter                              svn_diff_t *diff,
682251881Speter                              const char *original_path,
683251881Speter                              const char *modified_path,
684251881Speter                              const char *original_header,
685251881Speter                              const char *modified_header,
686251881Speter                              const char *header_encoding,
687251881Speter                              apr_pool_t *pool);
688251881Speter
689251881Speter/** Similar to svn_diff_file_output_unified2(), but with @a header_encoding
690251881Speter * set to @c APR_LOCALE_CHARSET.
691251881Speter *
692251881Speter * @deprecated Provided for backward compatibility with the 1.2 API.
693251881Speter */
694251881SpeterSVN_DEPRECATED
695251881Spetersvn_error_t *
696251881Spetersvn_diff_file_output_unified(svn_stream_t *output_stream,
697251881Speter                             svn_diff_t *diff,
698251881Speter                             const char *original_path,
699251881Speter                             const char *modified_path,
700251881Speter                             const char *original_header,
701251881Speter                             const char *modified_header,
702251881Speter                             apr_pool_t *pool);
703251881Speter
704251881Speter
705251881Speter/** A convenience function to produce diff3 output from the
706251881Speter * diff generated by svn_diff_file_diff3().
707251881Speter *
708251881Speter * Output a @a diff between @a original_path, @a modified_path and
709251881Speter * @a latest_path in merged format to @a output_stream.  Optionally supply
710251881Speter * @a conflict_modified, @a conflict_original, @a conflict_separator and/or
711251881Speter * @a conflict_latest to be displayed as conflict markers in the output.
712251881Speter * If @a conflict_original, @a conflict_modified, @a conflict_latest and/or
713251881Speter * @a conflict_separator is @c NULL, a default marker will be displayed.
714362181Sdim * @a conflict_style dictates how conflicts are displayed.
715289180Speter * Uses @a scratch_pool for temporary allocations.
716251881Speter *
717289180Speter * If not @c NULL, call @a cancel_func with @a cancel_baton once or multiple
718289180Speter * times while processing larger diffs.
719289180Speter *
720289180Speter * @since New in 1.9.
721289180Speter */
722289180Spetersvn_error_t *
723289180Spetersvn_diff_file_output_merge3(svn_stream_t *output_stream,
724289180Speter                            svn_diff_t *diff,
725289180Speter                            const char *original_path,
726289180Speter                            const char *modified_path,
727289180Speter                            const char *latest_path,
728289180Speter                            const char *conflict_original,
729289180Speter                            const char *conflict_modified,
730289180Speter                            const char *conflict_latest,
731289180Speter                            const char *conflict_separator,
732289180Speter                            svn_diff_conflict_display_style_t conflict_style,
733289180Speter                            svn_cancel_func_t cancel_func,
734289180Speter                            void *cancel_baton,
735289180Speter                            apr_pool_t *scratch_pool);
736289180Speter
737289180Speter/** Similar to svn_diff_file_output_merge3, but without cancel support.
738289180Speter *
739251881Speter * @since New in 1.6.
740289180Speter *
741289180Speter * @deprecated Provided for backward compatibility with the 1.8 API.
742251881Speter */
743289180SpeterSVN_DEPRECATED
744251881Spetersvn_error_t *
745251881Spetersvn_diff_file_output_merge2(svn_stream_t *output_stream,
746251881Speter                            svn_diff_t *diff,
747251881Speter                            const char *original_path,
748251881Speter                            const char *modified_path,
749251881Speter                            const char *latest_path,
750251881Speter                            const char *conflict_original,
751251881Speter                            const char *conflict_modified,
752251881Speter                            const char *conflict_latest,
753251881Speter                            const char *conflict_separator,
754251881Speter                            svn_diff_conflict_display_style_t conflict_style,
755251881Speter                            apr_pool_t *pool);
756251881Speter
757251881Speter
758251881Speter/** Similar to svn_diff_file_output_merge2, but with @a
759251881Speter * display_original_in_conflict and @a display_resolved_conflicts
760251881Speter * booleans instead of the @a conflict_style enum.
761251881Speter *
762251881Speter * If both booleans are false, acts like
763251881Speter * svn_diff_conflict_display_modified_latest; if @a
764251881Speter * display_original_in_conflict is true, acts like
765251881Speter * svn_diff_conflict_display_modified_original_latest; if @a
766251881Speter * display_resolved_conflicts is true, acts like
767251881Speter * svn_diff_conflict_display_resolved_modified_latest.  The booleans
768251881Speter * may not both be true.
769251881Speter *
770251881Speter * @deprecated Provided for backward compatibility with the 1.5 API.
771251881Speter */
772251881SpeterSVN_DEPRECATED
773251881Spetersvn_error_t *
774251881Spetersvn_diff_file_output_merge(svn_stream_t *output_stream,
775251881Speter                           svn_diff_t *diff,
776251881Speter                           const char *original_path,
777251881Speter                           const char *modified_path,
778251881Speter                           const char *latest_path,
779251881Speter                           const char *conflict_original,
780251881Speter                           const char *conflict_modified,
781251881Speter                           const char *conflict_latest,
782251881Speter                           const char *conflict_separator,
783251881Speter                           svn_boolean_t display_original_in_conflict,
784251881Speter                           svn_boolean_t display_resolved_conflicts,
785251881Speter                           apr_pool_t *pool);
786251881Speter
787289180Speter/** Creates a git-like binary diff hunk describing the differences between
788289180Speter * @a original and @a latest. It does this by either producing either the
789289180Speter * literal content of both versions in a compressed format, or by describing
790289180Speter * one way transforms.
791289180Speter *
792289180Speter * Either @a original or @a latest may be NULL to describe that the version
793289180Speter * didn't exist.
794289180Speter *
795289180Speter * Writes the output to @a output_stream.
796289180Speter *
797289180Speter * If not @c NULL, call @a cancel_func with @a cancel_baton once or multiple
798289180Speter * times while processing larger diffs.
799289180Speter *
800289180Speter * @since New in 1.9.
801289180Speter */
802289180Spetersvn_error_t *
803289180Spetersvn_diff_output_binary(svn_stream_t *output_stream,
804289180Speter                       svn_stream_t *original,
805289180Speter                       svn_stream_t *latest,
806289180Speter                       svn_cancel_func_t cancel_func,
807289180Speter                       void *cancel_baton,
808289180Speter                       apr_pool_t *scratch_pool);
809251881Speter
810251881Speter/* Diffs on in-memory structures */
811251881Speter
812251881Speter/** Generate @a diff output from the @a original and @a modified
813251881Speter * in-memory strings.  @a diff will be allocated from @a pool.
814251881Speter *
815251881Speter * @since New in 1.5.
816251881Speter */
817251881Spetersvn_error_t *
818251881Spetersvn_diff_mem_string_diff(svn_diff_t **diff,
819251881Speter                         const svn_string_t *original,
820251881Speter                         const svn_string_t *modified,
821251881Speter                         const svn_diff_file_options_t *options,
822251881Speter                         apr_pool_t *pool);
823251881Speter
824251881Speter
825251881Speter/** Generate @a diff output from the @a original, @a modified and @a latest
826251881Speter * in-memory strings.  @a diff will be allocated in @a pool.
827251881Speter *
828251881Speter * @since New in 1.5.
829251881Speter */
830251881Spetersvn_error_t *
831251881Spetersvn_diff_mem_string_diff3(svn_diff_t **diff,
832251881Speter                          const svn_string_t *original,
833251881Speter                          const svn_string_t *modified,
834251881Speter                          const svn_string_t *latest,
835251881Speter                          const svn_diff_file_options_t *options,
836251881Speter                          apr_pool_t *pool);
837251881Speter
838251881Speter
839251881Speter/** Generate @a diff output from the @a original, @a modified and @a latest
840251881Speter * in-memory strings, using @a ancestor.  @a diff will be allocated in @a pool.
841251881Speter *
842251881Speter * @since New in 1.5.
843251881Speter */
844251881Spetersvn_error_t *
845251881Spetersvn_diff_mem_string_diff4(svn_diff_t **diff,
846251881Speter                          const svn_string_t *original,
847251881Speter                          const svn_string_t *modified,
848251881Speter                          const svn_string_t *latest,
849251881Speter                          const svn_string_t *ancestor,
850251881Speter                          const svn_diff_file_options_t *options,
851251881Speter                          apr_pool_t *pool);
852251881Speter
853251881Speter/** Outputs the @a diff object generated by svn_diff_mem_string_diff()
854251881Speter * in unified diff format on @a output_stream, using @a original
855251881Speter * and @a modified for the text in the output.
856251881Speter *
857251881Speter * If @a with_diff_header is TRUE, write a diff header ("---" and "+++"
858251881Speter * lines), using @a original_header and @a modified_header to fill the field
859251881Speter * after the "---" and "+++" markers; otherwise @a original_header and
860251881Speter * @a modified_header are ignored and may be NULL.
861251881Speter *
862251881Speter * Outputs the header and hunk delimiters in @a header_encoding.
863251881Speter * A @a hunk_delimiter can optionally be specified.
864251881Speter * If @a hunk_delimiter is NULL, use the default hunk delimiter "@@".
865251881Speter *
866251881Speter * As a special case, if the hunk delimiter is "##", then for an incomplete
867251881Speter * final line use the text "\ No newline at end of property" instead of
868251881Speter * "\ No newline at end of file".
869251881Speter *
870289180Speter * If @a context_size is not negative, then this number of context lines
871289180Speter * will be used in the generated diff output. Otherwise the legacy compile
872289180Speter * time default will be used.
873289180Speter *
874289180Speter * If not @c NULL, call @a cancel_func with @a cancel_baton once or multiple
875289180Speter * times while processing larger diffs.
876289180Speter *
877289180Speter * Uses @a scratch_pool for temporary allocations.
878289180Speter *
879289180Speter * @since New in 1.9
880289180Speter */
881289180Spetersvn_error_t *
882289180Spetersvn_diff_mem_string_output_unified3(svn_stream_t *output_stream,
883289180Speter                                    svn_diff_t *diff,
884289180Speter                                    svn_boolean_t with_diff_header,
885289180Speter                                    const char *hunk_delimiter,
886289180Speter                                    const char *original_header,
887289180Speter                                    const char *modified_header,
888289180Speter                                    const char *header_encoding,
889289180Speter                                    const svn_string_t *original,
890289180Speter                                    const svn_string_t *modified,
891289180Speter                                    int context_size,
892289180Speter                                    svn_cancel_func_t cancel_func,
893289180Speter                                    void *cancel_baton,
894289180Speter                                    apr_pool_t *scratch_pool);
895289180Speter
896289180Speter/** Similar to svn_diff_mem_string_output_unified3() but without
897289180Speter * cancel support and with @a context_size set to -1.
898289180Speter *
899251881Speter * @since New in 1.7. Hunk delimiter "##" has the special meaning since 1.8.
900289180Speter *
901289180Speter * @deprecated Provided for backwards compatibility with the 1.8 API.
902251881Speter */
903289180SpeterSVN_DEPRECATED
904251881Spetersvn_error_t *
905251881Spetersvn_diff_mem_string_output_unified2(svn_stream_t *output_stream,
906251881Speter                                    svn_diff_t *diff,
907251881Speter                                    svn_boolean_t with_diff_header,
908251881Speter                                    const char *hunk_delimiter,
909251881Speter                                    const char *original_header,
910251881Speter                                    const char *modified_header,
911251881Speter                                    const char *header_encoding,
912251881Speter                                    const svn_string_t *original,
913251881Speter                                    const svn_string_t *modified,
914251881Speter                                    apr_pool_t *pool);
915251881Speter
916251881Speter/** Similar to svn_diff_mem_string_output_unified2() but with
917251881Speter * @a with_diff_header always set to TRUE and @a hunk_delimiter always
918251881Speter * set to NULL.
919251881Speter *
920251881Speter * @since New in 1.5.
921289180Speter *
922289180Speter * @deprecated Provided for backwards compatibility with the 1.8 API.
923251881Speter */
924289180SpeterSVN_DEPRECATED
925251881Spetersvn_error_t *
926251881Spetersvn_diff_mem_string_output_unified(svn_stream_t *output_stream,
927251881Speter                                   svn_diff_t *diff,
928251881Speter                                   const char *original_header,
929251881Speter                                   const char *modified_header,
930251881Speter                                   const char *header_encoding,
931251881Speter                                   const svn_string_t *original,
932251881Speter                                   const svn_string_t *modified,
933251881Speter                                   apr_pool_t *pool);
934251881Speter
935251881Speter/** Output the @a diff generated by svn_diff_mem_string_diff3() in diff3
936251881Speter * format on @a output_stream, using @a original, @a modified and @a latest
937251881Speter * for content changes.
938251881Speter *
939251881Speter * Use the conflict markers @a conflict_original, @a conflict_modified,
940251881Speter * @a conflict_latest and @a conflict_separator or the default one for
941251881Speter * each of these if @c NULL is passed.
942251881Speter *
943251881Speter * @a conflict_style dictates how conflicts are displayed.
944251881Speter *
945289180Speter * If not @c NULL, call @a cancel_func with @a cancel_baton once or multiple
946289180Speter * times while processing larger diffs.
947289180Speter *
948289180Speter * Uses @a scratch_pool for temporary allocations.
949289180Speter *
950289180Speter * @since New in 1.9.
951289180Speter */
952289180Spetersvn_error_t *
953289180Spetersvn_diff_mem_string_output_merge3(svn_stream_t *output_stream,
954289180Speter                                  svn_diff_t *diff,
955289180Speter                                  const svn_string_t *original,
956289180Speter                                  const svn_string_t *modified,
957289180Speter                                  const svn_string_t *latest,
958289180Speter                                  const char *conflict_original,
959289180Speter                                  const char *conflict_modified,
960289180Speter                                  const char *conflict_latest,
961289180Speter                                  const char *conflict_separator,
962289180Speter                                  svn_diff_conflict_display_style_t style,
963289180Speter                                  svn_cancel_func_t cancel_func,
964289180Speter                                  void *cancel_baton,
965289180Speter                                  apr_pool_t *scratch_pool);
966289180Speter
967289180Speter/** Similar to svn_diff_mem_string_output_merge2(), but without cancel support.
968289180Speter *
969251881Speter * @since New in 1.6.
970289180Speter *
971289180Speter * @deprecated Provided for backwards compatibility with the 1.8 API.
972251881Speter */
973289180SpeterSVN_DEPRECATED
974251881Spetersvn_error_t *
975251881Spetersvn_diff_mem_string_output_merge2(svn_stream_t *output_stream,
976251881Speter                                  svn_diff_t *diff,
977251881Speter                                  const svn_string_t *original,
978251881Speter                                  const svn_string_t *modified,
979251881Speter                                  const svn_string_t *latest,
980251881Speter                                  const char *conflict_original,
981251881Speter                                  const char *conflict_modified,
982251881Speter                                  const char *conflict_latest,
983251881Speter                                  const char *conflict_separator,
984251881Speter                                  svn_diff_conflict_display_style_t style,
985251881Speter                                  apr_pool_t *pool);
986251881Speter
987251881Speter/** Similar to svn_diff_mem_string_output_merge2, but with @a
988251881Speter * display_original_in_conflict and @a display_resolved_conflicts
989251881Speter * booleans instead of the @a conflict_style enum.
990251881Speter *
991251881Speter * If both booleans are false, acts like
992251881Speter * svn_diff_conflict_display_modified_latest; if @a
993251881Speter * display_original_in_conflict is true, acts like
994251881Speter * svn_diff_conflict_display_modified_original_latest; if @a
995251881Speter * display_resolved_conflicts is true, acts like
996251881Speter * svn_diff_conflict_display_resolved_modified_latest.  The booleans
997251881Speter * may not both be true.
998251881Speter *
999251881Speter * @deprecated Provided for backward compatibility with the 1.5 API.
1000251881Speter */
1001251881SpeterSVN_DEPRECATED
1002251881Spetersvn_error_t *
1003251881Spetersvn_diff_mem_string_output_merge(svn_stream_t *output_stream,
1004251881Speter                                 svn_diff_t *diff,
1005251881Speter                                 const svn_string_t *original,
1006251881Speter                                 const svn_string_t *modified,
1007251881Speter                                 const svn_string_t *latest,
1008251881Speter                                 const char *conflict_original,
1009251881Speter                                 const char *conflict_modified,
1010251881Speter                                 const char *conflict_latest,
1011251881Speter                                 const char *conflict_separator,
1012251881Speter                                 svn_boolean_t display_original_in_conflict,
1013251881Speter                                 svn_boolean_t display_resolved_conflicts,
1014251881Speter                                 apr_pool_t *pool);
1015251881Speter
1016251881Speter
1017251881Speter
1018251881Speter/* Diff parsing. If you want to apply a patch to a working copy
1019251881Speter * rather than parse it, see svn_client_patch(). */
1020251881Speter
1021251881Speter/**
1022251881Speter * Describes what operation has been performed on a file.
1023251881Speter *
1024251881Speter * @since New in 1.7.
1025251881Speter */
1026251881Spetertypedef enum svn_diff_operation_kind_e
1027251881Speter{
1028251881Speter  svn_diff_op_unchanged,
1029251881Speter  svn_diff_op_added,
1030251881Speter  svn_diff_op_deleted,
1031251881Speter  svn_diff_op_copied,
1032251881Speter  svn_diff_op_moved,
1033251881Speter  /* There's no tree changes, just text modifications. */
1034251881Speter  svn_diff_op_modified
1035251881Speter} svn_diff_operation_kind_t;
1036251881Speter
1037251881Speter/**
1038251881Speter * A single hunk inside a patch.
1039251881Speter *
1040251881Speter * The lines of text comprising the hunk can be interpreted in three ways:
1041251881Speter *   - diff text       The hunk as it appears in the unidiff patch file,
1042251881Speter *                     including the hunk header line ("@@ ... @@")
1043251881Speter *   - original text   The text the patch was based on.
1044251881Speter *   - modified text   The result of patching the original text.
1045251881Speter *
1046251881Speter * For example, consider a hunk with the following diff text:
1047251881Speter *
1048251881Speter * @verbatim
1049251881Speter     @@ -1,5 +1,5 @@
1050251881Speter      #include <stdio.h>
1051251881Speter      int main(int argc, char *argv[]) {
1052251881Speter     -        printf("Hello World!\n");
1053251881Speter     +        printf("I like Subversion!\n");
1054251881Speter      } @endverbatim
1055251881Speter *
1056251881Speter * The original text of this hunk is:
1057251881Speter *
1058251881Speter * @verbatim
1059251881Speter     #include <stdio.h>
1060251881Speter     int main(int argc, char *argv[]) {
1061251881Speter             printf("Hello World!\n");
1062251881Speter     } @endverbatim
1063251881Speter *
1064251881Speter * And the modified text is:
1065251881Speter *
1066251881Speter * @verbatim
1067251881Speter     #include <stdio.h>
1068251881Speter     int main(int argc, char *argv[]) {
1069251881Speter             printf("I like Subversion!\n");
1070251881Speter     } @endverbatim
1071251881Speter *
1072251881Speter * @see svn_diff_hunk_readline_diff_text()
1073251881Speter * @see svn_diff_hunk_readline_original_text()
1074251881Speter * @see svn_diff_hunk_readline_modified_text()
1075251881Speter *
1076251881Speter * @since New in 1.7. */
1077251881Spetertypedef struct svn_diff_hunk_t svn_diff_hunk_t;
1078251881Speter
1079251881Speter/**
1080251881Speter * Allocate @a *stringbuf in @a result_pool, and read into it one line
1081262250Speter * of the diff text of @a hunk. The hunk header is not returned only the
1082289180Speter * unidiff data lines (starting with '+', '-', or ' ') are returned.
1083251881Speter * If the @a hunk is being interpreted in reverse (i.e. the reverse
1084251881Speter * parameter of svn_diff_parse_next_patch() was @c TRUE), the diff
1085251881Speter * text will be returned in reversed form.
1086251881Speter * The line-terminator is detected automatically and stored in @a *eol
1087251881Speter * if @a eol is not NULL.
1088251881Speter * If EOF is reached, set @a *eof to TRUE, and set @a *eol to NULL if the
1089251881Speter * hunk does not end with a newline character and @a eol is not NULL.
1090251881Speter * Temporary allocations will be performed in @a scratch_pool.
1091251881Speter *
1092289180Speter * @note The hunk header information can be retrieved with the following
1093289180Speter * functions:
1094262250Speter * @see svn_diff_hunk_get_original_start()
1095262250Speter * @see svn_diff_hunk_get_original_length()
1096262250Speter * @see svn_diff_hunk_get_modified_start()
1097262250Speter * @see svn_diff_hunk_get_modified_length()
1098262250Speter *
1099251881Speter * @since New in 1.7.
1100251881Speter */
1101251881Spetersvn_error_t *
1102251881Spetersvn_diff_hunk_readline_diff_text(svn_diff_hunk_t *hunk,
1103251881Speter                                 svn_stringbuf_t **stringbuf,
1104251881Speter                                 const char **eol,
1105251881Speter                                 svn_boolean_t *eof,
1106251881Speter                                 apr_pool_t *result_pool,
1107251881Speter                                 apr_pool_t *scratch_pool);
1108251881Speter
1109251881Speter/**
1110251881Speter * Allocate @a *stringbuf in @a result_pool, and read into it one line
1111251881Speter * of the original text of @a hunk.
1112251881Speter * The line-terminator is detected automatically and stored in @a *eol
1113251881Speter * if @a eol is not NULL.
1114251881Speter * If EOF is reached, set @a *eof to TRUE, and set @a *eol to NULL if the
1115251881Speter * hunk text does not end with a newline character and @a eol is not NULL.
1116251881Speter * Temporary allocations will be performed in @a scratch_pool.
1117251881Speter *
1118251881Speter * @see svn_diff_hunk_t
1119251881Speter * @since New in 1.7.
1120251881Speter */
1121251881Spetersvn_error_t *
1122251881Spetersvn_diff_hunk_readline_original_text(svn_diff_hunk_t *hunk,
1123251881Speter                                     svn_stringbuf_t **stringbuf,
1124251881Speter                                     const char **eol,
1125251881Speter                                     svn_boolean_t *eof,
1126251881Speter                                     apr_pool_t *result_pool,
1127251881Speter                                     apr_pool_t *scratch_pool);
1128251881Speter
1129251881Speter/**
1130251881Speter * Like svn_diff_hunk_readline_original_text(), but it returns lines from
1131251881Speter * the modified text of the hunk.
1132251881Speter *
1133251881Speter * @see svn_diff_hunk_t
1134251881Speter * @since New in 1.7.
1135251881Speter */
1136251881Spetersvn_error_t *
1137251881Spetersvn_diff_hunk_readline_modified_text(svn_diff_hunk_t *hunk,
1138251881Speter                                     svn_stringbuf_t **stringbuf,
1139251881Speter                                     const char **eol,
1140251881Speter                                     svn_boolean_t *eof,
1141251881Speter                                     apr_pool_t *result_pool,
1142251881Speter                                     apr_pool_t *scratch_pool);
1143251881Speter
1144251881Speter/** Reset the diff text of @a hunk so it can be read again from the start.
1145251881Speter * @since New in 1.7. */
1146251881Spetervoid
1147251881Spetersvn_diff_hunk_reset_diff_text(svn_diff_hunk_t *hunk);
1148251881Speter
1149251881Speter/** Reset the original text of @a hunk so it can be read again from the start.
1150251881Speter * @since New in 1.7. */
1151251881Spetervoid
1152251881Spetersvn_diff_hunk_reset_original_text(svn_diff_hunk_t *hunk);
1153251881Speter
1154251881Speter/** Reset the modified text of @a hunk so it can be read again from the start.
1155251881Speter * @since New in 1.7. */
1156251881Spetervoid
1157251881Spetersvn_diff_hunk_reset_modified_text(svn_diff_hunk_t *hunk);
1158251881Speter
1159251881Speter/** Return the line offset of the original hunk text,
1160251881Speter * as parsed from the hunk header.
1161251881Speter * @since New in 1.7. */
1162251881Spetersvn_linenum_t
1163251881Spetersvn_diff_hunk_get_original_start(const svn_diff_hunk_t *hunk);
1164251881Speter
1165251881Speter/** Return the number of lines in the original @a hunk text,
1166251881Speter * as parsed from the hunk header.
1167251881Speter * @since New in 1.7. */
1168251881Spetersvn_linenum_t
1169251881Spetersvn_diff_hunk_get_original_length(const svn_diff_hunk_t *hunk);
1170251881Speter
1171251881Speter/** Return the line offset of the modified @a hunk text,
1172251881Speter * as parsed from the hunk header.
1173251881Speter * @since New in 1.7. */
1174251881Spetersvn_linenum_t
1175251881Spetersvn_diff_hunk_get_modified_start(const svn_diff_hunk_t *hunk);
1176251881Speter
1177251881Speter/** Return the number of lines in the modified @a hunk text,
1178251881Speter * as parsed from the hunk header.
1179251881Speter * @since New in 1.7. */
1180251881Spetersvn_linenum_t
1181251881Spetersvn_diff_hunk_get_modified_length(const svn_diff_hunk_t *hunk);
1182251881Speter
1183251881Speter/** Return the number of lines of leading context of @a hunk,
1184251881Speter * i.e. the number of lines starting with ' ' before the first line
1185251881Speter * that starts with a '+' or '-'.
1186251881Speter * @since New in 1.7. */
1187251881Spetersvn_linenum_t
1188251881Spetersvn_diff_hunk_get_leading_context(const svn_diff_hunk_t *hunk);
1189251881Speter
1190251881Speter/** Return the number of lines of trailing context of @a hunk,
1191251881Speter * i.e. the number of lines starting with ' ' after the last line
1192251881Speter * that starts with a '+' or '-'.
1193251881Speter * @since New in 1.7. */
1194251881Spetersvn_linenum_t
1195251881Spetersvn_diff_hunk_get_trailing_context(const svn_diff_hunk_t *hunk);
1196251881Speter
1197251881Speter/**
1198251881Speter * Data type to manage parsing of properties in patches.
1199251881Speter * API users should not allocate structures of this type directly.
1200251881Speter *
1201251881Speter * @since New in 1.7. */
1202251881Spetertypedef struct svn_prop_patch_t {
1203251881Speter  const char *name;
1204251881Speter
1205251881Speter  /** Represents the operation performed on the property */
1206251881Speter  svn_diff_operation_kind_t operation;
1207251881Speter
1208251881Speter  /**
1209251881Speter   * An array containing an svn_diff_hunk_t object for each hunk parsed
1210251881Speter   * from the patch associated with our property name */
1211251881Speter  apr_array_header_t *hunks;
1212251881Speter} svn_prop_patch_t;
1213251881Speter
1214251881Speter/**
1215362181Sdim * A binary patch representation. This basically describes replacing one
1216362181Sdim * exact binary representation with another one.
1217362181Sdim *
1218362181Sdim * @since New in 1.10. */
1219362181Sdimtypedef struct svn_diff_binary_patch_t svn_diff_binary_patch_t;
1220362181Sdim
1221362181Sdim/**
1222362181Sdim * Creates a stream allocated in @a result_pool from which the original
1223362181Sdim * (pre-patch-application) version of the binary patched file can be read.
1224362181Sdim *
1225362181Sdim * @note Like many svn_diff_get functions over patches, this is implemented
1226362181Sdim * as reading from the backing patch file. Therefore it is recommended to
1227362181Sdim * read the whole stream before using other functions on the same patch file.
1228362181Sdim *
1229362181Sdim * @since New in 1.10 */
1230362181Sdimsvn_stream_t *
1231362181Sdimsvn_diff_get_binary_diff_original_stream(const svn_diff_binary_patch_t *bpatch,
1232362181Sdim                                         apr_pool_t *result_pool);
1233362181Sdim
1234362181Sdim/**
1235362181Sdim * Creates a stream allocated in @a result_pool from which the resulting
1236362181Sdim * (post-patch-application) version of the binary patched file can be read.
1237362181Sdim *
1238362181Sdim * @note Like many svn_diff_get functions over patches, this is implemented
1239362181Sdim * as reading from the backing patch file. Therefore it is recommended to
1240362181Sdim * read the whole stream before using other functions on the same patch file.
1241362181Sdim *
1242362181Sdim * @since New in 1.10 */
1243362181Sdimsvn_stream_t *
1244362181Sdimsvn_diff_get_binary_diff_result_stream(const svn_diff_binary_patch_t *bpatch,
1245362181Sdim                                       apr_pool_t *result_pool);
1246362181Sdim
1247362181Sdim/**
1248251881Speter * Data type to manage parsing of patches.
1249362181Sdim *
1250362181Sdim * Represents a patch to one target file.
1251362181Sdim *
1252251881Speter * API users should not allocate structures of this type directly.
1253251881Speter *
1254251881Speter * @since New in 1.7. */
1255251881Spetertypedef struct svn_patch_t {
1256251881Speter  /**
1257251881Speter   * The old and new file names as retrieved from the patch file.
1258251881Speter   * These paths are UTF-8 encoded and canonicalized, but otherwise
1259251881Speter   * left unchanged from how they appeared in the patch file. */
1260251881Speter  const char *old_filename;
1261251881Speter  const char *new_filename;
1262251881Speter
1263251881Speter  /**
1264251881Speter   * An array containing an svn_diff_hunk_t * for each hunk parsed
1265251881Speter   * from the patch. */
1266251881Speter  apr_array_header_t *hunks;
1267251881Speter
1268251881Speter  /**
1269251881Speter   * A hash table keyed by property names containing svn_prop_patch_t
1270251881Speter   * object for each property parsed from the patch. */
1271251881Speter  apr_hash_t *prop_patches;
1272251881Speter
1273251881Speter  /**
1274251881Speter   * Represents the operation performed on the file. */
1275251881Speter  svn_diff_operation_kind_t operation;
1276251881Speter
1277251881Speter  /**
1278362181Sdim   * Indicates whether the patch is being interpreted in reverse.
1279362181Sdim   * ### If so, how does this affect the interpretation of other fields?
1280362181Sdim   */
1281251881Speter  svn_boolean_t reverse;
1282289180Speter
1283289180Speter  /**
1284289180Speter   * Mergeinfo parsed from svn:mergeinfo diff data, with one entry for
1285289180Speter   * forward merges and one for reverse merges.
1286289180Speter   * Either entry can be @c NULL if no such merges are part of the diff.
1287289180Speter   * @since New in 1.9. */
1288289180Speter  svn_mergeinfo_t mergeinfo;
1289289180Speter  svn_mergeinfo_t reverse_mergeinfo;
1290362181Sdim
1291362181Sdim  /**
1292362181Sdim   * Declares that there is a binary conflict and contains the information
1293362181Sdim   * to apply it as parsed from the file.
1294362181Sdim   * @since New in 1.10. */
1295362181Sdim  svn_diff_binary_patch_t *binary_patch;
1296362181Sdim
1297362181Sdim  /** The old and new executability bits, as retrieved from the patch file, from
1298362181Sdim   * the git-like mode headers.
1299362181Sdim   *
1300362181Sdim   * A patch may specify an executability change via @a old_executable_bit and
1301362181Sdim   * @a new_executable_bit, via a #SVN_PROP_EXECUTABLE propchange hunk, or both
1302362181Sdim   * ways. It is upto caller how to decide how conflicting information is
1303362181Sdim   * handled.
1304362181Sdim   *
1305362181Sdim   * #svn_tristate_unknown indicates the patch does not specify the
1306362181Sdim   * corresponding bit.
1307362181Sdim   *
1308362181Sdim   * @since New in 1.10.
1309362181Sdim   */
1310362181Sdim  svn_tristate_t old_executable_bit;
1311362181Sdim  svn_tristate_t new_executable_bit;
1312362181Sdim
1313362181Sdim  /** The old and new symlink bits, as retrieved from the patch file, from
1314362181Sdim  * the git-like mode headers.
1315362181Sdim  *
1316362181Sdim  * A patch may specify a symlink change via @a old_symlink_bit and
1317362181Sdim  * @a new_symlink_bit, via a #SVN_PROP_SPECIAL propchange hunk, or both
1318362181Sdim  * ways. It is upto caller how to decide how conflicting information is
1319362181Sdim  * handled. Most implementations will currently just describe a replacement
1320362181Sdim  * of the file though.
1321362181Sdim  *
1322362181Sdim  * #svn_tristate_unknown indicates the patch does not specify the
1323362181Sdim  * corresponding bit.
1324362181Sdim  *
1325362181Sdim  * @since New in 1.10.
1326362181Sdim  */
1327362181Sdim  svn_tristate_t old_symlink_bit;
1328362181Sdim  svn_tristate_t new_symlink_bit;
1329251881Speter} svn_patch_t;
1330251881Speter
1331251881Speter/** An opaque type representing an open patch file.
1332251881Speter *
1333251881Speter * @since New in 1.7. */
1334251881Spetertypedef struct svn_patch_file_t svn_patch_file_t;
1335251881Speter
1336251881Speter/** Open @a patch_file at @a local_abspath.
1337251881Speter * Allocate @a patch_file in @a result_pool.
1338251881Speter *
1339251881Speter * @since New in 1.7. */
1340251881Spetersvn_error_t *
1341251881Spetersvn_diff_open_patch_file(svn_patch_file_t **patch_file,
1342251881Speter                         const char *local_abspath,
1343251881Speter                         apr_pool_t *result_pool);
1344251881Speter
1345251881Speter/**
1346251881Speter * Return the next @a *patch in @a patch_file.
1347251881Speter * If no patch can be found, set @a *patch to NULL.
1348251881Speter * If @a reverse is TRUE, invert the patch while parsing it.
1349251881Speter * If @a ignore_whitespace is TRUE, allow patches with no leading
1350251881Speter * whitespace to be parsed.
1351251881Speter * Allocate results in @a result_pool.
1352251881Speter * Use @a scratch_pool for all other allocations.
1353251881Speter *
1354251881Speter * @since New in 1.7. */
1355251881Spetersvn_error_t *
1356251881Spetersvn_diff_parse_next_patch(svn_patch_t **patch,
1357251881Speter                          svn_patch_file_t *patch_file,
1358251881Speter                          svn_boolean_t reverse,
1359251881Speter                          svn_boolean_t ignore_whitespace,
1360251881Speter                          apr_pool_t *result_pool,
1361251881Speter                          apr_pool_t *scratch_pool);
1362251881Speter
1363251881Speter/**
1364251881Speter * Dispose of @a patch_file.
1365251881Speter * Use @a scratch_pool for all temporary allocations.
1366251881Speter *
1367251881Speter * @since New in 1.7.
1368251881Speter */
1369251881Spetersvn_error_t *
1370251881Spetersvn_diff_close_patch_file(svn_patch_file_t *patch_file,
1371251881Speter                          apr_pool_t *scratch_pool);
1372251881Speter
1373251881Speter#ifdef __cplusplus
1374251881Speter}
1375251881Speter#endif /* __cplusplus */
1376251881Speter
1377251881Speter#endif /* SVN_DIFF_H */
1378