Subversion
svn_delta.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_delta.h
24  * @brief Delta-parsing
25  */
26 
27 /* ==================================================================== */
28 
29 
30 
31 #ifndef SVN_DELTA_H
32 #define SVN_DELTA_H
33 
34 #include <apr.h>
35 #include <apr_pools.h>
36 #include <apr_hash.h>
37 #include <apr_tables.h>
38 #include <apr_file_io.h> /* for apr_file_t */
39 
40 #include "svn_types.h"
41 #include "svn_string.h"
42 #include "svn_io.h"
43 #include "svn_checksum.h"
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif /* __cplusplus */
48 
49 
50 
51 /** This compression level effectively disables data compression.
52  * However, the data pre-processing costs may still not be zero.
53  *
54  * @since New in 1.7.
55  */
56 #define SVN_DELTA_COMPRESSION_LEVEL_NONE 0
57 
58 /** This is the maximum compression level we can pass to zlib.
59  *
60  * @since New in 1.7.
61  */
62 #define SVN_DELTA_COMPRESSION_LEVEL_MAX 9
63 
64 /** This is the default compression level we pass to zlib. It
65  * should be between 0 and 9, with higher numbers resulting in
66  * better compression rates but slower operation.
67  *
68  * @since New in 1.7.
69  */
70 #define SVN_DELTA_COMPRESSION_LEVEL_DEFAULT 5
71 
72 /**
73  * Get libsvn_delta version information.
74  *
75  * @since New in 1.1.
76  */
77 const svn_version_t *
78 svn_delta_version(void);
79 
80 /**
81  * @defgroup delta_support Delta generation and handling
82  *
83  * @{
84  */
85 
86 /** Text deltas.
87  *
88  * A text delta represents the difference between two strings of
89  * bytes, the `source' string and the `target' string. Given a source
90  * string and a target string, we can compute a text delta; given a
91  * source string and a delta, we can reconstruct the target string.
92  * However, note that deltas are not reversible: you cannot always
93  * reconstruct the source string given the target string and delta.
94  *
95  * Since text deltas can be very large, the interface here allows us
96  * to produce and consume them in pieces. Each piece, represented by
97  * an #svn_txdelta_window_t structure, describes how to produce the
98  * next section of the target string.
99  *
100  * To compute a new text delta:
101  *
102  * - We call svn_txdelta() on the streams we want to compare. That
103  * returns us an #svn_txdelta_stream_t object.
104  *
105  * - We then call svn_txdelta_next_window() on the stream object
106  * repeatedly. Each call returns a new #svn_txdelta_window_t
107  * object, which describes the next portion of the target string.
108  * When svn_txdelta_next_window() returns zero, we are done building
109  * the target string.
110  *
111  * @defgroup svn_delta_txt_delta Text deltas
112  * @{
113  */
114 
115 /** Action codes for text delta instructions. */
117  /* Note: The svndiff implementation relies on the values assigned in
118  * this enumeration matching the instruction encoding values. */
119 
120  /** Append the @a length bytes at @a offset in the source view to the
121  * target.
122  *
123  * It must be the case that 0 <= @a offset < @a offset +
124  * @a length <= size of source view.
125  */
127 
128  /** Append the @a length bytes at @a offset in the target view, to the
129  * target.
130  *
131  * It must be the case that 0 <= @a offset < current position in the
132  * target view.
133  *
134  * However! @a offset + @a length may be *beyond* the end of the existing
135  * target data. "Where the heck does the text come from, then?"
136  * If you start at @a offset, and append @a length bytes one at a time,
137  * it'll work out --- you're adding new bytes to the end at the
138  * same rate you're reading them from the middle. Thus, if your
139  * current target text is "abcdefgh", and you get an #svn_txdelta_target
140  * instruction whose @a offset is 6 and whose @a length is 7,
141  * the resulting string is "abcdefghghghghg". This trick is actually
142  * useful in encoding long runs of consecutive characters, long runs
143  * of CR/LF pairs, etc.
144  */
146 
147  /** Append the @a length bytes at @a offset in the window's @a new string
148  * to the target.
149  *
150  * It must be the case that 0 <= @a offset < @a offset +
151  * @a length <= length of @a new. Windows MUST use new data in ascending
152  * order with no overlap at the moment; svn_txdelta_to_svndiff()
153  * depends on this.
154  */
156 };
157 
158 /** A single text delta instruction. */
159 typedef struct svn_txdelta_op_t
160 {
161  /** Action code of delta instruction */
163  /** Offset of delta, see #svn_delta_action for more details. */
164  apr_size_t offset;
165  /** Number of bytes of delta, see #svn_delta_action for more details. */
166  apr_size_t length;
168 
169 
170 /** An #svn_txdelta_window_t object describes how to reconstruct a
171  * contiguous section of the target string (the "target view") using a
172  * specified contiguous region of the source string (the "source
173  * view"). It contains a series of instructions which assemble the
174  * new target string text by pulling together substrings from:
175  *
176  * - the source view,
177  *
178  * - the previously constructed portion of the target view,
179  *
180  * - a string of new data contained within the window structure
181  *
182  * The source view must always slide forward from one window to the
183  * next; that is, neither the beginning nor the end of the source view
184  * may move to the left as we read from a window stream. This
185  * property allows us to apply deltas to non-seekable source streams
186  * without making a full copy of the source stream.
187  */
188 typedef struct svn_txdelta_window_t
189 {
190 
191  /** The offset of the source view for this window. */
193 
194  /** The length of the source view for this window. */
195  apr_size_t sview_len;
196 
197  /** The length of the target view for this window, i.e. the number of
198  * bytes which will be reconstructed by the instruction stream. */
199  apr_size_t tview_len;
200 
201  /** The number of instructions in this window. */
202  int num_ops;
203 
204  /** The number of svn_txdelta_source instructions in this window. If
205  * this number is 0, we don't need to read the source in order to
206  * reconstruct the target view.
207  */
208  int src_ops;
209 
210  /** The instructions for this window. */
212 
213  /** New data, for use by any `svn_txdelta_new' instructions. */
215 
217 
218 /**
219  * Return a deep copy of @a window, allocated in @a pool.
220  *
221  * @since New in 1.3.
222  */
225  apr_pool_t *pool);
226 
227 /**
228  * Compose two delta windows, yielding a third, allocated in @a pool.
229  *
230  * @since New in 1.4
231  *
232  */
235  const svn_txdelta_window_t *window_B,
236  apr_pool_t *pool);
237 
238 /**
239  * Apply the instructions from @a window to a source view @a sbuf to
240  * produce a target view @a tbuf.
241  *
242  * @a sbuf is assumed to have @a window->sview_len bytes of data and
243  * @a tbuf is assumed to have room for @a tlen bytes of output. @a
244  * tlen may be more than @a window->tview_len, so return the actual
245  * number of bytes written. @a sbuf is not touched and may be NULL if
246  * @a window contains no source-copy operations. This is purely a
247  * memory operation; nothing can go wrong as long as we have a valid
248  * window.
249  *
250  * @since New in 1.4
251  *
252  * @since Since 1.9, @a tbuf may be NULL if @a *tlen is 0.
253  */
254 void
256  const char *sbuf, char *tbuf,
257  apr_size_t *tlen);
258 
259 /** A typedef for functions that consume a series of delta windows, for
260  * use in caller-pushes interfaces. Such functions will typically
261  * apply the delta windows to produce some file, or save the windows
262  * somewhere. At the end of the delta window stream, you must call
263  * this function passing zero for the @a window argument.
264  */
265 typedef svn_error_t *(*svn_txdelta_window_handler_t)(
266  svn_txdelta_window_t *window, void *baton);
267 
268 
269 /** This function will generate delta windows that turn @a source into
270  * @a target, and pushing these windows into the @a handler window handler
271  * callback (passing @a handler_baton to each invocation).
272  *
273  * If @a checksum is not NULL, then a checksum (of kind @a checksum_kind)
274  * will be computed for the target stream, and placed into *checksum.
275  *
276  * If @a cancel_func is not NULL, then it should refer to a cancellation
277  * function (along with @a cancel_baton).
278  *
279  * Results (the checksum) will be allocated from @a result_pool, and all
280  * temporary allocations will be performed in @a scratch_pool.
281  *
282  * Note: this function replaces the combination of svn_txdelta() and
283  * svn_txdelta_send_txstream().
284  *
285  * @since New in 1.6.
286  */
287 svn_error_t *
289  svn_stream_t *target,
291  void *handler_baton,
292  svn_checksum_kind_t checksum_kind,
293  svn_checksum_t **checksum,
294  svn_cancel_func_t cancel_func,
295  void *cancel_baton,
296  apr_pool_t *result_pool,
297  apr_pool_t *scratch_pool);
298 
299 
300 /** A delta stream --- this is the hat from which we pull a series of
301  * svn_txdelta_window_t objects, which, taken in order, describe the
302  * entire target string. This type is defined within libsvn_delta, and
303  * opaque outside that library.
304  */
306 
307 
308 /** A typedef for a function that will set @a *window to the next
309  * window from a #svn_txdelta_stream_t object. If there are no more
310  * delta windows, NULL will be used. The returned window, if any,
311  * will be allocated in @a pool. @a baton is the baton specified
312  * when the stream was created.
313  *
314  * @since New in 1.4.
315  */
316 typedef svn_error_t *
317 (*svn_txdelta_next_window_fn_t)(svn_txdelta_window_t **window,
318  void *baton,
319  apr_pool_t *pool);
320 
321 /** A typedef for a function that will return the md5 checksum of the
322  * fulltext deltified by a #svn_txdelta_stream_t object. Will
323  * return NULL if the final null window hasn't yet been returned by
324  * the stream. The returned value will be allocated in the same pool
325  * as the stream. @a baton is the baton specified when the stream was
326  * created.
327  *
328  * @since New in 1.4.
329  */
330 typedef const unsigned char *
331 (*svn_txdelta_md5_digest_fn_t)(void *baton);
332 
333 /** A typedef for a function that opens an #svn_txdelta_stream_t object,
334  * allocated in @a result_pool. @a baton is provided by the caller.
335  * Any temporary allocations may be performed in @a scratch_pool.
336  *
337  * @since New in 1.10.
338  */
339 typedef svn_error_t *
340 (*svn_txdelta_stream_open_func_t)(svn_txdelta_stream_t **txdelta_stream,
341  void *baton,
342  apr_pool_t *result_pool,
343  apr_pool_t *scratch_pool);
344 
345 /** Create and return a generic text delta stream with @a baton, @a
346  * next_window and @a md5_digest. Allocate the new stream in @a
347  * pool.
348  *
349  * @since New in 1.4.
350  */
352 svn_txdelta_stream_create(void *baton,
353  svn_txdelta_next_window_fn_t next_window,
354  svn_txdelta_md5_digest_fn_t md5_digest,
355  apr_pool_t *pool);
356 
357 /** Set @a *window to a pointer to the next window from the delta stream
358  * @a stream. When we have completely reconstructed the target string,
359  * set @a *window to zero.
360  *
361  * The window will be allocated in @a pool.
362  */
363 svn_error_t *
365  svn_txdelta_stream_t *stream,
366  apr_pool_t *pool);
367 
368 
369 /** Return the md5 digest for the complete fulltext deltified by
370  * @a stream, or @c NULL if @a stream has not yet returned its final
371  * @c NULL window. The digest is allocated in the same memory as @a
372  * STREAM.
373  */
374 const unsigned char *
376 
377 /** Set @a *stream to a pointer to a delta stream that will turn the byte
378  * string from @a source into the byte stream from @a target.
379  *
380  * @a source and @a target are both readable generic streams. When we call
381  * svn_txdelta_next_window() on @a *stream, it will read from @a source and
382  * @a target to gather as much data as it needs. If @a calculate_checksum
383  * is set, you may call svn_txdelta_md5_digest() to get an MD5 checksum
384  * for @a target.
385  *
386  * Do any necessary allocation in a sub-pool of @a pool.
387  *
388  * @since New in 1.8.
389  */
390 void
392  svn_stream_t *source,
393  svn_stream_t *target,
394  svn_boolean_t calculate_checksum,
395  apr_pool_t *pool);
396 
397 /** Similar to svn_txdelta2 but always calculating the target checksum.
398  *
399  * @deprecated Provided for backward compatibility with the 1.7 API.
400  */
402 void
404  svn_stream_t *source,
405  svn_stream_t *target,
406  apr_pool_t *pool);
407 
408 
409 /**
410  * Return a writable stream which, when fed target data, will send
411  * delta windows to @a handler/@a handler_baton which transform the
412  * data in @a source to the target data. As usual, the window handler
413  * will receive a NULL window to signify the end of the window stream.
414  * The stream handler functions will read data from @a source as
415  * necessary.
416  *
417  * @since New in 1.1.
418  */
419 svn_stream_t *
421  void *handler_baton,
422  svn_stream_t *source,
423  apr_pool_t *pool);
424 
425 
426 /** Send the contents of @a string to window-handler @a handler/@a baton.
427  * This is effectively a 'copy' operation, resulting in delta windows that
428  * make the target equivalent to the value of @a string.
429  *
430  * All temporary allocation is performed in @a pool.
431  */
432 svn_error_t *
435  void *handler_baton,
436  apr_pool_t *pool);
437 
438 /** Send the contents of @a stream to window-handler @a handler/@a baton.
439  * This is effectively a 'copy' operation, resulting in delta windows that
440  * make the target equivalent to the stream.
441  *
442  * If @a digest is non-NULL, populate it with the md5 checksum for the
443  * fulltext that was deltified (@a digest must be at least
444  * @c APR_MD5_DIGESTSIZE bytes long).
445  *
446  * All temporary allocation is performed in @a pool.
447  */
448 svn_error_t *
451  void *handler_baton,
452  unsigned char *digest,
453  apr_pool_t *pool);
454 
455 /** Send the contents of @a txstream to window-handler @a handler/@a baton.
456  * Windows will be extracted from the stream and delivered to the handler.
457  *
458  * All temporary allocation is performed in @a pool.
459  */
460 svn_error_t *
463  void *handler_baton,
464  apr_pool_t *pool);
465 
466 
467 /** Send the @a contents of length @a len as a txdelta against an empty
468  * source directly to window-handler @a handler/@a handler_baton.
469  *
470  * All temporary allocation is performed in @a pool.
471  *
472  * @since New in 1.8.
473  */
474 svn_error_t *
475 svn_txdelta_send_contents(const unsigned char *contents,
476  apr_size_t len,
478  void *handler_baton,
479  apr_pool_t *pool);
480 
481 /** Prepare to apply a text delta. @a source is a readable generic stream
482  * yielding the source data, @a target is a writable generic stream to
483  * write target data to, and allocation takes place in a sub-pool of
484  * @a pool. On return, @a *handler is set to a window handler function and
485  * @a *handler_baton is set to the value to pass as the @a baton argument to
486  * @a *handler.
487  *
488  * If @a result_digest is non-NULL, it points to APR_MD5_DIGESTSIZE bytes
489  * of storage, and the final call to @a handler populates it with the
490  * MD5 digest of the resulting fulltext.
491  *
492  * If @a error_info is non-NULL, it is inserted parenthetically into
493  * the error string for any error returned by svn_txdelta_apply() or
494  * @a *handler. (It is normally used to provide path information,
495  * since there's nothing else in the delta application's context to
496  * supply a path for error messages.)
497  *
498  * @note To avoid lifetime issues, @a error_info is copied into
499  * @a pool or a subpool thereof.
500  */
501 void
503  svn_stream_t *target,
504  unsigned char *result_digest,
505  const char *error_info,
506  apr_pool_t *pool,
508  void **handler_baton);
509 
510 
511 
512 
513 /*** Producing and consuming svndiff-format text deltas. ***/
514 
515 /** Prepare to produce an svndiff-format diff from text delta windows.
516  * @a output is a writable generic stream to write the svndiff data to.
517  * Allocation takes place in a sub-pool of @a pool. On return, @a *handler
518  * is set to a window handler function and @a *handler_baton is set to
519  * the value to pass as the @a baton argument to @a *handler. The svndiff
520  * version is @a svndiff_version. @a compression_level is the zlib
521  * compression level from 0 (no compression) and 9 (maximum compression).
522  *
523  * @since New in 1.7. Since 1.10, @a svndiff_version can be 2 for the
524  * svndiff2 format. @a compression_level is currently ignored if
525  * @a svndiff_version is set to 2.
526  */
527 void
529  void **handler_baton,
530  svn_stream_t *output,
531  int svndiff_version,
532  int compression_level,
533  apr_pool_t *pool);
534 
535 /** Similar to svn_txdelta_to_svndiff3(), but always using the SVN default
536  * compression level (#SVN_DELTA_COMPRESSION_LEVEL_DEFAULT).
537  *
538  * @since New in 1.4.
539  * @deprecated Provided for backward compatibility with the 1.6 API.
540  */
542 void
544  void **handler_baton,
545  svn_stream_t *output,
546  int svndiff_version,
547  apr_pool_t *pool);
548 
549 /** Similar to svn_txdelta_to_svndiff2, but always using svndiff
550  * version 0.
551  *
552  * @deprecated Provided for backward compatibility with the 1.3 API.
553  */
555 void
557  apr_pool_t *pool,
559  void **handler_baton);
560 
561 /** Return a readable generic stream which will produce svndiff-encoded
562  * text delta from the delta stream @a txstream. @a svndiff_version and
563  * @a compression_level are same as in svn_txdelta_to_svndiff3().
564  *
565  * Allocate the stream in @a pool.
566  *
567  * @since New in 1.10.
568  */
569 svn_stream_t *
571  int svndiff_version,
572  int compression_level,
573  apr_pool_t *pool);
574 
575 /** Return a writable generic stream which will parse svndiff-format
576  * data into a text delta, invoking @a handler with @a handler_baton
577  * whenever a new window is ready.
578  *
579  * When the caller closes this stream, this will signal completion to
580  * the window handler by invoking @a handler once more, passing zero for
581  * the @c window argument.
582  *
583  * If @a error_on_early_close is @c TRUE, then attempt to avoid
584  * signaling completion to the window handler if the delta was
585  * incomplete. Specifically, attempting to close the stream will be
586  * successful only if the data written to the stream consisted of one or
587  * more complete windows of svndiff data and no extra bytes. Otherwise,
588  * closing the stream will not signal completion to the window handler,
589  * and will return a #SVN_ERR_SVNDIFF_UNEXPECTED_END error. Note that if
590  * no data at all was written, the delta is considered incomplete.
591  *
592  * If @a error_on_early_close is @c FALSE, closing the stream will
593  * signal completion to the window handler, regardless of how much data
594  * was written, and discard any pending incomplete data.
595  *
596  * Allocate the stream in @a pool.
597  */
598 svn_stream_t *
600  void *handler_baton,
601  svn_boolean_t error_on_early_close,
602  apr_pool_t *pool);
603 
604 /**
605  * Read and parse one delta window in svndiff format from the
606  * readable stream @a stream and place it in @a *window, allocating
607  * the result in @a pool. The caller must take responsibility for
608  * stripping off the four-byte 'SVN@<ver@>' header at the beginning of
609  * the svndiff document before reading the first window, and must
610  * provide the version number (the value of the fourth byte) to each
611  * invocation of this routine with the @a svndiff_version argument.
612  *
613  * @since New in 1.1.
614  */
615 svn_error_t *
617  svn_stream_t *stream,
618  int svndiff_version,
619  apr_pool_t *pool);
620 
621 /**
622  * Read and skip one delta window in svndiff format from the
623  * file @a file. @a pool is used for temporary allocations. The
624  * caller must take responsibility for stripping off the four-byte
625  * 'SVN@<ver@>' header at the beginning of the svndiff document before
626  * reading or skipping the first window, and must provide the version
627  * number (the value of the fourth byte) to each invocation of this
628  * routine with the @a svndiff_version argument.
629  *
630  * @since New in 1.1.
631  */
632 svn_error_t *
633 svn_txdelta_skip_svndiff_window(apr_file_t *file,
634  int svndiff_version,
635  apr_pool_t *pool);
636 
637 /** @} */
638 
639 
640 /** Traversing tree deltas.
641  *
642  * In Subversion, we've got various producers and consumers of tree
643  * deltas.
644  *
645  * In processing a `commit' command:
646  * - The client examines its working copy data, and produces a tree
647  * delta describing the changes to be committed.
648  * - The client networking library consumes that delta, and sends them
649  * across the wire as an equivalent series of network requests (for
650  * example, to svnserve as an ra_svn protocol stream, or to an
651  * Apache httpd server as WebDAV commands)
652  * - The server receives those requests and produces a tree delta ---
653  * hopefully equivalent to the one the client produced above.
654  * - The Subversion server module consumes that delta and commits an
655  * appropriate transaction to the filesystem.
656  *
657  * In processing an `update' command, the process is reversed:
658  * - The Subversion server module talks to the filesystem and produces
659  * a tree delta describing the changes necessary to bring the
660  * client's working copy up to date.
661  * - The server consumes this delta, and assembles a reply
662  * representing the appropriate changes.
663  * - The client networking library receives that reply, and produces a
664  * tree delta --- hopefully equivalent to the one the Subversion
665  * server produced above.
666  * - The working copy library consumes that delta, and makes the
667  * appropriate changes to the working copy.
668  *
669  * The simplest approach would be to represent tree deltas using the
670  * obvious data structure. To do an update, the server would
671  * construct a delta structure, and the working copy library would
672  * apply that structure to the working copy; the network layer's job
673  * would simply be to get the structure across the net intact.
674  *
675  * However, we expect that these deltas will occasionally be too large
676  * to fit in a typical workstation's swap area. For example, in
677  * checking out a 200Mb source tree, the entire source tree is
678  * represented by a single tree delta. So it's important to handle
679  * deltas that are too large to fit in swap all at once.
680  *
681  * So instead of representing the tree delta explicitly, we define a
682  * standard way for a consumer to process each piece of a tree delta
683  * as soon as the producer creates it. The #svn_delta_editor_t
684  * structure is a set of callback functions to be defined by a delta
685  * consumer, and invoked by a delta producer. Each invocation of a
686  * callback function describes a piece of the delta --- a file's
687  * contents changing, something being renamed, etc.
688  *
689  * @defgroup svn_delta_tree_deltas Tree deltas
690  * @{
691  */
692 
693 /** A structure full of callback functions the delta source will invoke
694  * as it produces the delta.
695  *
696  * @note Don't try to allocate one of these yourself. Instead, always
697  * use svn_delta_default_editor() or some other constructor, to avoid
698  * backwards compatibility problems if the structure is extended in
699  * future releases and to ensure that unused slots are filled in with
700  * no-op functions.
701  *
702  * <h3>Function Usage</h3>
703  *
704  * Here's how to use these functions to express a tree delta.
705  *
706  * The delta consumer implements the callback functions described in
707  * this structure, and the delta producer invokes them. So the
708  * caller (producer) is pushing tree delta data at the callee
709  * (consumer).
710  *
711  * At the start of traversal, the consumer provides @a edit_baton, a
712  * baton global to the entire delta edit. If there is a target
713  * revision that needs to be set for this operation, the producer
714  * should call the @c set_target_revision function at this point.
715  *
716  * Next, if there are any tree deltas to express, the producer should
717  * pass the @a edit_baton to the @c open_root function, to get a baton
718  * representing root of the tree being edited.
719  *
720  * Most of the callbacks work in the obvious way:
721  *
722  * @c delete_entry
723  * @c add_file
724  * @c add_directory
725  * @c open_file
726  * @c open_directory
727  *
728  * Each of these takes a directory baton, indicating the directory
729  * in which the change takes place, and a @a path argument, giving the
730  * path of the file, subdirectory, or directory entry to change.
731  *
732  * The @a path argument to each of the callbacks is relative to the
733  * root of the edit. Editors will usually want to join this relative
734  * path with some base stored in the edit baton (e.g. a URL, or a
735  * location in the OS filesystem).
736  *
737  * Since every call requires a parent directory baton, including
738  * @c add_directory and @c open_directory, where do we ever get our
739  * initial directory baton, to get things started? The @c open_root
740  * function returns a baton for the top directory of the change. In
741  * general, the producer needs to invoke the editor's @c open_root
742  * function before it can get anything of interest done.
743  *
744  * While @c open_root provides a directory baton for the root of
745  * the tree being changed, the @c add_directory and @c open_directory
746  * callbacks provide batons for other directories. Like the
747  * callbacks above, they take a @a parent_baton and a relative path
748  * @a path, and then return a new baton for the subdirectory being
749  * created / modified --- @a child_baton. The producer can then use
750  * @a child_baton to make further changes in that subdirectory.
751  *
752  * So, if we already have subdirectories named `foo' and `foo/bar',
753  * then the producer can create a new file named `foo/bar/baz.c' by
754  * calling:
755  *
756  * - @c open_root () --- yielding a baton @a root for the top directory
757  *
758  * - @c open_directory (@a root, "foo") --- yielding a baton @a f for `foo'
759  *
760  * - @c open_directory (@a f, "foo/bar") --- yielding a baton @a b for
761  * `foo/bar'
762  *
763  * - @c add_file (@a b, "foo/bar/baz.c")
764  *
765  * When the producer is finished making changes to a directory, it
766  * should call @c close_directory. This lets the consumer do any
767  * necessary cleanup, and free the baton's storage.
768  *
769  * The @c add_file and @c open_file callbacks each return a baton
770  * for the file being created or changed. This baton can then be
771  * passed to @c apply_textdelta or @c apply_textdelta_stream to change
772  * the file's contents, or @c change_file_prop to change the file's
773  * properties. When the producer is finished making changes to a
774  * file, it should call @c close_file, to let the consumer clean up
775  * and free the baton.
776  *
777  * The @c add_file and @c add_directory functions each take arguments
778  * @a copyfrom_path and @a copyfrom_revision. If @a copyfrom_path is
779  * non-@c NULL, then @a copyfrom_path and @a copyfrom_revision indicate where
780  * the file or directory should be copied from (to create the file
781  * or directory being added). In that case, @a copyfrom_path must be
782  * either a path relative to the root of the edit, or a URI from the
783  * repository being edited. If @a copyfrom_path is @c NULL, then @a
784  * copyfrom_revision must be #SVN_INVALID_REVNUM; it is invalid to
785  * pass a mix of valid and invalid copyfrom arguments.
786  *
787  *
788  * <h3>Function Call Ordering</h3>
789  *
790  * There are six restrictions on the order in which the producer
791  * may use the batons:
792  *
793  * 1. The producer may call @c open_directory, @c add_directory,
794  * @c open_file, @c add_file at most once on any given directory
795  * entry. @c delete_entry may be called at most once on any given
796  * directory entry and may later be followed by @c add_directory or
797  * @c add_file on the same directory entry. @c delete_entry may
798  * not be called on any directory entry after @c open_directory,
799  * @c add_directory, @c open_file or @c add_file has been called on
800  * that directory entry.
801  *
802  * 2. The producer may not close a directory baton until it has
803  * closed all batons for its subdirectories.
804  *
805  * 3. When a producer calls @c open_directory or @c add_directory,
806  * it must specify the most recently opened of the currently open
807  * directory batons. Put another way, the producer cannot have
808  * two sibling directory batons open at the same time.
809  *
810  * 4. A producer must call @c change_dir_prop on a directory either
811  * before opening any of the directory's subdirs or after closing
812  * them, but not in the middle.
813  *
814  * 5. When the producer calls @c open_file or @c add_file, either:
815  *
816  * (a) The producer must follow with any changes to the file
817  * (@c change_file_prop and/or @c apply_textdelta /
818  * @c apply_textdelta_stream, as applicable), followed by
819  * a @c close_file call, before issuing any other file or
820  * directory calls, or
821  *
822  * (b) The producer must follow with a @c change_file_prop call if
823  * it is applicable, before issuing any other file or directory
824  * calls; later, after all directory batons including the root
825  * have been closed, the producer must issue @c apply_textdelta /
826  * @c apply_textdelta_stream and @c close_file calls.
827  *
828  * 6. When the producer calls @c apply_textdelta, it must make all of
829  * the window handler calls (including the @c NULL window at the
830  * end) before issuing any other #svn_delta_editor_t calls.
831  *
832  * So, the producer needs to use directory and file batons as if it
833  * is doing a single depth-first traversal of the tree, with the
834  * exception that the producer may keep file batons open in order to
835  * make @c apply_textdelta / @c apply_textdelta_stream calls at the end.
836  *
837  *
838  * <h3>Pool Usage</h3>
839  *
840  * Many editor functions are invoked multiple times, in a sequence
841  * determined by the editor "driver". The driver is responsible for
842  * creating a pool for use on each iteration of the editor function,
843  * and clearing that pool between each iteration. The driver passes
844  * the appropriate pool on each function invocation.
845  *
846  * Based on the requirement of calling the editor functions in a
847  * depth-first style, it is usually customary for the driver to similarly
848  * nest the pools. However, this is only a safety feature to ensure
849  * that pools associated with deeper items are always cleared when the
850  * top-level items are also cleared. The interface does not assume, nor
851  * require, any particular organization of the pools passed to these
852  * functions. In fact, if "postfix deltas" are used for files, the file
853  * pools definitely need to live outside the scope of their parent
854  * directories' pools.
855  *
856  * Note that close_directory can be called *before* a file in that
857  * directory has been closed. That is, the directory's baton is
858  * closed before the file's baton. The implication is that
859  * @c apply_textdelta / @c apply_textdelta_stream and @c close_file
860  * should not refer to a parent directory baton UNLESS the editor has
861  * taken precautions to allocate it in a pool of the appropriate
862  * lifetime (the @a dir_pool passed to @c open_directory and
863  * @c add_directory definitely does not have the proper lifetime).
864  * In general, it is recommended to simply avoid keeping a parent
865  * directory baton in a file baton.
866  *
867  *
868  * <h3>Errors</h3>
869  *
870  * At least one implementation of the editor interface is
871  * asynchronous; an error from one operation may be detected some
872  * number of operations later. As a result, an editor driver must not
873  * assume that an error from an editing function resulted from the
874  * particular operation being detected. Moreover, once an editing
875  * function (including @c close_edit) returns an error, the edit is
876  * dead; the only further operation which may be called on the editor
877  * is @c abort_edit.
878  */
879 typedef struct svn_delta_editor_t
880 {
881  /** Set the target revision for this edit to @a target_revision. This
882  * call, if used, should precede all other editor calls.
883  *
884  * @note This is typically used only for server->client update-type
885  * operations. It doesn't really make much sense for commit-type
886  * operations, because the revision of a commit isn't known until
887  * the commit is finalized.
888  *
889  * Any temporary allocations may be performed in @a scratch_pool.
890  */
891  svn_error_t *(*set_target_revision)(void *edit_baton,
892  svn_revnum_t target_revision,
893  apr_pool_t *scratch_pool);
894 
895  /** Set @a *root_baton to a baton for the top directory of the change.
896  * (This is the top of the subtree being changed, not necessarily
897  * the root of the filesystem.) As with any other directory baton, the
898  * producer should call @c close_directory on @a root_baton when done.
899  * And as with other @c open_* calls, the @a base_revision here is the
900  * current revision of the directory (before getting bumped up to the
901  * new target revision set with @c set_target_revision).
902  *
903  * Allocations for the returned @a root_baton should be performed in
904  * @a result_pool. It is also typical to (possibly) save this pool for
905  * later usage by @c close_directory.
906  */
907  svn_error_t *(*open_root)(void *edit_baton,
908  svn_revnum_t base_revision,
909  apr_pool_t *result_pool,
910  void **root_baton);
911 
912 
913  /** Remove the directory entry at @a path, a child of the directory
914  * represented by @a parent_baton. If @a revision is a valid
915  * revision number, it is used as a sanity check to ensure that you
916  * are really removing the revision of @a path that you think you are.
917  *
918  * Any temporary allocations may be performed in @a scratch_pool.
919  *
920  * @note The @a revision parameter is typically used only for
921  * client->server commit-type operations, allowing the server to
922  * verify that it is deleting what the client thinks it should be
923  * deleting. It only really makes sense in the opposite direction
924  * (during server->client update-type operations) when the trees
925  * whose delta is being described are ancestrally related (that is,
926  * one tree is an ancestor of the other).
927  */
928  svn_error_t *(*delete_entry)(const char *path,
929  svn_revnum_t revision,
930  void *parent_baton,
931  apr_pool_t *scratch_pool);
932 
933 
934  /** We are going to add a new subdirectory at @a path, a child of
935  * the directory represented by @a parent_baton. We will use
936  * the value this callback stores in @a *child_baton as the
937  * parent baton for further changes in the new subdirectory.
938  *
939  * If @a copyfrom_path is non-@c NULL, this add has history (i.e., is a
940  * copy), and the origin of the copy may be recorded as
941  * @a copyfrom_path under @a copyfrom_revision.
942  *
943  * Allocations for the returned @a child_baton should be performed in
944  * @a result_pool. It is also typical to (possibly) save this pool for
945  * later usage by @c close_directory.
946  */
947  svn_error_t *(*add_directory)(const char *path,
948  void *parent_baton,
949  const char *copyfrom_path,
950  svn_revnum_t copyfrom_revision,
951  apr_pool_t *result_pool,
952  void **child_baton);
953 
954  /** We are going to make changes in the subdirectory at @a path, a
955  * child of the directory represented by @a parent_baton.
956  * The callback must store a value in @a *child_baton that
957  * should be used as the parent baton for subsequent changes in this
958  * subdirectory. If a valid revnum, @a base_revision is the current
959  * revision of the subdirectory.
960  *
961  * Allocations for the returned @a child_baton should be performed in
962  * @a result_pool. It is also typical to (possibly) save this pool for
963  * later usage by @c close_directory.
964  */
965  svn_error_t *(*open_directory)(const char *path,
966  void *parent_baton,
967  svn_revnum_t base_revision,
968  apr_pool_t *result_pool,
969  void **child_baton);
970 
971  /** Change the value of a directory's property.
972  * - @a dir_baton specifies the directory whose property should change.
973  * - @a name is the name of the property to change.
974  * - @a value is the new (final) value of the property, or @c NULL if the
975  * property should be removed altogether.
976  *
977  * The callback is guaranteed to be called exactly once for each property
978  * whose value differs between the start and the end of the edit.
979  *
980  * Any temporary allocations may be performed in @a scratch_pool.
981  */
982  svn_error_t *(*change_dir_prop)(void *dir_baton,
983  const char *name,
984  const svn_string_t *value,
985  apr_pool_t *scratch_pool);
986 
987  /** We are done processing a subdirectory, whose baton is @a dir_baton
988  * (set by @c add_directory or @c open_directory). We won't be using
989  * the baton any more, so whatever resources it refers to may now be
990  * freed.
991  *
992  * Any temporary allocations may be performed in @a scratch_pool.
993  */
994  svn_error_t *(*close_directory)(void *dir_baton,
995  apr_pool_t *scratch_pool);
996 
997 
998  /** In the directory represented by @a parent_baton, indicate that
999  * @a path is present as a subdirectory in the edit source, but
1000  * cannot be conveyed to the edit consumer. Currently, this would
1001  * only occur because of authorization restrictions, but may change
1002  * in the future.
1003  *
1004  * Any temporary allocations may be performed in @a scratch_pool.
1005  */
1006  svn_error_t *(*absent_directory)(const char *path,
1007  void *parent_baton,
1008  apr_pool_t *scratch_pool);
1009 
1010  /** We are going to add a new file at @a path, a child of the
1011  * directory represented by @a parent_baton. The callback can
1012  * store a baton for this new file in @a **file_baton; whatever value
1013  * it stores there should be passed through to @c apply_textdelta or
1014  * @c apply_textdelta_stream.
1015  *
1016  * If @a copyfrom_path is non-@c NULL, this add has history (i.e., is a
1017  * copy), and the origin of the copy may be recorded as
1018  * @a copyfrom_path under @a copyfrom_revision.
1019  *
1020  * Allocations for the returned @a file_baton should be performed in
1021  * @a result_pool. It is also typical to save this pool for later usage
1022  * by @c apply_textdelta and possibly @c close_file.
1023  *
1024  * @note Because the editor driver could be employing the "postfix
1025  * deltas" paradigm, @a result_pool could potentially be relatively
1026  * long-lived. Every file baton created by the editor for a given
1027  * editor drive might be resident in memory similtaneously. Editor
1028  * implementations should ideally keep their file batons as
1029  * conservative (memory-usage-wise) as possible, and use @a result_pool
1030  * only for those batons. (Consider using a subpool of @a result_pool
1031  * for scratch work, destroying the subpool before exiting this
1032  * function's implementation.)
1033  */
1034  svn_error_t *(*add_file)(const char *path,
1035  void *parent_baton,
1036  const char *copyfrom_path,
1037  svn_revnum_t copyfrom_revision,
1038  apr_pool_t *result_pool,
1039  void **file_baton);
1040 
1041  /** We are going to make changes to a file at @a path, a child of the
1042  * directory represented by @a parent_baton.
1043  *
1044  * The callback can store a baton for this new file in @a **file_baton;
1045  * whatever value it stores there should be passed through to
1046  * @c apply_textdelta or @c apply_textdelta_stream. If a valid revnum,
1047  * @a base_revision is the current revision of the file.
1048  *
1049  * Allocations for the returned @a file_baton should be performed in
1050  * @a result_pool. It is also typical to save this pool for later usage
1051  * by @c apply_textdelta and possibly @c close_file.
1052  *
1053  * @note See note about memory usage on @a add_file, which also
1054  * applies here.
1055  */
1056  svn_error_t *(*open_file)(const char *path,
1057  void *parent_baton,
1058  svn_revnum_t base_revision,
1059  apr_pool_t *result_pool,
1060  void **file_baton);
1061 
1062  /** Apply a text delta, yielding the new revision of a file.
1063  *
1064  * @a file_baton indicates the file we're creating or updating, and the
1065  * ancestor file on which it is based; it is the baton set by some
1066  * prior @c add_file or @c open_file callback.
1067  *
1068  * The callback should set @a *handler to a text delta window
1069  * handler; we will then call @a *handler on successive text
1070  * delta windows as we receive them. The callback should set
1071  * @a *handler_baton to the value we should pass as the @a baton
1072  * argument to @a *handler. These values should be allocated within
1073  * @a result_pool.
1074  *
1075  * @a base_checksum is the hex MD5 digest for the base text against
1076  * which the delta is being applied; it is ignored if NULL, and may
1077  * be ignored even if not NULL. If it is not ignored, it must match
1078  * the checksum of the base text against which svndiff data is being
1079  * applied; if it does not, @c apply_textdelta or the @a *handler call
1080  * which detects the mismatch will return the error
1081  * SVN_ERR_CHECKSUM_MISMATCH (if there is no base text, there may
1082  * still be an error if @a base_checksum is neither NULL nor the hex
1083  * MD5 checksum of the empty string).
1084  */
1085  svn_error_t *(*apply_textdelta)(void *file_baton,
1086  const char *base_checksum,
1087  apr_pool_t *result_pool,
1089  void **handler_baton);
1090 
1091  /** Change the value of a file's property.
1092  * - @a file_baton specifies the file whose property should change.
1093  * - @a name is the name of the property to change.
1094  * - @a value is the new (final) value of the property, or @c NULL if the
1095  * property should be removed altogether.
1096  *
1097  * The callback is guaranteed to be called exactly once for each property
1098  * whose value differs between the start and the end of the edit.
1099  *
1100  * Any temporary allocations may be performed in @a scratch_pool.
1101  */
1102  svn_error_t *(*change_file_prop)(void *file_baton,
1103  const char *name,
1104  const svn_string_t *value,
1105  apr_pool_t *scratch_pool);
1106 
1107  /** We are done processing a file, whose baton is @a file_baton (set by
1108  * @c add_file or @c open_file). We won't be using the baton any
1109  * more, so whatever resources it refers to may now be freed.
1110  *
1111  * @a text_checksum is the hex MD5 digest for the fulltext that
1112  * resulted from a delta application, see @c apply_textdelta and
1113  * @c apply_textdelta_stream. The checksum is ignored if NULL.
1114  * If not null, it is compared to the checksum of the new fulltext,
1115  * and the error SVN_ERR_CHECKSUM_MISMATCH is returned if they do
1116  * not match. If there is no new fulltext, @a text_checksum is ignored.
1117  *
1118  * Any temporary allocations may be performed in @a scratch_pool.
1119  */
1120  svn_error_t *(*close_file)(void *file_baton,
1121  const char *text_checksum,
1122  apr_pool_t *scratch_pool);
1123 
1124  /** In the directory represented by @a parent_baton, indicate that
1125  * @a path is present as a file in the edit source, but cannot be
1126  * cannot be conveyed to the edit consumer. Currently, this would
1127  * only occur because of authorization restrictions, but may change
1128  * in the future.
1129  *
1130  * Any temporary allocations may be performed in @a scratch_pool.
1131  */
1132  svn_error_t *(*absent_file)(const char *path,
1133  void *parent_baton,
1134  apr_pool_t *scratch_pool);
1135 
1136  /** All delta processing is done. Call this, with the @a edit_baton for
1137  * the entire edit.
1138  *
1139  * Any temporary allocations may be performed in @a scratch_pool.
1140  */
1141  svn_error_t *(*close_edit)(void *edit_baton,
1142  apr_pool_t *scratch_pool);
1143 
1144  /** The editor-driver has decided to bail out. Allow the editor to
1145  * gracefully clean up things if it needs to.
1146  *
1147  * Any temporary allocations may be performed in @a scratch_pool.
1148  */
1149  svn_error_t *(*abort_edit)(void *edit_baton,
1150  apr_pool_t *scratch_pool);
1151 
1152  /** Apply a text delta stream, yielding the new revision of a file.
1153  * This callback operates on the passed-in @a editor instance.
1154  *
1155  * @a file_baton indicates the file we're creating or updating, and the
1156  * ancestor file on which it is based; it is the baton set by some
1157  * prior @c add_file or @c open_file callback.
1158  *
1159  * @a open_func is a function that opens a #svn_txdelta_stream_t object.
1160  * @a open_baton is provided by the caller.
1161  *
1162  * @a base_checksum is the hex MD5 digest for the base text against
1163  * which the delta is being applied; it is ignored if NULL, and may
1164  * be ignored even if not NULL. If it is not ignored, it must match
1165  * the checksum of the base text against which svndiff data is being
1166  * applied; if it does not, @c apply_textdelta_stream call which detects
1167  * the mismatch will return the error #SVN_ERR_CHECKSUM_MISMATCH
1168  * (if there is no base text, there may still be an error if
1169  * @a base_checksum is neither NULL nor the hex MD5 checksum of the
1170  * empty string).
1171  *
1172  * Any temporary allocations may be performed in @a scratch_pool.
1173  *
1174  * @since New in 1.10.
1175  */
1176  svn_error_t *(*apply_textdelta_stream)(
1177  const struct svn_delta_editor_t *editor,
1178  void *file_baton,
1179  const char *base_checksum,
1181  void *open_baton,
1182  apr_pool_t *scratch_pool);
1183 
1184  /* Be sure to update svn_delta_get_cancellation_editor() and
1185  * svn_delta_default_editor() if you add a new callback here. */
1187 
1188 
1189 /** Return a default delta editor template, allocated in @a pool.
1190  *
1191  * The editor functions in the template do only the most basic
1192  * baton-swapping: each editor function that produces a baton does so
1193  * by copying its incoming baton into the outgoing baton reference.
1194  *
1195  * This editor is not intended to be useful by itself, but is meant to
1196  * be the basis for a useful editor. After getting a default editor,
1197  * you substitute in your own implementations for the editor functions
1198  * you care about. The ones you don't care about, you don't have to
1199  * implement -- you can rely on the template's implementation to
1200  * safely do nothing of consequence.
1201  */
1202 svn_delta_editor_t *
1203 svn_delta_default_editor(apr_pool_t *pool);
1204 
1205 /** A text-delta window handler which does nothing.
1206  *
1207  * Editors can return this handler from @c apply_textdelta if they don't
1208  * care about text delta windows.
1209  */
1210 svn_error_t *
1212  void *baton);
1213 
1214 /** Set @a *editor and @a *edit_baton to a cancellation editor that
1215  * wraps @a wrapped_editor and @a wrapped_baton.
1216  *
1217  * The @a editor will call @a cancel_func with @a cancel_baton when each of
1218  * its functions is called, continuing on to call the corresponding wrapped
1219  * function if @a cancel_func returns #SVN_NO_ERROR.
1220  *
1221  * If @a cancel_func is @c NULL, set @a *editor to @a wrapped_editor and
1222  * @a *edit_baton to @a wrapped_baton.
1223  */
1224 svn_error_t *
1226  void *cancel_baton,
1227  const svn_delta_editor_t *wrapped_editor,
1228  void *wrapped_baton,
1229  const svn_delta_editor_t **editor,
1230  void **edit_baton,
1231  apr_pool_t *pool);
1232 
1233 /** Set @a *editor and @a *edit_baton to an depth-based filtering
1234  * editor that wraps @a wrapped_editor and @a wrapped_baton.
1235  *
1236  * The @a editor will track the depth of this drive against the @a
1237  * requested_depth, taking into account whether not the edit drive is
1238  * making use of a target (via @a has_target), and forward editor
1239  * calls which operate "within" the request depth range through to @a
1240  * wrapped_editor.
1241  *
1242  * @a requested_depth must be one of the following depth values:
1243  * #svn_depth_infinity, #svn_depth_empty, #svn_depth_files,
1244  * #svn_depth_immediates, or #svn_depth_unknown.
1245  *
1246  * If filtering is deemed unnecessary (or if @a requested_depth is
1247  * #svn_depth_unknown), @a *editor and @a *edit_baton will be set to @a
1248  * wrapped_editor and @a wrapped_baton, respectively; otherwise,
1249  * they'll be set to new objects allocated from @a pool.
1250  *
1251  * @note Because the svn_delta_editor_t interface's @c delete_entry()
1252  * function doesn't carry node kind information, a depth-based
1253  * filtering editor being asked to filter for #svn_depth_files but
1254  * receiving a @c delete_entry() call on an immediate child of the
1255  * editor's target is unable to know if that deletion should be
1256  * allowed or filtered out -- a delete of a top-level file is okay in
1257  * this case, a delete of a top-level subdirectory is not. As such,
1258  * this filtering editor takes a conservative approach, and ignores
1259  * top-level deletion requests when filtering for #svn_depth_files.
1260  * Fortunately, most non-depth-aware (pre-1.5) Subversion editor
1261  * drivers can be told to drive non-recursively (where non-recursive
1262  * means essentially #svn_depth_files), which means they won't
1263  * transmit out-of-scope editor commands anyway.
1264  *
1265  * @since New in 1.5.
1266  */
1267 svn_error_t *
1268 svn_delta_depth_filter_editor(const svn_delta_editor_t **editor,
1269  void **edit_baton,
1270  const svn_delta_editor_t *wrapped_editor,
1271  void *wrapped_edit_baton,
1272  svn_depth_t requested_depth,
1273  svn_boolean_t has_target,
1274  apr_pool_t *pool);
1275 
1276 /** @} */
1277 
1278 
1279 /** Path-based editor drives.
1280  *
1281  * @defgroup svn_delta_path_delta_drivers Path-based delta drivers
1282  * @{
1283  */
1284 
1285 /** Callback function type for svn_delta_path_driver().
1286  *
1287  * The handler of this callback is given the callback baton @a
1288  * callback_baton, @a path which is a relpath relative to the
1289  * root of the edit, and the @a parent_baton which represents
1290  * path's parent directory as created by the editor passed to
1291  * svn_delta_path_driver().
1292  *
1293  * If @a path represents a directory, the handler must return a @a
1294  * *dir_baton for @a path, generated from the same editor (so that the
1295  * driver can later close that directory).
1296  *
1297  * If, however, @a path represents a file, the handler should NOT
1298  * return any file batons. It can close any opened or added files
1299  * immediately, or delay that close until the end of the edit when
1300  * svn_delta_path_driver() returns.
1301  *
1302  * Finally, if @a parent_baton is @c NULL, then the root of the edit
1303  * is also one of the paths passed to svn_delta_path_driver(). The
1304  * handler of this callback must call the editor's open_root()
1305  * function and return the top-level root dir baton in @a *dir_baton.
1306  */
1307 typedef svn_error_t *(*svn_delta_path_driver_cb_func_t)(
1308  void **dir_baton,
1309  void *parent_baton,
1310  void *callback_baton,
1311  const char *path,
1312  apr_pool_t *pool);
1313 
1314 
1315 /** Drive @a editor (with its @a edit_baton) to visit each path in @a paths.
1316  * As each path is hit as part of the editor drive, use
1317  * @a callback_func and @a callback_baton to allow the caller to handle
1318  * the portion of the editor drive related to that path.
1319  *
1320  * Each path in @a paths is a (const char *) relpath, relative
1321  * to the root path of the @a edit. The editor drive will be
1322  * performed in the same order as @a paths. The paths should be sorted
1323  * using something like svn_sort_compare_paths to ensure that a depth-first
1324  * pattern is observed for directory/file baton creation. If @a sort_paths
1325  * is set, the function will sort the paths for you. Some callers may need
1326  * further customization of the order (ie. libsvn_delta/compat.c).
1327  *
1328  * Use @a scratch_pool for all necessary allocations.
1329  *
1330  * @since New in 1.8.
1331  */
1332 svn_error_t *
1333 svn_delta_path_driver2(const svn_delta_editor_t *editor,
1334  void *edit_baton,
1335  const apr_array_header_t *paths,
1336  svn_boolean_t sort_paths,
1337  svn_delta_path_driver_cb_func_t callback_func,
1338  void *callback_baton,
1339  apr_pool_t *scratch_pool);
1340 
1341 
1342 /** Similar to svn_delta_path_driver2, but takes an (unused) revision,
1343  * and will sort the provided @a paths using svn_sort_compare_paths.
1344  *
1345  * @note In versions prior to 1.8, this function would modify the order
1346  * of elements in @a paths, despite the 'const' marker on the parameter.
1347  * This has been fixed in 1.8.
1348  *
1349  * @deprecated Provided for backward compatibility with the 1.7 API.
1350  */
1352 svn_error_t *
1353 svn_delta_path_driver(const svn_delta_editor_t *editor,
1354  void *edit_baton,
1355  svn_revnum_t revision,
1356  const apr_array_header_t *paths,
1357  svn_delta_path_driver_cb_func_t callback_func,
1358  void *callback_baton,
1359  apr_pool_t *scratch_pool);
1360 
1361 /** @} */
1362 
1363 
1364 /*** File revision iterator types ***/
1365 
1366 /**
1367  * The callback invoked by file rev loopers, such as
1368  * svn_ra_plugin_t.get_file_revs2() and svn_repos_get_file_revs2().
1369  *
1370  * @a baton is provided by the caller, @a path is the pathname of the file
1371  * in revision @a rev and @a rev_props are the revision properties.
1372  *
1373  * If @a delta_handler and @a delta_baton are non-NULL, they may be set to a
1374  * handler/baton which will be called with the delta between the previous
1375  * revision and this one after the return of this callback. They may be
1376  * left as NULL/NULL.
1377  *
1378  * @a result_of_merge will be @c TRUE if the revision being returned was
1379  * included as the result of a merge.
1380  *
1381  * @a prop_diffs is an array of svn_prop_t elements indicating the property
1382  * delta for this and the previous revision.
1383  *
1384  * @a pool may be used for temporary allocations, but you can't rely
1385  * on objects allocated to live outside of this particular call and
1386  * the immediately following calls to @a *delta_handler if any. (Pass
1387  * in a pool via @a baton if need be.)
1388  *
1389  * @since New in 1.5.
1390  */
1391 typedef svn_error_t *(*svn_file_rev_handler_t)(
1392  void *baton,
1393  const char *path,
1394  svn_revnum_t rev,
1395  apr_hash_t *rev_props,
1396  svn_boolean_t result_of_merge,
1397  svn_txdelta_window_handler_t *delta_handler,
1398  void **delta_baton,
1399  apr_array_header_t *prop_diffs,
1400  apr_pool_t *pool);
1401 
1402 /**
1403  * The old file rev handler interface.
1404  *
1405  * @note #svn_file_rev_handler_old_t is a placeholder type for both
1406  * #svn_repos_file_rev_handler_t and #svn_ra_file_rev_handler_t. It is
1407  * reproduced here for dependency reasons.
1408  *
1409  * @deprecated This type is provided for the svn_compat_wrap_file_rev_handler()
1410  * compatibility wrapper, and should not be used for new development.
1411  * @since New in 1.5.
1412  */
1413 typedef svn_error_t *(*svn_file_rev_handler_old_t)(
1414  void *baton,
1415  const char *path,
1416  svn_revnum_t rev,
1417  apr_hash_t *rev_props,
1418  svn_txdelta_window_handler_t *delta_handler,
1419  void **delta_baton,
1420  apr_array_header_t *prop_diffs,
1421  apr_pool_t *pool);
1422 
1423 /** Return, in @a *handler2 and @a *handler2_baton a function/baton that
1424  * will call @a handler/@a handler_baton, allocating the @a *handler2_baton
1425  * in @a pool.
1426  *
1427  * @note This is used by compatibility wrappers, which exist in more than
1428  * Subversion core library.
1429  *
1430  * @note #svn_file_rev_handler_old_t is a placeholder type for both
1431  * #svn_repos_file_rev_handler_t and #svn_ra_file_rev_handler_t. It is
1432  * reproduced here for dependency reasons.
1433  *
1434  * @since New in 1.5.
1435  */
1436 void
1438  void **handler2_baton,
1440  void *handler_baton,
1441  apr_pool_t *pool);
1442 
1443 /** @} end group: delta_support */
1444 
1445 
1446 #ifdef __cplusplus
1447 }
1448 #endif /* __cplusplus */
1449 
1450 #endif /* SVN_DELTA_H */
Counted-length strings for Subversion, plus some C string goodies.
svn_error_t * svn_txdelta_send_contents(const unsigned char *contents, apr_size_t len, svn_txdelta_window_handler_t handler, void *handler_baton, apr_pool_t *pool)
Send the contents of length len as a txdelta against an empty source directly to window-handler handl...
svn_depth_t
The concept of depth for directories.
Definition: svn_types.h:504
void svn_txdelta_to_svndiff3(svn_txdelta_window_handler_t *handler, void **handler_baton, svn_stream_t *output, int svndiff_version, int compression_level, apr_pool_t *pool)
Prepare to produce an svndiff-format diff from text delta windows.
svn_checksum_kind_t
Various types of checksums.
Definition: svn_checksum.h:45
void svn_txdelta_apply_instructions(svn_txdelta_window_t *window, const char *sbuf, char *tbuf, apr_size_t *tlen)
Apply the instructions from window to a source view sbuf to produce a target view tbuf...
int num_ops
The number of instructions in this window.
Definition: svn_delta.h:202
struct svn_delta_editor_t svn_delta_editor_t
A structure full of callback functions the delta source will invoke as it produces the delta...
void svn_txdelta2(svn_txdelta_stream_t **stream, svn_stream_t *source, svn_stream_t *target, svn_boolean_t calculate_checksum, apr_pool_t *pool)
Set *stream to a pointer to a delta stream that will turn the byte string from source into the byte s...
apr_size_t offset
Offset of delta, see svn_delta_action for more details.
Definition: svn_delta.h:164
General file I/O for Subversion.
Subversion checksum routines.
apr_size_t tview_len
The length of the target view for this window, i.e.
Definition: svn_delta.h:199
int src_ops
The number of svn_txdelta_source instructions in this window.
Definition: svn_delta.h:208
svn_error_t * svn_txdelta_send_txstream(svn_txdelta_stream_t *txstream, svn_txdelta_window_handler_t handler, void *handler_baton, apr_pool_t *pool)
Send the contents of txstream to window-handler handler/baton.
enum svn_delta_action action_code
Action code of delta instruction.
Definition: svn_delta.h:162
svn_stream_t * svn_txdelta_target_push(svn_txdelta_window_handler_t handler, void *handler_baton, svn_stream_t *source, apr_pool_t *pool)
Return a writable stream which, when fed target data, will send delta windows to handler/handler_bato...
A structure full of callback functions the delta source will invoke as it produces the delta...
Definition: svn_delta.h:879
const svn_txdelta_op_t * ops
The instructions for this window.
Definition: svn_delta.h:211
svn_stream_t * svn_txdelta_parse_svndiff(svn_txdelta_window_handler_t handler, void *handler_baton, svn_boolean_t error_on_early_close, apr_pool_t *pool)
Return a writable generic stream which will parse svndiff-format data into a text delta...
svn_error_t *(* svn_txdelta_stream_open_func_t)(svn_txdelta_stream_t **txdelta_stream, void *baton, apr_pool_t *result_pool, apr_pool_t *scratch_pool)
A typedef for a function that opens an svn_txdelta_stream_t object, allocated in result_pool.
Definition: svn_delta.h:340
svn_error_t * svn_txdelta_next_window(svn_txdelta_window_t **window, svn_txdelta_stream_t *stream, apr_pool_t *pool)
Set *window to a pointer to the next window from the delta stream stream.
svn_delta_action
Action codes for text delta instructions.
Definition: svn_delta.h:116
svn_error_t * svn_txdelta_read_svndiff_window(svn_txdelta_window_t **window, svn_stream_t *stream, int svndiff_version, apr_pool_t *pool)
Read and parse one delta window in svndiff format from the readable stream stream and place it in *wi...
A simple counted string.
Definition: svn_string.h:96
void svn_txdelta(svn_txdelta_stream_t **stream, svn_stream_t *source, svn_stream_t *target, apr_pool_t *pool)
Similar to svn_txdelta2 but always calculating the target checksum.
Append the length bytes at offset in the window&#39;s new string to the target.
Definition: svn_delta.h:155
Subversion error object.
Definition: svn_types.h:178
struct svn_txdelta_window_t svn_txdelta_window_t
An svn_txdelta_window_t object describes how to reconstruct a contiguous section of the target string...
struct svn_txdelta_stream_t svn_txdelta_stream_t
A delta stream — this is the hat from which we pull a series of svn_txdelta_window_t objects...
Definition: svn_delta.h:305
A single text delta instruction.
Definition: svn_delta.h:159
apr_int64_t svn_filesize_t
The size of a file in the Subversion FS.
Definition: svn_types.h:473
svn_error_t *(* svn_txdelta_window_handler_t)(svn_txdelta_window_t *window, void *baton)
A typedef for functions that consume a series of delta windows, for use in caller-pushes interfaces...
Definition: svn_delta.h:265
apr_size_t length
Number of bytes of delta, see svn_delta_action for more details.
Definition: svn_delta.h:166
apr_size_t sview_len
The length of the source view for this window.
Definition: svn_delta.h:195
svn_delta_editor_t * svn_delta_default_editor(apr_pool_t *pool)
Return a default delta editor template, allocated in pool.
Append the length bytes at offset in the target view, to the target.
Definition: svn_delta.h:145
svn_error_t * svn_txdelta_skip_svndiff_window(apr_file_t *file, int svndiff_version, apr_pool_t *pool)
Read and skip one delta window in svndiff format from the file file.
svn_error_t * svn_delta_get_cancellation_editor(svn_cancel_func_t cancel_func, void *cancel_baton, const svn_delta_editor_t *wrapped_editor, void *wrapped_baton, const svn_delta_editor_t **editor, void **edit_baton, apr_pool_t *pool)
Set *editor and *edit_baton to a cancellation editor that wraps wrapped_editor and wrapped_baton...
svn_error_t *(* svn_txdelta_next_window_fn_t)(svn_txdelta_window_t **window, void *baton, apr_pool_t *pool)
A typedef for a function that will set *window to the next window from a svn_txdelta_stream_t object...
Definition: svn_delta.h:317
svn_error_t *(* svn_delta_path_driver_cb_func_t)(void **dir_baton, void *parent_baton, void *callback_baton, const char *path, apr_pool_t *pool)
Callback function type for svn_delta_path_driver().
Definition: svn_delta.h:1307
struct svn_txdelta_op_t svn_txdelta_op_t
A single text delta instruction.
svn_error_t *(* svn_file_rev_handler_old_t)(void *baton, const char *path, svn_revnum_t rev, apr_hash_t *rev_props, svn_txdelta_window_handler_t *delta_handler, void **delta_baton, apr_array_header_t *prop_diffs, apr_pool_t *pool)
The old file rev handler interface.
Definition: svn_delta.h:1413
Version information.
Definition: svn_version.h:147
svn_error_t * svn_delta_noop_window_handler(svn_txdelta_window_t *window, void *baton)
A text-delta window handler which does nothing.
struct svn_stream_t svn_stream_t
An abstract stream of bytes–either incoming or outgoing or both.
Definition: svn_io.h:863
svn_error_t * svn_delta_depth_filter_editor(const svn_delta_editor_t **editor, void **edit_baton, const svn_delta_editor_t *wrapped_editor, void *wrapped_edit_baton, svn_depth_t requested_depth, svn_boolean_t has_target, apr_pool_t *pool)
Set *editor and *edit_baton to an depth-based filtering editor that wraps wrapped_editor and wrapped_...
svn_txdelta_window_t * svn_txdelta_compose_windows(const svn_txdelta_window_t *window_A, const svn_txdelta_window_t *window_B, apr_pool_t *pool)
Compose two delta windows, yielding a third, allocated in pool.
Subversion&#39;s data types.
svn_txdelta_window_t * svn_txdelta_window_dup(const svn_txdelta_window_t *window, apr_pool_t *pool)
Return a deep copy of window, allocated in pool.
A generic checksum representation.
Definition: svn_checksum.h:69
#define SVN_DEPRECATED
Macro used to mark deprecated functions.
Definition: svn_types.h:60
svn_error_t *(* svn_cancel_func_t)(void *cancel_baton)
A user defined callback that subversion will call with a user defined baton to see if the current ope...
Definition: svn_types.h:1172
svn_stream_t * svn_txdelta_to_svndiff_stream(svn_txdelta_stream_t *txstream, int svndiff_version, int compression_level, apr_pool_t *pool)
Return a readable generic stream which will produce svndiff-encoded text delta from the delta stream ...
svn_filesize_t sview_offset
The offset of the source view for this window.
Definition: svn_delta.h:192
const unsigned char *(* svn_txdelta_md5_digest_fn_t)(void *baton)
A typedef for a function that will return the md5 checksum of the fulltext deltified by a svn_txdelta...
Definition: svn_delta.h:331
const svn_string_t * new_data
New data, for use by any `svn_txdelta_new&#39; instructions.
Definition: svn_delta.h:214
long int svn_revnum_t
About Special Files in Subversion.
Definition: svn_types.h:426
svn_error_t * svn_txdelta_send_string(const svn_string_t *string, svn_txdelta_window_handler_t handler, void *handler_baton, apr_pool_t *pool)
Send the contents of string to window-handler handler/baton.
Append the length bytes at offset in the source view to the target.
Definition: svn_delta.h:126
const svn_version_t * svn_delta_version(void)
Get libsvn_delta version information.
svn_error_t * svn_delta_path_driver(const svn_delta_editor_t *editor, void *edit_baton, svn_revnum_t revision, const apr_array_header_t *paths, svn_delta_path_driver_cb_func_t callback_func, void *callback_baton, apr_pool_t *scratch_pool)
Similar to svn_delta_path_driver2, but takes an (unused) revision, and will sort the provided paths u...
svn_error_t * svn_delta_path_driver2(const svn_delta_editor_t *editor, void *edit_baton, const apr_array_header_t *paths, svn_boolean_t sort_paths, svn_delta_path_driver_cb_func_t callback_func, void *callback_baton, apr_pool_t *scratch_pool)
Drive editor (with its edit_baton) to visit each path in paths.
svn_error_t *(* svn_file_rev_handler_t)(void *baton, const char *path, svn_revnum_t rev, apr_hash_t *rev_props, svn_boolean_t result_of_merge, svn_txdelta_window_handler_t *delta_handler, void **delta_baton, apr_array_header_t *prop_diffs, apr_pool_t *pool)
The callback invoked by file rev loopers, such as svn_ra_plugin_t.get_file_revs2() and svn_repos_get_...
Definition: svn_delta.h:1391
svn_error_t * svn_txdelta_send_stream(svn_stream_t *stream, svn_txdelta_window_handler_t handler, void *handler_baton, unsigned char *digest, apr_pool_t *pool)
Send the contents of stream to window-handler handler/baton.
int svn_boolean_t
YABT: Yet Another Boolean Type.
Definition: svn_types.h:139
const unsigned char * svn_txdelta_md5_digest(svn_txdelta_stream_t *stream)
Return the md5 digest for the complete fulltext deltified by stream, or NULL if stream has not yet re...
void svn_txdelta_to_svndiff(svn_stream_t *output, apr_pool_t *pool, svn_txdelta_window_handler_t *handler, void **handler_baton)
Similar to svn_txdelta_to_svndiff2, but always using svndiff version 0.
An svn_txdelta_window_t object describes how to reconstruct a contiguous section of the target string...
Definition: svn_delta.h:188
void svn_txdelta_apply(svn_stream_t *source, svn_stream_t *target, unsigned char *result_digest, const char *error_info, apr_pool_t *pool, svn_txdelta_window_handler_t *handler, void **handler_baton)
Prepare to apply a text delta.
svn_error_t * svn_txdelta_run(svn_stream_t *source, svn_stream_t *target, svn_txdelta_window_handler_t handler, void *handler_baton, svn_checksum_kind_t checksum_kind, svn_checksum_t **checksum, svn_cancel_func_t cancel_func, void *cancel_baton, apr_pool_t *result_pool, apr_pool_t *scratch_pool)
This function will generate delta windows that turn source into target, and pushing these windows int...
void svn_txdelta_to_svndiff2(svn_txdelta_window_handler_t *handler, void **handler_baton, svn_stream_t *output, int svndiff_version, apr_pool_t *pool)
Similar to svn_txdelta_to_svndiff3(), but always using the SVN default compression level (SVN_DELTA_C...
svn_txdelta_stream_t * svn_txdelta_stream_create(void *baton, svn_txdelta_next_window_fn_t next_window, svn_txdelta_md5_digest_fn_t md5_digest, apr_pool_t *pool)
Create and return a generic text delta stream with baton, next_window and md5_digest.
void svn_compat_wrap_file_rev_handler(svn_file_rev_handler_t *handler2, void **handler2_baton, svn_file_rev_handler_old_t handler, void *handler_baton, apr_pool_t *pool)
Return, in *handler2 and *handler2_baton a function/baton that will call handler/handler_baton, allocating the *handler2_baton in pool.