In the command-line client, forbid
[svn.git] / subversion / include / svn_delta.h
blob64430cf7ae4a8c059b9cc81105c6038af6e7d467
1 /**
2 * @copyright
3 * ====================================================================
4 * Copyright (c) 2000-2007 CollabNet. All rights reserved.
6 * This software is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at http://subversion.tigris.org/license-1.html.
9 * If newer versions of this license are posted there, you may use a
10 * newer version instead, at your option.
12 * This software consists of voluntary contributions made by many
13 * individuals. For exact contribution history, see the revision
14 * history and logs, available at http://subversion.tigris.org/.
15 * ====================================================================
16 * @endcopyright
18 * @file svn_delta.h
19 * @brief Delta-parsing
22 /* ==================================================================== */
26 #ifndef SVN_DELTA_H
27 #define SVN_DELTA_H
29 #include <apr.h>
30 #include <apr_pools.h>
32 #include "svn_types.h"
33 #include "svn_string.h"
34 #include "svn_error.h"
35 #include "svn_io.h"
36 #include "svn_version.h"
38 #ifdef __cplusplus
39 extern "C" {
40 #endif /* __cplusplus */
44 /**
45 * Get libsvn_delta version information.
47 * @since New in 1.1.
49 const svn_version_t *svn_delta_version(void);
51 /**
52 * @defgroup delta_support Delta generation and handling
54 * @{
55 */
57 /** Text deltas.
59 * A text delta represents the difference between two strings of
60 * bytes, the `source' string and the `target' string. Given a source
61 * string and a target string, we can compute a text delta; given a
62 * source string and a delta, we can reconstruct the target string.
63 * However, note that deltas are not reversible: you cannot always
64 * reconstruct the source string given the target string and delta.
66 * Since text deltas can be very large, the interface here allows us
67 * to produce and consume them in pieces. Each piece, represented by
68 * an @c svn_txdelta_window_t structure, describes how to produce the
69 * next section of the target string.
71 * To compute a new text delta:
73 * - We call svn_txdelta() on the streams we want to compare. That
74 * returns us an @c svn_txdelta_stream_t object.
76 * - We then call svn_txdelta_next_window() on the stream object
77 * repeatedly. Each call returns a new @c svn_txdelta_window_t
78 * object, which describes the next portion of the target string.
79 * When svn_txdelta_next_window() returns zero, we are done building
80 * the target string.
82 * @defgroup svn_delta_txt_delta Text deltas
83 * @{
86 /** Action codes for text delta instructions. */
87 enum svn_delta_action {
88 /** Append the @a length bytes at @a offset in the source view to the
89 * target.
91 * It must be the case that @a 0 <= @a offset < @a offset +
92 * @a length <= size of source view.
94 svn_txdelta_source,
96 /** Append the @a length bytes at @a offset in the target view, to the
97 * target.
99 * It must be the case that @a 0 <= @a offset < current position in the
100 * target view.
102 * However! @a offset + @a length may be *beyond* the end of the existing
103 * target data. "Where the heck does the text come from, then?"
104 * If you start at @a offset, and append @a length bytes one at a time,
105 * it'll work out --- you're adding new bytes to the end at the
106 * same rate you're reading them from the middle. Thus, if your
107 * current target text is "abcdefgh", and you get an @c svn_txdelta_target
108 * instruction whose @a offset is @a 6 and whose @a length is @a 7,
109 * the resulting string is "abcdefghghghghg". This trick is actually
110 * useful in encoding long runs of consecutive characters, long runs
111 * of CR/LF pairs, etc.
113 svn_txdelta_target,
115 /** Append the @a length bytes at @a offset in the window's @a new string
116 * to the target.
118 * It must be the case that @a 0 <= @a offset < @a offset +
119 * @a length <= length of @a new. Windows MUST use new data in ascending
120 * order with no overlap at the moment; svn_txdelta_to_svndiff()
121 * depends on this.
123 svn_txdelta_new
126 /** A single text delta instruction. */
127 typedef struct svn_txdelta_op_t
129 /** Action code of delta instruction */
130 enum svn_delta_action action_code;
131 /** Offset of delta, see #svn_delta_action for more details. */
132 apr_size_t offset;
133 /** Number of bytes of delta, see #svn_delta_action for more details. */
134 apr_size_t length;
135 } svn_txdelta_op_t;
138 /** An @c svn_txdelta_window_t object describes how to reconstruct a
139 * contiguous section of the target string (the "target view") using a
140 * specified contiguous region of the source string (the "source
141 * view"). It contains a series of instructions which assemble the
142 * new target string text by pulling together substrings from:
144 * - the source view,
146 * - the previously constructed portion of the target view,
148 * - a string of new data contained within the window structure
150 * The source view must always slide forward from one window to the
151 * next; that is, neither the beginning nor the end of the source view
152 * may move to the left as we read from a window stream. This
153 * property allows us to apply deltas to non-seekable source streams
154 * without making a full copy of the source stream.
156 typedef struct svn_txdelta_window_t
159 /** The offset of the source view for this window. */
160 svn_filesize_t sview_offset;
162 /** The length of the source view for this window. */
163 apr_size_t sview_len;
165 /** The length of the target view for this window, i.e. the number of
166 * bytes which will be reconstructed by the instruction stream. */
167 apr_size_t tview_len;
169 /** The number of instructions in this window. */
170 int num_ops;
172 /** The number of svn_txdelta_source instructions in this window. If
173 * this number is 0, we don't need to read the source in order to
174 * reconstruct the target view.
176 int src_ops;
178 /** The instructions for this window. */
179 const svn_txdelta_op_t *ops;
181 /** New data, for use by any `svn_txdelta_new' instructions. */
182 const svn_string_t *new_data;
184 } svn_txdelta_window_t;
187 * Return a deep copy of @a window, allocated in @a pool.
189 * @since New in 1.3.
191 svn_txdelta_window_t *
192 svn_txdelta_window_dup(const svn_txdelta_window_t *window,
193 apr_pool_t *pool);
196 * Compose two delta windows, yielding a third, allocated in @a pool.
198 * @since New in 1.4
201 svn_txdelta_window_t *
202 svn_txdelta_compose_windows(const svn_txdelta_window_t *window_A,
203 const svn_txdelta_window_t *window_B,
204 apr_pool_t *pool);
207 * Apply the instructions from @a window to a source view @a sbuf to
208 * produce a target view @a tbuf.
210 * @a sbuf is assumed to have @a window->sview_len bytes of data and
211 * @a tbuf is assumed to have room for @a tlen bytes of output. @a
212 * tlen may be more than @a window->tview_len, so return the actual
213 * number of bytes written. @a sbuf is not touched and may be NULL if
214 * @a window contains no source-copy operations. This is purely a
215 * memory operation; nothing can go wrong as long as we have a valid
216 * window.
218 * @since New in 1.4
221 void
222 svn_txdelta_apply_instructions(svn_txdelta_window_t *window,
223 const char *sbuf, char *tbuf,
224 apr_size_t *tlen);
226 /** A typedef for functions that consume a series of delta windows, for
227 * use in caller-pushes interfaces. Such functions will typically
228 * apply the delta windows to produce some file, or save the windows
229 * somewhere. At the end of the delta window stream, you must call
230 * this function passing zero for the @a window argument.
232 typedef svn_error_t *(*svn_txdelta_window_handler_t)
233 (svn_txdelta_window_t *window, void *baton);
236 /** A delta stream --- this is the hat from which we pull a series of
237 * svn_txdelta_window_t objects, which, taken in order, describe the
238 * entire target string. This type is defined within libsvn_delta, and
239 * opaque outside that library.
241 typedef struct svn_txdelta_stream_t svn_txdelta_stream_t;
244 /** A typedef for a function that will set @a *window to the next
245 * window from a @c svn_txdelta_stream_t object. If there are no more
246 * delta windows, NULL will be used. The returned window, if any,
247 * will be allocated in @a pool. @a baton is the baton specified
248 * when the stream was created.
250 * @since New in 1.4.
252 typedef svn_error_t *
253 (*svn_txdelta_next_window_fn_t)(svn_txdelta_window_t **window,
254 void *baton,
255 apr_pool_t *pool);
257 /** A typedef for a function that will return the md5 checksum of the
258 * fulltext deltified by a @c svn_txdelta_stream_t object. Will
259 * return NULL if the final null window hasn't yet been returned by
260 * the stream. The returned value will be allocated in the same pool
261 * as the stream. @a baton is the baton specified when the stream was
262 * created.
264 * @since New in 1.4.
266 typedef const unsigned char *
267 (*svn_txdelta_md5_digest_fn_t)(void *baton);
269 /** Create and return a generic text delta stream with @a baton, @a
270 * next_window and @a md5_digest. Allocate the new stream in @a
271 * pool.
273 * @since New in 1.4.
275 svn_txdelta_stream_t *
276 svn_txdelta_stream_create(void *baton,
277 svn_txdelta_next_window_fn_t next_window,
278 svn_txdelta_md5_digest_fn_t md5_digest,
279 apr_pool_t *pool);
281 /** Set @a *window to a pointer to the next window from the delta stream
282 * @a stream. When we have completely reconstructed the target string,
283 * set @a *window to zero.
285 * The window will be allocated in @a pool.
287 svn_error_t *svn_txdelta_next_window(svn_txdelta_window_t **window,
288 svn_txdelta_stream_t *stream,
289 apr_pool_t *pool);
292 /** Return the md5 digest for the complete fulltext deltified by
293 * @a stream, or @c NULL if @a stream has not yet returned its final
294 * @c NULL window. The digest is allocated in the same memory as @a
295 * STREAM.
297 const unsigned char *svn_txdelta_md5_digest(svn_txdelta_stream_t *stream);
299 /** Set @a *stream to a pointer to a delta stream that will turn the byte
300 * string from @a source into the byte stream from @a target.
302 * @a source and @a target are both readable generic streams. When we call
303 * svn_txdelta_next_window() on @a *stream, it will read from @a source and
304 * @a target to gather as much data as it needs.
306 * Do any necessary allocation in a sub-pool of @a pool.
308 void svn_txdelta(svn_txdelta_stream_t **stream,
309 svn_stream_t *source,
310 svn_stream_t *target,
311 apr_pool_t *pool);
315 * Return a writable stream which, when fed target data, will send
316 * delta windows to @a handler/@a handler_baton which transform the
317 * data in @a source to the target data. As usual, the window handler
318 * will receive a NULL window to signify the end of the window stream.
319 * The stream handler functions will read data from @a source as
320 * necessary.
322 * @since New in 1.1.
324 svn_stream_t *svn_txdelta_target_push(svn_txdelta_window_handler_t handler,
325 void *handler_baton,
326 svn_stream_t *source,
327 apr_pool_t *pool);
330 /** Send the contents of @a string to window-handler @a handler/@a baton.
331 * This is effectively a 'copy' operation, resulting in delta windows that
332 * make the target equivalent to the value of @a string.
334 * All temporary allocation is performed in @a pool.
336 svn_error_t *svn_txdelta_send_string(const svn_string_t *string,
337 svn_txdelta_window_handler_t handler,
338 void *handler_baton,
339 apr_pool_t *pool);
341 /** Send the contents of @a stream to window-handler @a handler/@a baton.
342 * This is effectively a 'copy' operation, resulting in delta windows that
343 * make the target equivalent to the stream.
345 * If @a digest is non-NULL, populate it with the md5 checksum for the
346 * fulltext that was deltified (@a digest must be at least
347 * @c APR_MD5_DIGESTSIZE bytes long).
349 * All temporary allocation is performed in @a pool.
351 svn_error_t *svn_txdelta_send_stream(svn_stream_t *stream,
352 svn_txdelta_window_handler_t handler,
353 void *handler_baton,
354 unsigned char *digest,
355 apr_pool_t *pool);
357 /** Send the contents of @a txstream to window-handler @a handler/@a baton.
358 * Windows will be extracted from the stream and delivered to the handler.
360 * All temporary allocation is performed in @a pool.
362 svn_error_t *svn_txdelta_send_txstream(svn_txdelta_stream_t *txstream,
363 svn_txdelta_window_handler_t handler,
364 void *handler_baton,
365 apr_pool_t *pool);
368 /** Prepare to apply a text delta. @a source is a readable generic stream
369 * yielding the source data, @a target is a writable generic stream to
370 * write target data to, and allocation takes place in a sub-pool of
371 * @a pool. On return, @a *handler is set to a window handler function and
372 * @a *handler_baton is set to the value to pass as the @a baton argument to
373 * @a *handler.
375 * If @a result_digest is non-NULL, it points to APR_MD5_DIGESTSIZE bytes
376 * of storage, and the final call to @a handler populates it with the
377 * MD5 digest of the resulting fulltext.
379 * If @a error_info is non-NULL, it is inserted parenthetically into
380 * the error string for any error returned by svn_txdelta_apply() or
381 * @a *handler. (It is normally used to provide path information,
382 * since there's nothing else in the delta application's context to
383 * supply a path for error messages.)
385 * @note To avoid lifetime issues, @a error_info is copied into
386 * @a pool or a subpool thereof.
388 void svn_txdelta_apply(svn_stream_t *source,
389 svn_stream_t *target,
390 unsigned char *result_digest,
391 const char *error_info,
392 apr_pool_t *pool,
393 svn_txdelta_window_handler_t *handler,
394 void **handler_baton);
398 /*** Producing and consuming svndiff-format text deltas. ***/
400 /** Prepare to produce an svndiff-format diff from text delta windows.
401 * @a output is a writable generic stream to write the svndiff data to.
402 * Allocation takes place in a sub-pool of @a pool. On return, @a *handler
403 * is set to a window handler function and @a *handler_baton is set to
404 * the value to pass as the @a baton argument to @a *handler. The svndiff
405 * version is @a svndiff_version.
407 * @since New in 1.4.
409 void svn_txdelta_to_svndiff2(svn_txdelta_window_handler_t *handler,
410 void **handler_baton,
411 svn_stream_t *output,
412 int svndiff_version,
413 apr_pool_t *pool);
415 /** Similar to svn_txdelta_to_svndiff2, but always using svndiff
416 * version 0.
418 * @deprecated Provided for backward compatibility with the 1.3 API.
420 void svn_txdelta_to_svndiff(svn_stream_t *output,
421 apr_pool_t *pool,
422 svn_txdelta_window_handler_t *handler,
423 void **handler_baton);
425 /** Return a writable generic stream which will parse svndiff-format
426 * data into a text delta, invoking @a handler with @a handler_baton
427 * whenever a new window is ready. If @a error_on_early_close is @c
428 * TRUE, attempting to close this stream before it has handled the entire
429 * svndiff data set will result in @c SVN_ERR_SVNDIFF_UNEXPECTED_END,
430 * else this error condition will be ignored.
432 svn_stream_t *svn_txdelta_parse_svndiff(svn_txdelta_window_handler_t handler,
433 void *handler_baton,
434 svn_boolean_t error_on_early_close,
435 apr_pool_t *pool);
438 * Read and parse one delta window in svndiff format from the
439 * readable stream @a stream and place it in @a *window, allocating
440 * the result in @a pool. The caller must take responsibility for
441 * stripping off the four-byte 'SVN@<ver@>' header at the beginning of
442 * the svndiff document before reading the first window, and must
443 * provide the version number (the value of the fourth byte) to each
444 * invocation of this routine with the @a svndiff_version argument.
446 * @since New in 1.1.
448 svn_error_t *svn_txdelta_read_svndiff_window(svn_txdelta_window_t **window,
449 svn_stream_t *stream,
450 int svndiff_version,
451 apr_pool_t *pool);
454 * Read and skip one delta window in svndiff format from the
455 * file @a file. @a pool is used for temporary allocations. The
456 * caller must take responsibility for stripping off the four-byte
457 * 'SVN@<ver@>' header at the beginning of the svndiff document before
458 * reading or skipping the first window, and must provide the version
459 * number (the value of the fourth byte) to each invocation of this
460 * routine with the @a svndiff_version argument.
462 * @since New in 1.1.
464 svn_error_t *svn_txdelta_skip_svndiff_window(apr_file_t *file,
465 int svndiff_version,
466 apr_pool_t *pool);
468 /** @} */
471 /** Traversing tree deltas.
473 * In Subversion, we've got various producers and consumers of tree
474 * deltas.
476 * In processing a `commit' command:
477 * - The client examines its working copy data, and produces a tree
478 * delta describing the changes to be committed.
479 * - The client networking library consumes that delta, and sends them
480 * across the wire as an equivalent series of network requests (for
481 * example, to svnserve as an ra_svn protocol stream, or to an
482 * Apache httpd server as WebDAV commands)
483 * - The server receives those requests and produces a tree delta ---
484 * hopefully equivalent to the one the client produced above.
485 * - The Subversion server module consumes that delta and commits an
486 * appropriate transaction to the filesystem.
488 * In processing an `update' command, the process is reversed:
489 * - The Subversion server module talks to the filesystem and produces
490 * a tree delta describing the changes necessary to bring the
491 * client's working copy up to date.
492 * - The server consumes this delta, and assembles a reply
493 * representing the appropriate changes.
494 * - The client networking library receives that reply, and produces a
495 * tree delta --- hopefully equivalent to the one the Subversion
496 * server produced above.
497 * - The working copy library consumes that delta, and makes the
498 * appropriate changes to the working copy.
500 * The simplest approach would be to represent tree deltas using the
501 * obvious data structure. To do an update, the server would
502 * construct a delta structure, and the working copy library would
503 * apply that structure to the working copy; the network layer's job
504 * would simply be to get the structure across the net intact.
506 * However, we expect that these deltas will occasionally be too large
507 * to fit in a typical workstation's swap area. For example, in
508 * checking out a 200Mb source tree, the entire source tree is
509 * represented by a single tree delta. So it's important to handle
510 * deltas that are too large to fit in swap all at once.
512 * So instead of representing the tree delta explicitly, we define a
513 * standard way for a consumer to process each piece of a tree delta
514 * as soon as the producer creates it. The @c svn_delta_editor_t
515 * structure is a set of callback functions to be defined by a delta
516 * consumer, and invoked by a delta producer. Each invocation of a
517 * callback function describes a piece of the delta --- a file's
518 * contents changing, something being renamed, etc.
520 * @defgroup svn_delta_tree_deltas Tree deltas
521 * @{
524 /** A structure full of callback functions the delta source will invoke
525 * as it produces the delta.
527 * <h3>Function Usage</h3>
529 * Here's how to use these functions to express a tree delta.
531 * The delta consumer implements the callback functions described in
532 * this structure, and the delta producer invokes them. So the
533 * caller (producer) is pushing tree delta data at the callee
534 * (consumer).
536 * At the start of traversal, the consumer provides @a edit_baton, a
537 * baton global to the entire delta edit. If there is a target
538 * revision that needs to be set for this operation, the producer
539 * should call the @c set_target_revision function at this point.
541 * Next, if there are any tree deltas to express, the producer should
542 * pass the @a edit_baton to the @c open_root function, to get a baton
543 * representing root of the tree being edited.
545 * Most of the callbacks work in the obvious way:
547 * @c delete_entry
548 * @c add_file
549 * @c add_directory
550 * @c open_file
551 * @c open_directory
553 * Each of these takes a directory baton, indicating the directory
554 * in which the change takes place, and a @a path argument, giving the
555 * path (relative to the root of the edit) of the file,
556 * subdirectory, or directory entry to change. Editors will usually
557 * want to join this relative path with some base stored in the edit
558 * baton (e.g. a URL, a location in the OS filesystem).
560 * Since every call requires a parent directory baton, including
561 * @c add_directory and @c open_directory, where do we ever get our
562 * initial directory baton, to get things started? The @c open_root
563 * function returns a baton for the top directory of the change. In
564 * general, the producer needs to invoke the editor's @c open_root
565 * function before it can get anything of interest done.
567 * While @c open_root provides a directory baton for the root of
568 * the tree being changed, the @c add_directory and @c open_directory
569 * callbacks provide batons for other directories. Like the
570 * callbacks above, they take a @a parent_baton and a relative path
571 * @a path, and then return a new baton for the subdirectory being
572 * created / modified --- @a child_baton. The producer can then use
573 * @a child_baton to make further changes in that subdirectory.
575 * So, if we already have subdirectories named `foo' and `foo/bar',
576 * then the producer can create a new file named `foo/bar/baz.c' by
577 * calling:
579 * - @c open_root () --- yielding a baton @a root for the top directory
581 * - @c open_directory (@a root, "foo") --- yielding a baton @a f for `foo'
583 * - @c open_directory (@a f, "foo/bar") --- yielding a baton @a b for
584 * `foo/bar'
586 * - @c add_file (@a b, "foo/bar/baz.c")
588 * When the producer is finished making changes to a directory, it
589 * should call @c close_directory. This lets the consumer do any
590 * necessary cleanup, and free the baton's storage.
592 * The @c add_file and @c open_file callbacks each return a baton
593 * for the file being created or changed. This baton can then be
594 * passed to @c apply_textdelta to change the file's contents, or
595 * @c change_file_prop to change the file's properties. When the
596 * producer is finished making changes to a file, it should call
597 * @c close_file, to let the consumer clean up and free the baton.
599 * The @c add_file and @c add_directory functions each take arguments
600 * @a copyfrom_path and @a copyfrom_revision. If @a copyfrom_path is
601 * non-@c NULL, then @a copyfrom_path and @a copyfrom_revision indicate where
602 * the file or directory should be copied from (to create the file
603 * or directory being added). In that case, @a copyfrom_path must be
604 * either a path relative to the root of the edit, or a URI from the
605 * repository being edited. If @a copyfrom_path is @c NULL, then @a
606 * copyfrom_revision must be @c SVN_INVALID_REVNUM; it is invalid to
607 * pass a mix of valid and invalid copyfrom arguments.
610 * <h3>Function Call Ordering</h3>
612 * There are six restrictions on the order in which the producer
613 * may use the batons:
615 * 1. The producer may call @c open_directory, @c add_directory,
616 * @c open_file, @c add_file at most once on any given directory
617 * entry. @c delete_entry may be called at most once on any given
618 * directory entry and may later be followed by @c add_directory or
619 * @c add_file on the same directory entry. @c delete_entry may
620 * not be called on any directory entry after @c open_directory,
621 * @c add_directory, @c open_file or @c add_file has been called on
622 * that directory entry.
624 * 2. The producer may not close a directory baton until it has
625 * closed all batons for its subdirectories.
627 * 3. When a producer calls @c open_directory or @c add_directory,
628 * it must specify the most recently opened of the currently open
629 * directory batons. Put another way, the producer cannot have
630 * two sibling directory batons open at the same time.
632 * 4. A producer must call @c change_dir_prop on a directory either
633 * before opening any of the directory's subdirs or after closing
634 * them, but not in the middle.
636 * 5. When the producer calls @c open_file or @c add_file, either:
638 * (a) The producer must follow with any changes to the file
639 * (@c change_file_prop and/or @c apply_textdelta, as applicable),
640 * followed by a @c close_file call, before issuing any other file
641 * or directory calls, or
643 * (b) The producer must follow with a @c change_file_prop call if
644 * it is applicable, before issuing any other file or directory
645 * calls; later, after all directory batons including the root
646 * have been closed, the producer must issue @c apply_textdelta
647 * and @c close_file calls.
649 * 6. When the producer calls @c apply_textdelta, it must make all of
650 * the window handler calls (including the @c NULL window at the
651 * end) before issuing any other @c svn_delta_editor_t calls.
653 * So, the producer needs to use directory and file batons as if it
654 * is doing a single depth-first traversal of the tree, with the
655 * exception that the producer may keep file batons open in order to
656 * make @c apply_textdelta calls at the end.
659 * <h3>Pool Usage</h3>
661 * Many editor functions are invoked multiple times, in a sequence
662 * determined by the editor "driver". The driver is responsible for
663 * creating a pool for use on each iteration of the editor function,
664 * and clearing that pool between each iteration. The driver passes
665 * the appropriate pool on each function invocation.
667 * Based on the requirement of calling the editor functions in a
668 * depth-first style, it is usually customary for the driver to similarly
669 * nest the pools. However, this is only a safety feature to ensure
670 * that pools associated with deeper items are always cleared when the
671 * top-level items are also cleared. The interface does not assume, nor
672 * require, any particular organization of the pools passed to these
673 * functions. In fact, if "postfix deltas" are used for files, the file
674 * pools definitely need to live outside the scope of their parent
675 * directories' pools.
677 * Note that close_directory can be called *before* a file in that
678 * directory has been closed. That is, the directory's baton is
679 * closed before the file's baton. The implication is that
680 * @c apply_textdelta and @c close_file should not refer to a parent
681 * directory baton UNLESS the editor has taken precautions to
682 * allocate it in a pool of the appropriate lifetime (the @a dir_pool
683 * passed to @c open_directory and @c add_directory definitely does not
684 * have the proper lifetime). In general, it is recommended to simply
685 * avoid keeping a parent directory baton in a file baton.
688 * <h3>Errors</h3>
690 * At least one implementation of the editor interface is
691 * asynchronous; an error from one operation may be detected some
692 * number of operations later. As a result, an editor driver must not
693 * assume that an error from an editing function resulted from the
694 * particular operation being detected. Moreover, once an editing
695 * function returns an error, the edit is dead; the only further
696 * operation which may be called on the editor is abort_edit.
698 typedef struct svn_delta_editor_t
700 /** Set the target revision for this edit to @a target_revision. This
701 * call, if used, should precede all other editor calls.
703 svn_error_t *(*set_target_revision)(void *edit_baton,
704 svn_revnum_t target_revision,
705 apr_pool_t *pool);
707 /** Set @a *root_baton to a baton for the top directory of the change.
708 * (This is the top of the subtree being changed, not necessarily
709 * the root of the filesystem.) As with any other directory baton, the
710 * producer should call @c close_directory on @a root_baton when done.
711 * And as with other @c open_* calls, the @a base_revision here is the
712 * current revision of the directory (before getting bumped up to the
713 * new target revision set with @c set_target_revision).
715 * Allocations for the returned @a root_baton should be performed in
716 * @a dir_pool. It is also typical to (possibly) save this pool for later
717 * usage by @c close_directory.
719 svn_error_t *(*open_root)(void *edit_baton,
720 svn_revnum_t base_revision,
721 apr_pool_t *dir_pool,
722 void **root_baton);
725 /** Remove the directory entry named @a path, a child of the directory
726 * represented by @a parent_baton. If @a revision is a valid
727 * revision number, it is used as a sanity check to ensure that you
728 * are really removing the revision of @a path that you think you are.
730 * All allocations should be performed in @a pool.
732 svn_error_t *(*delete_entry)(const char *path,
733 svn_revnum_t revision,
734 void *parent_baton,
735 apr_pool_t *pool);
738 /** We are going to add a new subdirectory named @a path. We will use
739 * the value this callback stores in @a *child_baton as the
740 * @a parent_baton for further changes in the new subdirectory.
742 * If @a copyfrom_path is non-@c NULL, this add has history (i.e., is a
743 * copy), and the origin of the copy may be recorded as
744 * @a copyfrom_path under @a copyfrom_revision.
746 * Allocations for the returned @a child_baton should be performed in
747 * @a dir_pool. It is also typical to (possibly) save this pool for later
748 * usage by @c close_directory.
750 svn_error_t *(*add_directory)(const char *path,
751 void *parent_baton,
752 const char *copyfrom_path,
753 svn_revnum_t copyfrom_revision,
754 apr_pool_t *dir_pool,
755 void **child_baton);
757 /** We are going to make changes in a subdirectory (of the directory
758 * identified by @a parent_baton). The subdirectory is specified by
759 * @a path. The callback must store a value in @a *child_baton that
760 * should be used as the @a parent_baton for subsequent changes in this
761 * subdirectory. If a valid revnum, @a base_revision is the current
762 * revision of the subdirectory.
764 * Allocations for the returned @a child_baton should be performed in
765 * @a dir_pool. It is also typical to (possibly) save this pool for later
766 * usage by @c close_directory.
768 svn_error_t *(*open_directory)(const char *path,
769 void *parent_baton,
770 svn_revnum_t base_revision,
771 apr_pool_t *dir_pool,
772 void **child_baton);
774 /** Change the value of a directory's property.
775 * - @a dir_baton specifies the directory whose property should change.
776 * - @a name is the name of the property to change.
777 * - @a value is the new (final) value of the property, or @c NULL if the
778 * property should be removed altogether.
780 * The callback is guaranteed to be called exactly once for each property
781 * whose value differs between the start and the end of the edit.
783 * All allocations should be performed in @a pool.
785 svn_error_t *(*change_dir_prop)(void *dir_baton,
786 const char *name,
787 const svn_string_t *value,
788 apr_pool_t *pool);
790 /** We are done processing a subdirectory, whose baton is @a dir_baton
791 * (set by @c add_directory or @c open_directory). We won't be using
792 * the baton any more, so whatever resources it refers to may now be
793 * freed.
795 svn_error_t *(*close_directory)(void *dir_baton,
796 apr_pool_t *pool);
799 /** In the directory represented by @a parent_baton, indicate that
800 * @a path is present as a subdirectory in the edit source, but
801 * cannot be conveyed to the edit consumer (perhaps because of
802 * authorization restrictions).
804 svn_error_t *(*absent_directory)(const char *path,
805 void *parent_baton,
806 apr_pool_t *pool);
808 /** We are going to add a new file named @a path. The callback can
809 * store a baton for this new file in @a **file_baton; whatever value
810 * it stores there should be passed through to @c apply_textdelta.
812 * If @a copyfrom_path is non-@c NULL, this add has history (i.e., is a
813 * copy), and the origin of the copy may be recorded as
814 * @a copyfrom_path under @a copyfrom_revision.
816 * Allocations for the returned @a file_baton should be performed in
817 * @a file_pool. It is also typical to save this pool for later usage
818 * by @c apply_textdelta and possibly @c close_file.
820 svn_error_t *(*add_file)(const char *path,
821 void *parent_baton,
822 const char *copyfrom_path,
823 svn_revnum_t copyfrom_revision,
824 apr_pool_t *file_pool,
825 void **file_baton);
827 /** We are going to make change to a file named @a path, which resides
828 * in the directory identified by @a parent_baton.
830 * The callback can store a baton for this new file in @a **file_baton;
831 * whatever value it stores there should be passed through to
832 * @c apply_textdelta. If a valid revnum, @a base_revision is the
833 * current revision of the file.
835 * Allocations for the returned @a file_baton should be performed in
836 * @a file_pool. It is also typical to save this pool for later usage
837 * by @c apply_textdelta and possibly @c close_file.
839 svn_error_t *(*open_file)(const char *path,
840 void *parent_baton,
841 svn_revnum_t base_revision,
842 apr_pool_t *file_pool,
843 void **file_baton);
845 /** Apply a text delta, yielding the new revision of a file.
847 * @a file_baton indicates the file we're creating or updating, and the
848 * ancestor file on which it is based; it is the baton set by some
849 * prior @c add_file or @c open_file callback.
851 * The callback should set @a *handler to a text delta window
852 * handler; we will then call @a *handler on successive text
853 * delta windows as we receive them. The callback should set
854 * @a *handler_baton to the value we should pass as the @a baton
855 * argument to @a *handler.
857 * @a base_checksum is the hex MD5 digest for the base text against
858 * which the delta is being applied; it is ignored if NULL, and may
859 * be ignored even if not NULL. If it is not ignored, it must match
860 * the checksum of the base text against which svndiff data is being
861 * applied; if it does not, @c apply_textdelta or the @a *handler call
862 * which detects the mismatch will return the error
863 * SVN_ERR_CHECKSUM_MISMATCH (if there is no base text, there may
864 * still be an error if @a base_checksum is neither NULL nor the hex
865 * MD5 checksum of the empty string).
867 svn_error_t *(*apply_textdelta)(void *file_baton,
868 const char *base_checksum,
869 apr_pool_t *pool,
870 svn_txdelta_window_handler_t *handler,
871 void **handler_baton);
873 /** Change the value of a file's property.
874 * - @a file_baton specifies the file whose property should change.
875 * - @a name is the name of the property to change.
876 * - @a value is the new (final) value of the property, or @c NULL if the
877 * property should be removed altogether.
879 * The callback is guaranteed to be called exactly once for each property
880 * whose value differs between the start and the end of the edit.
882 * All allocations should be performed in @a pool.
884 svn_error_t *(*change_file_prop)(void *file_baton,
885 const char *name,
886 const svn_string_t *value,
887 apr_pool_t *pool);
889 /** We are done processing a file, whose baton is @a file_baton (set by
890 * @c add_file or @c open_file). We won't be using the baton any
891 * more, so whatever resources it refers to may now be freed.
893 * @a text_checksum is the hex MD5 digest for the fulltext that
894 * resulted from a delta application, see @c apply_textdelta. The
895 * checksum is ignored if NULL. If not null, it is compared to the
896 * checksum of the new fulltext, and the error
897 * SVN_ERR_CHECKSUM_MISMATCH is returned if they do not match. If
898 * there is no new fulltext, @a text_checksum is ignored.
900 svn_error_t *(*close_file)(void *file_baton,
901 const char *text_checksum,
902 apr_pool_t *pool);
904 /** In the directory represented by @a parent_baton, indicate that
905 * @a path is present as a file in the edit source, but cannot be
906 * conveyed to the edit consumer (perhaps because of authorization
907 * restrictions).
909 svn_error_t *(*absent_file)(const char *path,
910 void *parent_baton,
911 apr_pool_t *pool);
913 /** All delta processing is done. Call this, with the @a edit_baton for
914 * the entire edit.
916 svn_error_t *(*close_edit)(void *edit_baton,
917 apr_pool_t *pool);
919 /** The editor-driver has decided to bail out. Allow the editor to
920 * gracefully clean up things if it needs to.
922 svn_error_t *(*abort_edit)(void *edit_baton,
923 apr_pool_t *pool);
925 } svn_delta_editor_t;
928 /** Return a default delta editor template, allocated in @a pool.
930 * The editor functions in the template do only the most basic
931 * baton-swapping: each editor function that produces a baton does so
932 * by copying its incoming baton into the outgoing baton reference.
934 * This editor is not intended to be useful by itself, but is meant to
935 * be the basis for a useful editor. After getting a default editor,
936 * you substitute in your own implementations for the editor functions
937 * you care about. The ones you don't care about, you don't have to
938 * implement -- you can rely on the template's implementation to
939 * safely do nothing of consequence.
941 svn_delta_editor_t *svn_delta_default_editor(apr_pool_t *pool);
943 /** A text-delta window handler which does nothing.
945 * Editors can return this handler from @c apply_textdelta if they don't
946 * care about text delta windows.
948 svn_error_t *svn_delta_noop_window_handler(svn_txdelta_window_t *window,
949 void *baton);
951 /** Set @a *editor and @a *edit_baton to a cancellation editor that
952 * wraps @a wrapped_editor and @a wrapped_baton.
954 * The @a editor will call @a cancel_func with @a cancel_baton when each of
955 * its functions is called, continuing on to call the corresponding wrapped
956 * function if @a cancel_func returns @c SVN_NO_ERROR.
958 * If @a cancel_func is @c NULL, set @a *editor to @a wrapped_editor and
959 * @a *edit_baton to @a wrapped_baton.
961 svn_error_t *
962 svn_delta_get_cancellation_editor(svn_cancel_func_t cancel_func,
963 void *cancel_baton,
964 const svn_delta_editor_t *wrapped_editor,
965 void *wrapped_baton,
966 const svn_delta_editor_t **editor,
967 void **edit_baton,
968 apr_pool_t *pool);
970 /** Set @a *editor and @a *edit_baton to an depth-based filtering
971 * editor that wraps @a wrapped_editor and @a wrapped_baton.
973 * The @a editor will track the depth of this drive against the @a
974 * requested_depth, taking into account whether not the edit drive is
975 * making use of a target (via @a has_target), and forward editor
976 * calls which operate "within" the request depth range through to @a
977 * wrapped_editor.
979 * @a requested_depth must be one of the following depth values:
980 * @c svn_depth_infinity, @c svn_depth_empty, @c svn_depth_files,
981 * @c svn_depth_immediates, or @c svn_depth_unknown.
983 * If filtering is deemed unncessary (or if @a requested_depth is @c
984 * svn_depth_unknown), @a *editor and @a *edit_baton will be set to @a
985 * wrapped_editor and @a wrapped_baton, respectively; otherwise,
986 * they'll be set to new objects allocated from @a pool.
988 * @note Because the svn_delta_editor_t interface's @c delete_entry()
989 * function doesn't carry node kind information, a depth-based
990 * filtering editor being asked to filter for @c svn_depth_files but
991 * receiving a @c delete_entry() call on an immediate child of the
992 * editor's target is unable to know if that deletion should be
993 * allowed or filtered out -- a delete of a top-level file is okay in
994 * this case, a delete of a top-level subdirectory is not. As such,
995 * this filtering editor takes a conservative approach, and ignores
996 * top-level deletion requests when filtering for @c svn_depth_files.
997 * Fortunately, most non-depth-aware (pre-1.5) Subversion editor
998 * drivers can be told to drive non-recursively (where non-recursive
999 * means essentially @c svn_depth_files), which means they won't
1000 * transmit out-of-scope editor commands anyway.
1002 * @since New in 1.5.
1004 svn_error_t *
1005 svn_delta_depth_filter_editor(const svn_delta_editor_t **editor,
1006 void **edit_baton,
1007 const svn_delta_editor_t *wrapped_editor,
1008 void *wrapped_edit_baton,
1009 svn_depth_t requested_depth,
1010 svn_boolean_t has_target,
1011 apr_pool_t *pool);
1013 /** @} */
1016 /** Path-based editor drives.
1018 * @defgroup svn_delta_path_delta_drivers Path-based delta drivers
1019 * @{
1022 /** Callback function type for svn_delta_path_driver().
1024 * The handler of this callback is given the callback baton @a
1025 * callback_baton, @a path, and the @a parent_baton which represents
1026 * path's parent directory as created by the editor passed to
1027 * svn_delta_path_driver().
1029 * If @a path represents a directory, the handler must return a @a
1030 * *dir_baton for @a path, generated from the same editor (so that the
1031 * driver can later close that directory).
1033 * If, however, @a path represents a file, the handler should NOT
1034 * return any file batons. It can close any opened or added files
1035 * immediately, or delay that close until the end of the edit when
1036 * svn_delta_path_driver() returns.
1038 * Finally, if @a parent_baton is @c NULL, then the root of the edit
1039 * is also one of the paths passed to svn_delta_path_driver(). The
1040 * handler of this callback must call the editor's open_root()
1041 * function and return the top-level root dir baton in @a *dir_baton.
1043 typedef svn_error_t *(*svn_delta_path_driver_cb_func_t)
1044 (void **dir_baton,
1045 void *parent_baton,
1046 void *callback_baton,
1047 const char *path,
1048 apr_pool_t *pool);
1051 /** Drive @a editor (with its @a edit_baton) in such a way that
1052 * each path in @a paths is traversed in a depth-first fashion. As
1053 * each path is hit as part of the editor drive, use @a
1054 * callback_func and @a callback_baton to allow the caller to handle
1055 * the portion of the editor drive related to that path.
1057 * Use @a revision as the revision number passed to intermediate
1058 * directory openings.
1060 * Use @a pool for all necessary allocations.
1062 svn_error_t *
1063 svn_delta_path_driver(const svn_delta_editor_t *editor,
1064 void *edit_baton,
1065 svn_revnum_t revision,
1066 apr_array_header_t *paths,
1067 svn_delta_path_driver_cb_func_t callback_func,
1068 void *callback_baton,
1069 apr_pool_t *pool);
1071 /** @} */
1074 /*** File revision iterator types ***/
1077 * The callback invoked by file rev loopers, such as
1078 * svn_ra_plugin_t.get_file_revs2() and svn_repos_get_file_revs2().
1080 * @a baton is provided by the caller, @a path is the pathname of the file
1081 * in revision @a rev and @a rev_props are the revision properties.
1083 * If @a delta_handler and @a delta_baton are non-NULL, they may be set to a
1084 * handler/baton which will be called with the delta between the previous
1085 * revision and this one after the return of this callback. They may be
1086 * left as NULL/NULL.
1088 * @a result_of_merge will be @c TRUE if the revision being returned was
1089 * included as the result of a merge.
1091 * @a prop_diffs is an array of svn_prop_t elements indicating the property
1092 * delta for this and the previous revision.
1094 * @a pool may be used for temporary allocations, but you can't rely
1095 * on objects allocated to live outside of this particular call and
1096 * the immediately following calls to @a *delta_handler if any. (Pass
1097 * in a pool via @a baton if need be.)
1099 * @since New in 1.5.
1101 typedef svn_error_t *(*svn_file_rev_handler_t)
1102 (void *baton,
1103 const char *path,
1104 svn_revnum_t rev,
1105 apr_hash_t *rev_props,
1106 svn_boolean_t result_of_merge,
1107 svn_txdelta_window_handler_t *delta_handler,
1108 void **delta_baton,
1109 apr_array_header_t *prop_diffs,
1110 apr_pool_t *pool);
1113 * The old file rev handler interface.
1115 * @note @c svn_file_rev_handler_old_t is a placeholder type for both
1116 * @c svn_repos_file_rev_handler_t and @c svn_ra_file_rev_handler_t. It is
1117 * reproduced here for dependency reasons.
1119 * @deprecated This type is provided for the svn_compat_wrap_file_rev_handler()
1120 * compatibilty wrapper, and should not be used for new development.
1121 * @since New in 1.5.
1123 typedef svn_error_t *(*svn_file_rev_handler_old_t)
1124 (void *baton,
1125 const char *path,
1126 svn_revnum_t rev,
1127 apr_hash_t *rev_props,
1128 svn_txdelta_window_handler_t *delta_handler,
1129 void **delta_baton,
1130 apr_array_header_t *prop_diffs,
1131 apr_pool_t *pool);
1133 /** Return, in @a *handler2 and @a *handler2_baton a function/baton that
1134 * will call @a handler/@a handler_baton, allocating the @a *handler2_baton
1135 * in @a pool.
1137 * @note This is used by compatibility wrappers, which exist in more than
1138 * Subversion core library.
1140 * @note @c svn_file_rev_handler_old_t is a placeholder type for both
1141 * @c svn_repos_file_rev_handler_t and @c svn_ra_file_rev_handler_t. It is
1142 * reproduced here for dependency reasons.
1144 * @since New in 1.5.
1146 void
1147 svn_compat_wrap_file_rev_handler(svn_file_rev_handler_t *handler2,
1148 void **handler2_baton,
1149 svn_file_rev_handler_old_t handler,
1150 void *handler_baton,
1151 apr_pool_t *pool);
1153 /** @} end group: delta_support */
1156 #ifdef __cplusplus
1158 #endif /* __cplusplus */
1160 #endif /* SVN_DELTA_H */