00001 /** 00002 * @copyright 00003 * ==================================================================== 00004 * Licensed to the Apache Software Foundation (ASF) under one 00005 * or more contributor license agreements. See the NOTICE file 00006 * distributed with this work for additional information 00007 * regarding copyright ownership. The ASF licenses this file 00008 * to you under the Apache License, Version 2.0 (the 00009 * "License"); you may not use this file except in compliance 00010 * with the License. You may obtain a copy of the License at 00011 * 00012 * http://www.apache.org/licenses/LICENSE-2.0 00013 * 00014 * Unless required by applicable law or agreed to in writing, 00015 * software distributed under the License is distributed on an 00016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 00017 * KIND, either express or implied. See the License for the 00018 * specific language governing permissions and limitations 00019 * under the License. 00020 * ==================================================================== 00021 * @endcopyright 00022 * 00023 * @file svn_delta.h 00024 * @brief Delta-parsing 00025 */ 00026 00027 /* ==================================================================== */ 00028 00029 00030 00031 #ifndef SVN_DELTA_H 00032 #define SVN_DELTA_H 00033 00034 #include <apr.h> 00035 #include <apr_pools.h> 00036 #include <apr_hash.h> 00037 #include <apr_tables.h> 00038 #include <apr_file_io.h> /* for apr_file_t */ 00039 00040 #include "svn_types.h" 00041 #include "svn_string.h" 00042 #include "svn_io.h" 00043 #include "svn_checksum.h" 00044 00045 #ifdef __cplusplus 00046 extern "C" { 00047 #endif /* __cplusplus */ 00048 00049 00050 00051 /** This compression level effectively disables data compression. 00052 * However, the data pre-processing costs may still not be zero. 00053 * 00054 * @since New in 1.7. 00055 */ 00056 #define SVN_DELTA_COMPRESSION_LEVEL_NONE 0 00057 00058 /** This is the maximum compression level we can pass to zlib. 00059 * 00060 * @since New in 1.7. 00061 */ 00062 #define SVN_DELTA_COMPRESSION_LEVEL_MAX 9 00063 00064 /** This is the default compression level we pass to zlib. It 00065 * should be between 0 and 9, with higher numbers resulting in 00066 * better compression rates but slower operation. 00067 * 00068 * @since New in 1.7. 00069 */ 00070 #define SVN_DELTA_COMPRESSION_LEVEL_DEFAULT 5 00071 00072 /** 00073 * Get libsvn_delta version information. 00074 * 00075 * @since New in 1.1. 00076 */ 00077 const svn_version_t * 00078 svn_delta_version(void); 00079 00080 /** 00081 * @defgroup delta_support Delta generation and handling 00082 * 00083 * @{ 00084 */ 00085 00086 /** Text deltas. 00087 * 00088 * A text delta represents the difference between two strings of 00089 * bytes, the `source' string and the `target' string. Given a source 00090 * string and a target string, we can compute a text delta; given a 00091 * source string and a delta, we can reconstruct the target string. 00092 * However, note that deltas are not reversible: you cannot always 00093 * reconstruct the source string given the target string and delta. 00094 * 00095 * Since text deltas can be very large, the interface here allows us 00096 * to produce and consume them in pieces. Each piece, represented by 00097 * an #svn_txdelta_window_t structure, describes how to produce the 00098 * next section of the target string. 00099 * 00100 * To compute a new text delta: 00101 * 00102 * - We call svn_txdelta() on the streams we want to compare. That 00103 * returns us an #svn_txdelta_stream_t object. 00104 * 00105 * - We then call svn_txdelta_next_window() on the stream object 00106 * repeatedly. Each call returns a new #svn_txdelta_window_t 00107 * object, which describes the next portion of the target string. 00108 * When svn_txdelta_next_window() returns zero, we are done building 00109 * the target string. 00110 * 00111 * @defgroup svn_delta_txt_delta Text deltas 00112 * @{ 00113 */ 00114 00115 /** Action codes for text delta instructions. */ 00116 enum svn_delta_action { 00117 /* Note: The svndiff implementation relies on the values assigned in 00118 * this enumeration matching the instruction encoding values. */ 00119 00120 /** Append the @a length bytes at @a offset in the source view to the 00121 * target. 00122 * 00123 * It must be the case that 0 <= @a offset < @a offset + 00124 * @a length <= size of source view. 00125 */ 00126 svn_txdelta_source, 00127 00128 /** Append the @a length bytes at @a offset in the target view, to the 00129 * target. 00130 * 00131 * It must be the case that 0 <= @a offset < current position in the 00132 * target view. 00133 * 00134 * However! @a offset + @a length may be *beyond* the end of the existing 00135 * target data. "Where the heck does the text come from, then?" 00136 * If you start at @a offset, and append @a length bytes one at a time, 00137 * it'll work out --- you're adding new bytes to the end at the 00138 * same rate you're reading them from the middle. Thus, if your 00139 * current target text is "abcdefgh", and you get an #svn_txdelta_target 00140 * instruction whose @a offset is 6 and whose @a length is 7, 00141 * the resulting string is "abcdefghghghghg". This trick is actually 00142 * useful in encoding long runs of consecutive characters, long runs 00143 * of CR/LF pairs, etc. 00144 */ 00145 svn_txdelta_target, 00146 00147 /** Append the @a length bytes at @a offset in the window's @a new string 00148 * to the target. 00149 * 00150 * It must be the case that 0 <= @a offset < @a offset + 00151 * @a length <= length of @a new. Windows MUST use new data in ascending 00152 * order with no overlap at the moment; svn_txdelta_to_svndiff() 00153 * depends on this. 00154 */ 00155 svn_txdelta_new 00156 }; 00157 00158 /** A single text delta instruction. */ 00159 typedef struct svn_txdelta_op_t 00160 { 00161 /** Action code of delta instruction */ 00162 enum svn_delta_action action_code; 00163 /** Offset of delta, see #svn_delta_action for more details. */ 00164 apr_size_t offset; 00165 /** Number of bytes of delta, see #svn_delta_action for more details. */ 00166 apr_size_t length; 00167 } svn_txdelta_op_t; 00168 00169 00170 /** An #svn_txdelta_window_t object describes how to reconstruct a 00171 * contiguous section of the target string (the "target view") using a 00172 * specified contiguous region of the source string (the "source 00173 * view"). It contains a series of instructions which assemble the 00174 * new target string text by pulling together substrings from: 00175 * 00176 * - the source view, 00177 * 00178 * - the previously constructed portion of the target view, 00179 * 00180 * - a string of new data contained within the window structure 00181 * 00182 * The source view must always slide forward from one window to the 00183 * next; that is, neither the beginning nor the end of the source view 00184 * may move to the left as we read from a window stream. This 00185 * property allows us to apply deltas to non-seekable source streams 00186 * without making a full copy of the source stream. 00187 */ 00188 typedef struct svn_txdelta_window_t 00189 { 00190 00191 /** The offset of the source view for this window. */ 00192 svn_filesize_t sview_offset; 00193 00194 /** The length of the source view for this window. */ 00195 apr_size_t sview_len; 00196 00197 /** The length of the target view for this window, i.e. the number of 00198 * bytes which will be reconstructed by the instruction stream. */ 00199 apr_size_t tview_len; 00200 00201 /** The number of instructions in this window. */ 00202 int num_ops; 00203 00204 /** The number of svn_txdelta_source instructions in this window. If 00205 * this number is 0, we don't need to read the source in order to 00206 * reconstruct the target view. 00207 */ 00208 int src_ops; 00209 00210 /** The instructions for this window. */ 00211 const svn_txdelta_op_t *ops; 00212 00213 /** New data, for use by any `svn_txdelta_new' instructions. */ 00214 const svn_string_t *new_data; 00215 00216 } svn_txdelta_window_t; 00217 00218 /** 00219 * Return a deep copy of @a window, allocated in @a pool. 00220 * 00221 * @since New in 1.3. 00222 */ 00223 svn_txdelta_window_t * 00224 svn_txdelta_window_dup(const svn_txdelta_window_t *window, 00225 apr_pool_t *pool); 00226 00227 /** 00228 * Compose two delta windows, yielding a third, allocated in @a pool. 00229 * 00230 * @since New in 1.4 00231 * 00232 */ 00233 svn_txdelta_window_t * 00234 svn_txdelta_compose_windows(const svn_txdelta_window_t *window_A, 00235 const svn_txdelta_window_t *window_B, 00236 apr_pool_t *pool); 00237 00238 /** 00239 * Apply the instructions from @a window to a source view @a sbuf to 00240 * produce a target view @a tbuf. 00241 * 00242 * @a sbuf is assumed to have @a window->sview_len bytes of data and 00243 * @a tbuf is assumed to have room for @a tlen bytes of output. @a 00244 * tlen may be more than @a window->tview_len, so return the actual 00245 * number of bytes written. @a sbuf is not touched and may be NULL if 00246 * @a window contains no source-copy operations. This is purely a 00247 * memory operation; nothing can go wrong as long as we have a valid 00248 * window. 00249 * 00250 * @since New in 1.4 00251 * 00252 * @since Since 1.9, @a tbuf may be NULL if @a *tlen is 0. 00253 */ 00254 void 00255 svn_txdelta_apply_instructions(svn_txdelta_window_t *window, 00256 const char *sbuf, char *tbuf, 00257 apr_size_t *tlen); 00258 00259 /** A typedef for functions that consume a series of delta windows, for 00260 * use in caller-pushes interfaces. Such functions will typically 00261 * apply the delta windows to produce some file, or save the windows 00262 * somewhere. At the end of the delta window stream, you must call 00263 * this function passing zero for the @a window argument. 00264 */ 00265 typedef svn_error_t *(*svn_txdelta_window_handler_t)( 00266 svn_txdelta_window_t *window, void *baton); 00267 00268 00269 /** This function will generate delta windows that turn @a source into 00270 * @a target, and pushing these windows into the @a handler window handler 00271 * callback (passing @a handler_baton to each invocation). 00272 * 00273 * If @a checksum is not NULL, then a checksum (of kind @a checksum_kind) 00274 * will be computed for the target stream, and placed into *checksum. 00275 * 00276 * If @a cancel_func is not NULL, then it should refer to a cancellation 00277 * function (along with @a cancel_baton). 00278 * 00279 * Results (the checksum) will be allocated from @a result_pool, and all 00280 * temporary allocations will be performed in @a scratch_pool. 00281 * 00282 * Note: this function replaces the combination of svn_txdelta() and 00283 * svn_txdelta_send_txstream(). 00284 * 00285 * @since New in 1.6. 00286 */ 00287 svn_error_t * 00288 svn_txdelta_run(svn_stream_t *source, 00289 svn_stream_t *target, 00290 svn_txdelta_window_handler_t handler, 00291 void *handler_baton, 00292 svn_checksum_kind_t checksum_kind, 00293 svn_checksum_t **checksum, 00294 svn_cancel_func_t cancel_func, 00295 void *cancel_baton, 00296 apr_pool_t *result_pool, 00297 apr_pool_t *scratch_pool); 00298 00299 00300 /** A delta stream --- this is the hat from which we pull a series of 00301 * svn_txdelta_window_t objects, which, taken in order, describe the 00302 * entire target string. This type is defined within libsvn_delta, and 00303 * opaque outside that library. 00304 */ 00305 typedef struct svn_txdelta_stream_t svn_txdelta_stream_t; 00306 00307 00308 /** A typedef for a function that will set @a *window to the next 00309 * window from a #svn_txdelta_stream_t object. If there are no more 00310 * delta windows, NULL will be used. The returned window, if any, 00311 * will be allocated in @a pool. @a baton is the baton specified 00312 * when the stream was created. 00313 * 00314 * @since New in 1.4. 00315 */ 00316 typedef svn_error_t * 00317 (*svn_txdelta_next_window_fn_t)(svn_txdelta_window_t **window, 00318 void *baton, 00319 apr_pool_t *pool); 00320 00321 /** A typedef for a function that will return the md5 checksum of the 00322 * fulltext deltified by a #svn_txdelta_stream_t object. Will 00323 * return NULL if the final null window hasn't yet been returned by 00324 * the stream. The returned value will be allocated in the same pool 00325 * as the stream. @a baton is the baton specified when the stream was 00326 * created. 00327 * 00328 * @since New in 1.4. 00329 */ 00330 typedef const unsigned char * 00331 (*svn_txdelta_md5_digest_fn_t)(void *baton); 00332 00333 /** A typedef for a function that opens an #svn_txdelta_stream_t object, 00334 * allocated in @a result_pool. @a baton is provided by the caller. 00335 * Any temporary allocations may be performed in @a scratch_pool. 00336 * 00337 * @since New in 1.10. 00338 */ 00339 typedef svn_error_t * 00340 (*svn_txdelta_stream_open_func_t)(svn_txdelta_stream_t **txdelta_stream, 00341 void *baton, 00342 apr_pool_t *result_pool, 00343 apr_pool_t *scratch_pool); 00344 00345 /** Create and return a generic text delta stream with @a baton, @a 00346 * next_window and @a md5_digest. Allocate the new stream in @a 00347 * pool. 00348 * 00349 * @since New in 1.4. 00350 */ 00351 svn_txdelta_stream_t * 00352 svn_txdelta_stream_create(void *baton, 00353 svn_txdelta_next_window_fn_t next_window, 00354 svn_txdelta_md5_digest_fn_t md5_digest, 00355 apr_pool_t *pool); 00356 00357 /** Set @a *window to a pointer to the next window from the delta stream 00358 * @a stream. When we have completely reconstructed the target string, 00359 * set @a *window to zero. 00360 * 00361 * The window will be allocated in @a pool. 00362 */ 00363 svn_error_t * 00364 svn_txdelta_next_window(svn_txdelta_window_t **window, 00365 svn_txdelta_stream_t *stream, 00366 apr_pool_t *pool); 00367 00368 00369 /** Return the md5 digest for the complete fulltext deltified by 00370 * @a stream, or @c NULL if @a stream has not yet returned its final 00371 * @c NULL window. The digest is allocated in the same memory as @a 00372 * STREAM. 00373 */ 00374 const unsigned char * 00375 svn_txdelta_md5_digest(svn_txdelta_stream_t *stream); 00376 00377 /** Set @a *stream to a pointer to a delta stream that will turn the byte 00378 * string from @a source into the byte stream from @a target. 00379 * 00380 * @a source and @a target are both readable generic streams. When we call 00381 * svn_txdelta_next_window() on @a *stream, it will read from @a source and 00382 * @a target to gather as much data as it needs. If @a calculate_checksum 00383 * is set, you may call svn_txdelta_md5_digest() to get an MD5 checksum 00384 * for @a target. 00385 * 00386 * Do any necessary allocation in a sub-pool of @a pool. 00387 * 00388 * @since New in 1.8. 00389 */ 00390 void 00391 svn_txdelta2(svn_txdelta_stream_t **stream, 00392 svn_stream_t *source, 00393 svn_stream_t *target, 00394 svn_boolean_t calculate_checksum, 00395 apr_pool_t *pool); 00396 00397 /** Similar to svn_txdelta2 but always calculating the target checksum. 00398 * 00399 * @deprecated Provided for backward compatibility with the 1.7 API. 00400 */ 00401 SVN_DEPRECATED 00402 void 00403 svn_txdelta(svn_txdelta_stream_t **stream, 00404 svn_stream_t *source, 00405 svn_stream_t *target, 00406 apr_pool_t *pool); 00407 00408 00409 /** 00410 * Return a writable stream which, when fed target data, will send 00411 * delta windows to @a handler/@a handler_baton which transform the 00412 * data in @a source to the target data. As usual, the window handler 00413 * will receive a NULL window to signify the end of the window stream. 00414 * The stream handler functions will read data from @a source as 00415 * necessary. 00416 * 00417 * @since New in 1.1. 00418 */ 00419 svn_stream_t * 00420 svn_txdelta_target_push(svn_txdelta_window_handler_t handler, 00421 void *handler_baton, 00422 svn_stream_t *source, 00423 apr_pool_t *pool); 00424 00425 00426 /** Send the contents of @a string to window-handler @a handler/@a baton. 00427 * This is effectively a 'copy' operation, resulting in delta windows that 00428 * make the target equivalent to the value of @a string. 00429 * 00430 * All temporary allocation is performed in @a pool. 00431 */ 00432 svn_error_t * 00433 svn_txdelta_send_string(const svn_string_t *string, 00434 svn_txdelta_window_handler_t handler, 00435 void *handler_baton, 00436 apr_pool_t *pool); 00437 00438 /** Send the contents of @a stream to window-handler @a handler/@a baton. 00439 * This is effectively a 'copy' operation, resulting in delta windows that 00440 * make the target equivalent to the stream. 00441 * 00442 * If @a digest is non-NULL, populate it with the md5 checksum for the 00443 * fulltext that was deltified (@a digest must be at least 00444 * @c APR_MD5_DIGESTSIZE bytes long). 00445 * 00446 * All temporary allocation is performed in @a pool. 00447 */ 00448 svn_error_t * 00449 svn_txdelta_send_stream(svn_stream_t *stream, 00450 svn_txdelta_window_handler_t handler, 00451 void *handler_baton, 00452 unsigned char *digest, 00453 apr_pool_t *pool); 00454 00455 /** Send the contents of @a txstream to window-handler @a handler/@a baton. 00456 * Windows will be extracted from the stream and delivered to the handler. 00457 * 00458 * All temporary allocation is performed in @a pool. 00459 */ 00460 svn_error_t * 00461 svn_txdelta_send_txstream(svn_txdelta_stream_t *txstream, 00462 svn_txdelta_window_handler_t handler, 00463 void *handler_baton, 00464 apr_pool_t *pool); 00465 00466 00467 /** Send the @a contents of length @a len as a txdelta against an empty 00468 * source directly to window-handler @a handler/@a handler_baton. 00469 * 00470 * All temporary allocation is performed in @a pool. 00471 * 00472 * @since New in 1.8. 00473 */ 00474 svn_error_t * 00475 svn_txdelta_send_contents(const unsigned char *contents, 00476 apr_size_t len, 00477 svn_txdelta_window_handler_t handler, 00478 void *handler_baton, 00479 apr_pool_t *pool); 00480 00481 /** Prepare to apply a text delta. @a source is a readable generic stream 00482 * yielding the source data, @a target is a writable generic stream to 00483 * write target data to, and allocation takes place in a sub-pool of 00484 * @a pool. On return, @a *handler is set to a window handler function and 00485 * @a *handler_baton is set to the value to pass as the @a baton argument to 00486 * @a *handler. 00487 * 00488 * If @a result_digest is non-NULL, it points to APR_MD5_DIGESTSIZE bytes 00489 * of storage, and the final call to @a handler populates it with the 00490 * MD5 digest of the resulting fulltext. 00491 * 00492 * If @a error_info is non-NULL, it is inserted parenthetically into 00493 * the error string for any error returned by svn_txdelta_apply() or 00494 * @a *handler. (It is normally used to provide path information, 00495 * since there's nothing else in the delta application's context to 00496 * supply a path for error messages.) 00497 * 00498 * @note To avoid lifetime issues, @a error_info is copied into 00499 * @a pool or a subpool thereof. 00500 */ 00501 void 00502 svn_txdelta_apply(svn_stream_t *source, 00503 svn_stream_t *target, 00504 unsigned char *result_digest, 00505 const char *error_info, 00506 apr_pool_t *pool, 00507 svn_txdelta_window_handler_t *handler, 00508 void **handler_baton); 00509 00510 00511 00512 00513 /*** Producing and consuming svndiff-format text deltas. ***/ 00514 00515 /** Prepare to produce an svndiff-format diff from text delta windows. 00516 * @a output is a writable generic stream to write the svndiff data to. 00517 * Allocation takes place in a sub-pool of @a pool. On return, @a *handler 00518 * is set to a window handler function and @a *handler_baton is set to 00519 * the value to pass as the @a baton argument to @a *handler. The svndiff 00520 * version is @a svndiff_version. @a compression_level is the zlib 00521 * compression level from 0 (no compression) and 9 (maximum compression). 00522 * 00523 * @since New in 1.7. Since 1.10, @a svndiff_version can be 2 for the 00524 * svndiff2 format. @a compression_level is currently ignored if 00525 * @a svndiff_version is set to 2. 00526 */ 00527 void 00528 svn_txdelta_to_svndiff3(svn_txdelta_window_handler_t *handler, 00529 void **handler_baton, 00530 svn_stream_t *output, 00531 int svndiff_version, 00532 int compression_level, 00533 apr_pool_t *pool); 00534 00535 /** Similar to svn_txdelta_to_svndiff3(), but always using the SVN default 00536 * compression level (#SVN_DELTA_COMPRESSION_LEVEL_DEFAULT). 00537 * 00538 * @since New in 1.4. 00539 * @deprecated Provided for backward compatibility with the 1.6 API. 00540 */ 00541 SVN_DEPRECATED 00542 void 00543 svn_txdelta_to_svndiff2(svn_txdelta_window_handler_t *handler, 00544 void **handler_baton, 00545 svn_stream_t *output, 00546 int svndiff_version, 00547 apr_pool_t *pool); 00548 00549 /** Similar to svn_txdelta_to_svndiff2, but always using svndiff 00550 * version 0. 00551 * 00552 * @deprecated Provided for backward compatibility with the 1.3 API. 00553 */ 00554 SVN_DEPRECATED 00555 void 00556 svn_txdelta_to_svndiff(svn_stream_t *output, 00557 apr_pool_t *pool, 00558 svn_txdelta_window_handler_t *handler, 00559 void **handler_baton); 00560 00561 /** Return a readable generic stream which will produce svndiff-encoded 00562 * text delta from the delta stream @a txstream. @a svndiff_version and 00563 * @a compression_level are same as in svn_txdelta_to_svndiff3(). 00564 * 00565 * Allocate the stream in @a pool. 00566 * 00567 * @since New in 1.10. 00568 */ 00569 svn_stream_t * 00570 svn_txdelta_to_svndiff_stream(svn_txdelta_stream_t *txstream, 00571 int svndiff_version, 00572 int compression_level, 00573 apr_pool_t *pool); 00574 00575 /** Return a writable generic stream which will parse svndiff-format 00576 * data into a text delta, invoking @a handler with @a handler_baton 00577 * whenever a new window is ready. 00578 * 00579 * When the caller closes this stream, this will signal completion to 00580 * the window handler by invoking @a handler once more, passing zero for 00581 * the @c window argument. 00582 * 00583 * If @a error_on_early_close is @c TRUE, then attempt to avoid 00584 * signaling completion to the window handler if the delta was 00585 * incomplete. Specifically, attempting to close the stream will be 00586 * successful only if the data written to the stream consisted of one or 00587 * more complete windows of svndiff data and no extra bytes. Otherwise, 00588 * closing the stream will not signal completion to the window handler, 00589 * and will return a #SVN_ERR_SVNDIFF_UNEXPECTED_END error. Note that if 00590 * no data at all was written, the delta is considered incomplete. 00591 * 00592 * If @a error_on_early_close is @c FALSE, closing the stream will 00593 * signal completion to the window handler, regardless of how much data 00594 * was written, and discard any pending incomplete data. 00595 * 00596 * Allocate the stream in @a pool. 00597 */ 00598 svn_stream_t * 00599 svn_txdelta_parse_svndiff(svn_txdelta_window_handler_t handler, 00600 void *handler_baton, 00601 svn_boolean_t error_on_early_close, 00602 apr_pool_t *pool); 00603 00604 /** 00605 * Read and parse one delta window in svndiff format from the 00606 * readable stream @a stream and place it in @a *window, allocating 00607 * the result in @a pool. The caller must take responsibility for 00608 * stripping off the four-byte 'SVN@<ver@>' header at the beginning of 00609 * the svndiff document before reading the first window, and must 00610 * provide the version number (the value of the fourth byte) to each 00611 * invocation of this routine with the @a svndiff_version argument. 00612 * 00613 * @since New in 1.1. 00614 */ 00615 svn_error_t * 00616 svn_txdelta_read_svndiff_window(svn_txdelta_window_t **window, 00617 svn_stream_t *stream, 00618 int svndiff_version, 00619 apr_pool_t *pool); 00620 00621 /** 00622 * Read and skip one delta window in svndiff format from the 00623 * file @a file. @a pool is used for temporary allocations. The 00624 * caller must take responsibility for stripping off the four-byte 00625 * 'SVN@<ver@>' header at the beginning of the svndiff document before 00626 * reading or skipping the first window, and must provide the version 00627 * number (the value of the fourth byte) to each invocation of this 00628 * routine with the @a svndiff_version argument. 00629 * 00630 * @since New in 1.1. 00631 */ 00632 svn_error_t * 00633 svn_txdelta_skip_svndiff_window(apr_file_t *file, 00634 int svndiff_version, 00635 apr_pool_t *pool); 00636 00637 /** @} */ 00638 00639 00640 /** Traversing tree deltas. 00641 * 00642 * In Subversion, we've got various producers and consumers of tree 00643 * deltas. 00644 * 00645 * In processing a `commit' command: 00646 * - The client examines its working copy data, and produces a tree 00647 * delta describing the changes to be committed. 00648 * - The client networking library consumes that delta, and sends them 00649 * across the wire as an equivalent series of network requests (for 00650 * example, to svnserve as an ra_svn protocol stream, or to an 00651 * Apache httpd server as WebDAV commands) 00652 * - The server receives those requests and produces a tree delta --- 00653 * hopefully equivalent to the one the client produced above. 00654 * - The Subversion server module consumes that delta and commits an 00655 * appropriate transaction to the filesystem. 00656 * 00657 * In processing an `update' command, the process is reversed: 00658 * - The Subversion server module talks to the filesystem and produces 00659 * a tree delta describing the changes necessary to bring the 00660 * client's working copy up to date. 00661 * - The server consumes this delta, and assembles a reply 00662 * representing the appropriate changes. 00663 * - The client networking library receives that reply, and produces a 00664 * tree delta --- hopefully equivalent to the one the Subversion 00665 * server produced above. 00666 * - The working copy library consumes that delta, and makes the 00667 * appropriate changes to the working copy. 00668 * 00669 * The simplest approach would be to represent tree deltas using the 00670 * obvious data structure. To do an update, the server would 00671 * construct a delta structure, and the working copy library would 00672 * apply that structure to the working copy; the network layer's job 00673 * would simply be to get the structure across the net intact. 00674 * 00675 * However, we expect that these deltas will occasionally be too large 00676 * to fit in a typical workstation's swap area. For example, in 00677 * checking out a 200Mb source tree, the entire source tree is 00678 * represented by a single tree delta. So it's important to handle 00679 * deltas that are too large to fit in swap all at once. 00680 * 00681 * So instead of representing the tree delta explicitly, we define a 00682 * standard way for a consumer to process each piece of a tree delta 00683 * as soon as the producer creates it. The #svn_delta_editor_t 00684 * structure is a set of callback functions to be defined by a delta 00685 * consumer, and invoked by a delta producer. Each invocation of a 00686 * callback function describes a piece of the delta --- a file's 00687 * contents changing, something being renamed, etc. 00688 * 00689 * @defgroup svn_delta_tree_deltas Tree deltas 00690 * @{ 00691 */ 00692 00693 /** A structure full of callback functions the delta source will invoke 00694 * as it produces the delta. 00695 * 00696 * @note Don't try to allocate one of these yourself. Instead, always 00697 * use svn_delta_default_editor() or some other constructor, to avoid 00698 * backwards compatibility problems if the structure is extended in 00699 * future releases and to ensure that unused slots are filled in with 00700 * no-op functions. 00701 * 00702 * <h3>Function Usage</h3> 00703 * 00704 * Here's how to use these functions to express a tree delta. 00705 * 00706 * The delta consumer implements the callback functions described in 00707 * this structure, and the delta producer invokes them. So the 00708 * caller (producer) is pushing tree delta data at the callee 00709 * (consumer). 00710 * 00711 * At the start of traversal, the consumer provides @a edit_baton, a 00712 * baton global to the entire delta edit. If there is a target 00713 * revision that needs to be set for this operation, the producer 00714 * should call the @c set_target_revision function at this point. 00715 * 00716 * Next, if there are any tree deltas to express, the producer should 00717 * pass the @a edit_baton to the @c open_root function, to get a baton 00718 * representing root of the tree being edited. 00719 * 00720 * Most of the callbacks work in the obvious way: 00721 * 00722 * @c delete_entry 00723 * @c add_file 00724 * @c add_directory 00725 * @c open_file 00726 * @c open_directory 00727 * 00728 * Each of these takes a directory baton, indicating the directory 00729 * in which the change takes place, and a @a path argument, giving the 00730 * path of the file, subdirectory, or directory entry to change. 00731 * 00732 * The @a path argument to each of the callbacks is relative to the 00733 * root of the edit. Editors will usually want to join this relative 00734 * path with some base stored in the edit baton (e.g. a URL, or a 00735 * location in the OS filesystem). 00736 * 00737 * Since every call requires a parent directory baton, including 00738 * @c add_directory and @c open_directory, where do we ever get our 00739 * initial directory baton, to get things started? The @c open_root 00740 * function returns a baton for the top directory of the change. In 00741 * general, the producer needs to invoke the editor's @c open_root 00742 * function before it can get anything of interest done. 00743 * 00744 * While @c open_root provides a directory baton for the root of 00745 * the tree being changed, the @c add_directory and @c open_directory 00746 * callbacks provide batons for other directories. Like the 00747 * callbacks above, they take a @a parent_baton and a relative path 00748 * @a path, and then return a new baton for the subdirectory being 00749 * created / modified --- @a child_baton. The producer can then use 00750 * @a child_baton to make further changes in that subdirectory. 00751 * 00752 * So, if we already have subdirectories named `foo' and `foo/bar', 00753 * then the producer can create a new file named `foo/bar/baz.c' by 00754 * calling: 00755 * 00756 * - @c open_root () --- yielding a baton @a root for the top directory 00757 * 00758 * - @c open_directory (@a root, "foo") --- yielding a baton @a f for `foo' 00759 * 00760 * - @c open_directory (@a f, "foo/bar") --- yielding a baton @a b for 00761 * `foo/bar' 00762 * 00763 * - @c add_file (@a b, "foo/bar/baz.c") 00764 * 00765 * When the producer is finished making changes to a directory, it 00766 * should call @c close_directory. This lets the consumer do any 00767 * necessary cleanup, and free the baton's storage. 00768 * 00769 * The @c add_file and @c open_file callbacks each return a baton 00770 * for the file being created or changed. This baton can then be 00771 * passed to @c apply_textdelta or @c apply_textdelta_stream to change 00772 * the file's contents, or @c change_file_prop to change the file's 00773 * properties. When the producer is finished making changes to a 00774 * file, it should call @c close_file, to let the consumer clean up 00775 * and free the baton. 00776 * 00777 * The @c add_file and @c add_directory functions each take arguments 00778 * @a copyfrom_path and @a copyfrom_revision. If @a copyfrom_path is 00779 * non-@c NULL, then @a copyfrom_path and @a copyfrom_revision indicate where 00780 * the file or directory should be copied from (to create the file 00781 * or directory being added). In that case, @a copyfrom_path must be 00782 * either a path relative to the root of the edit, or a URI from the 00783 * repository being edited. If @a copyfrom_path is @c NULL, then @a 00784 * copyfrom_revision must be #SVN_INVALID_REVNUM; it is invalid to 00785 * pass a mix of valid and invalid copyfrom arguments. 00786 * 00787 * 00788 * <h3>Function Call Ordering</h3> 00789 * 00790 * There are six restrictions on the order in which the producer 00791 * may use the batons: 00792 * 00793 * 1. The producer may call @c open_directory, @c add_directory, 00794 * @c open_file, @c add_file at most once on any given directory 00795 * entry. @c delete_entry may be called at most once on any given 00796 * directory entry and may later be followed by @c add_directory or 00797 * @c add_file on the same directory entry. @c delete_entry may 00798 * not be called on any directory entry after @c open_directory, 00799 * @c add_directory, @c open_file or @c add_file has been called on 00800 * that directory entry. 00801 * 00802 * 2. The producer may not close a directory baton until it has 00803 * closed all batons for its subdirectories. 00804 * 00805 * 3. When a producer calls @c open_directory or @c add_directory, 00806 * it must specify the most recently opened of the currently open 00807 * directory batons. Put another way, the producer cannot have 00808 * two sibling directory batons open at the same time. 00809 * 00810 * 4. A producer must call @c change_dir_prop on a directory either 00811 * before opening any of the directory's subdirs or after closing 00812 * them, but not in the middle. 00813 * 00814 * 5. When the producer calls @c open_file or @c add_file, either: 00815 * 00816 * (a) The producer must follow with any changes to the file 00817 * (@c change_file_prop and/or @c apply_textdelta / 00818 * @c apply_textdelta_stream, as applicable), followed by 00819 * a @c close_file call, before issuing any other file or 00820 * directory calls, or 00821 * 00822 * (b) The producer must follow with a @c change_file_prop call if 00823 * it is applicable, before issuing any other file or directory 00824 * calls; later, after all directory batons including the root 00825 * have been closed, the producer must issue @c apply_textdelta / 00826 * @c apply_textdelta_stream and @c close_file calls. 00827 * 00828 * 6. When the producer calls @c apply_textdelta, it must make all of 00829 * the window handler calls (including the @c NULL window at the 00830 * end) before issuing any other #svn_delta_editor_t calls. 00831 * 00832 * So, the producer needs to use directory and file batons as if it 00833 * is doing a single depth-first traversal of the tree, with the 00834 * exception that the producer may keep file batons open in order to 00835 * make @c apply_textdelta / @c apply_textdelta_stream calls at the end. 00836 * 00837 * 00838 * <h3>Pool Usage</h3> 00839 * 00840 * Many editor functions are invoked multiple times, in a sequence 00841 * determined by the editor "driver". The driver is responsible for 00842 * creating a pool for use on each iteration of the editor function, 00843 * and clearing that pool between each iteration. The driver passes 00844 * the appropriate pool on each function invocation. 00845 * 00846 * Based on the requirement of calling the editor functions in a 00847 * depth-first style, it is usually customary for the driver to similarly 00848 * nest the pools. However, this is only a safety feature to ensure 00849 * that pools associated with deeper items are always cleared when the 00850 * top-level items are also cleared. The interface does not assume, nor 00851 * require, any particular organization of the pools passed to these 00852 * functions. In fact, if "postfix deltas" are used for files, the file 00853 * pools definitely need to live outside the scope of their parent 00854 * directories' pools. 00855 * 00856 * Note that close_directory can be called *before* a file in that 00857 * directory has been closed. That is, the directory's baton is 00858 * closed before the file's baton. The implication is that 00859 * @c apply_textdelta / @c apply_textdelta_stream and @c close_file 00860 * should not refer to a parent directory baton UNLESS the editor has 00861 * taken precautions to allocate it in a pool of the appropriate 00862 * lifetime (the @a dir_pool passed to @c open_directory and 00863 * @c add_directory definitely does not have the proper lifetime). 00864 * In general, it is recommended to simply avoid keeping a parent 00865 * directory baton in a file baton. 00866 * 00867 * 00868 * <h3>Errors</h3> 00869 * 00870 * At least one implementation of the editor interface is 00871 * asynchronous; an error from one operation may be detected some 00872 * number of operations later. As a result, an editor driver must not 00873 * assume that an error from an editing function resulted from the 00874 * particular operation being detected. Moreover, once an editing 00875 * function (including @c close_edit) returns an error, the edit is 00876 * dead; the only further operation which may be called on the editor 00877 * is @c abort_edit. 00878 */ 00879 typedef struct svn_delta_editor_t 00880 { 00881 /** Set the target revision for this edit to @a target_revision. This 00882 * call, if used, should precede all other editor calls. 00883 * 00884 * @note This is typically used only for server->client update-type 00885 * operations. It doesn't really make much sense for commit-type 00886 * operations, because the revision of a commit isn't known until 00887 * the commit is finalized. 00888 * 00889 * Any temporary allocations may be performed in @a scratch_pool. 00890 */ 00891 svn_error_t *(*set_target_revision)(void *edit_baton, 00892 svn_revnum_t target_revision, 00893 apr_pool_t *scratch_pool); 00894 00895 /** Set @a *root_baton to a baton for the top directory of the change. 00896 * (This is the top of the subtree being changed, not necessarily 00897 * the root of the filesystem.) As with any other directory baton, the 00898 * producer should call @c close_directory on @a root_baton when done. 00899 * And as with other @c open_* calls, the @a base_revision here is the 00900 * current revision of the directory (before getting bumped up to the 00901 * new target revision set with @c set_target_revision). 00902 * 00903 * Allocations for the returned @a root_baton should be performed in 00904 * @a result_pool. It is also typical to (possibly) save this pool for 00905 * later usage by @c close_directory. 00906 */ 00907 svn_error_t *(*open_root)(void *edit_baton, 00908 svn_revnum_t base_revision, 00909 apr_pool_t *result_pool, 00910 void **root_baton); 00911 00912 00913 /** Remove the directory entry at @a path, a child of the directory 00914 * represented by @a parent_baton. If @a revision is a valid 00915 * revision number, it is used as a sanity check to ensure that you 00916 * are really removing the revision of @a path that you think you are. 00917 * 00918 * Any temporary allocations may be performed in @a scratch_pool. 00919 * 00920 * @note The @a revision parameter is typically used only for 00921 * client->server commit-type operations, allowing the server to 00922 * verify that it is deleting what the client thinks it should be 00923 * deleting. It only really makes sense in the opposite direction 00924 * (during server->client update-type operations) when the trees 00925 * whose delta is being described are ancestrally related (that is, 00926 * one tree is an ancestor of the other). 00927 */ 00928 svn_error_t *(*delete_entry)(const char *path, 00929 svn_revnum_t revision, 00930 void *parent_baton, 00931 apr_pool_t *scratch_pool); 00932 00933 00934 /** We are going to add a new subdirectory at @a path, a child of 00935 * the directory represented by @a parent_baton. We will use 00936 * the value this callback stores in @a *child_baton as the 00937 * parent baton for further changes in the new subdirectory. 00938 * 00939 * If @a copyfrom_path is non-@c NULL, this add has history (i.e., is a 00940 * copy), and the origin of the copy may be recorded as 00941 * @a copyfrom_path under @a copyfrom_revision. 00942 * 00943 * Allocations for the returned @a child_baton should be performed in 00944 * @a result_pool. It is also typical to (possibly) save this pool for 00945 * later usage by @c close_directory. 00946 */ 00947 svn_error_t *(*add_directory)(const char *path, 00948 void *parent_baton, 00949 const char *copyfrom_path, 00950 svn_revnum_t copyfrom_revision, 00951 apr_pool_t *result_pool, 00952 void **child_baton); 00953 00954 /** We are going to make changes in the subdirectory at @a path, a 00955 * child of the directory represented by @a parent_baton. 00956 * The callback must store a value in @a *child_baton that 00957 * should be used as the parent baton for subsequent changes in this 00958 * subdirectory. If a valid revnum, @a base_revision is the current 00959 * revision of the subdirectory. 00960 * 00961 * Allocations for the returned @a child_baton should be performed in 00962 * @a result_pool. It is also typical to (possibly) save this pool for 00963 * later usage by @c close_directory. 00964 */ 00965 svn_error_t *(*open_directory)(const char *path, 00966 void *parent_baton, 00967 svn_revnum_t base_revision, 00968 apr_pool_t *result_pool, 00969 void **child_baton); 00970 00971 /** Change the value of a directory's property. 00972 * - @a dir_baton specifies the directory whose property should change. 00973 * - @a name is the name of the property to change. 00974 * - @a value is the new (final) value of the property, or @c NULL if the 00975 * property should be removed altogether. 00976 * 00977 * The callback is guaranteed to be called exactly once for each property 00978 * whose value differs between the start and the end of the edit. 00979 * 00980 * Any temporary allocations may be performed in @a scratch_pool. 00981 */ 00982 svn_error_t *(*change_dir_prop)(void *dir_baton, 00983 const char *name, 00984 const svn_string_t *value, 00985 apr_pool_t *scratch_pool); 00986 00987 /** We are done processing a subdirectory, whose baton is @a dir_baton 00988 * (set by @c add_directory or @c open_directory). We won't be using 00989 * the baton any more, so whatever resources it refers to may now be 00990 * freed. 00991 * 00992 * Any temporary allocations may be performed in @a scratch_pool. 00993 */ 00994 svn_error_t *(*close_directory)(void *dir_baton, 00995 apr_pool_t *scratch_pool); 00996 00997 00998 /** In the directory represented by @a parent_baton, indicate that 00999 * @a path is present as a subdirectory in the edit source, but 01000 * cannot be conveyed to the edit consumer. Currently, this would 01001 * only occur because of authorization restrictions, but may change 01002 * in the future. 01003 * 01004 * Any temporary allocations may be performed in @a scratch_pool. 01005 */ 01006 svn_error_t *(*absent_directory)(const char *path, 01007 void *parent_baton, 01008 apr_pool_t *scratch_pool); 01009 01010 /** We are going to add a new file at @a path, a child of the 01011 * directory represented by @a parent_baton. The callback can 01012 * store a baton for this new file in @a **file_baton; whatever value 01013 * it stores there should be passed through to @c apply_textdelta or 01014 * @c apply_textdelta_stream. 01015 * 01016 * If @a copyfrom_path is non-@c NULL, this add has history (i.e., is a 01017 * copy), and the origin of the copy may be recorded as 01018 * @a copyfrom_path under @a copyfrom_revision. 01019 * 01020 * Allocations for the returned @a file_baton should be performed in 01021 * @a result_pool. It is also typical to save this pool for later usage 01022 * by @c apply_textdelta and possibly @c close_file. 01023 * 01024 * @note Because the editor driver could be employing the "postfix 01025 * deltas" paradigm, @a result_pool could potentially be relatively 01026 * long-lived. Every file baton created by the editor for a given 01027 * editor drive might be resident in memory similtaneously. Editor 01028 * implementations should ideally keep their file batons as 01029 * conservative (memory-usage-wise) as possible, and use @a result_pool 01030 * only for those batons. (Consider using a subpool of @a result_pool 01031 * for scratch work, destroying the subpool before exiting this 01032 * function's implementation.) 01033 */ 01034 svn_error_t *(*add_file)(const char *path, 01035 void *parent_baton, 01036 const char *copyfrom_path, 01037 svn_revnum_t copyfrom_revision, 01038 apr_pool_t *result_pool, 01039 void **file_baton); 01040 01041 /** We are going to make changes to a file at @a path, a child of the 01042 * directory represented by @a parent_baton. 01043 * 01044 * The callback can store a baton for this new file in @a **file_baton; 01045 * whatever value it stores there should be passed through to 01046 * @c apply_textdelta or @c apply_textdelta_stream. If a valid revnum, 01047 * @a base_revision is the current revision of the file. 01048 * 01049 * Allocations for the returned @a file_baton should be performed in 01050 * @a result_pool. It is also typical to save this pool for later usage 01051 * by @c apply_textdelta and possibly @c close_file. 01052 * 01053 * @note See note about memory usage on @a add_file, which also 01054 * applies here. 01055 */ 01056 svn_error_t *(*open_file)(const char *path, 01057 void *parent_baton, 01058 svn_revnum_t base_revision, 01059 apr_pool_t *result_pool, 01060 void **file_baton); 01061 01062 /** Apply a text delta, yielding the new revision of a file. 01063 * 01064 * @a file_baton indicates the file we're creating or updating, and the 01065 * ancestor file on which it is based; it is the baton set by some 01066 * prior @c add_file or @c open_file callback. 01067 * 01068 * The callback should set @a *handler to a text delta window 01069 * handler; we will then call @a *handler on successive text 01070 * delta windows as we receive them. The callback should set 01071 * @a *handler_baton to the value we should pass as the @a baton 01072 * argument to @a *handler. These values should be allocated within 01073 * @a result_pool. 01074 * 01075 * @a base_checksum is the hex MD5 digest for the base text against 01076 * which the delta is being applied; it is ignored if NULL, and may 01077 * be ignored even if not NULL. If it is not ignored, it must match 01078 * the checksum of the base text against which svndiff data is being 01079 * applied; if it does not, @c apply_textdelta or the @a *handler call 01080 * which detects the mismatch will return the error 01081 * SVN_ERR_CHECKSUM_MISMATCH (if there is no base text, there may 01082 * still be an error if @a base_checksum is neither NULL nor the hex 01083 * MD5 checksum of the empty string). 01084 */ 01085 svn_error_t *(*apply_textdelta)(void *file_baton, 01086 const char *base_checksum, 01087 apr_pool_t *result_pool, 01088 svn_txdelta_window_handler_t *handler, 01089 void **handler_baton); 01090 01091 /** Change the value of a file's property. 01092 * - @a file_baton specifies the file whose property should change. 01093 * - @a name is the name of the property to change. 01094 * - @a value is the new (final) value of the property, or @c NULL if the 01095 * property should be removed altogether. 01096 * 01097 * The callback is guaranteed to be called exactly once for each property 01098 * whose value differs between the start and the end of the edit. 01099 * 01100 * Any temporary allocations may be performed in @a scratch_pool. 01101 */ 01102 svn_error_t *(*change_file_prop)(void *file_baton, 01103 const char *name, 01104 const svn_string_t *value, 01105 apr_pool_t *scratch_pool); 01106 01107 /** We are done processing a file, whose baton is @a file_baton (set by 01108 * @c add_file or @c open_file). We won't be using the baton any 01109 * more, so whatever resources it refers to may now be freed. 01110 * 01111 * @a text_checksum is the hex MD5 digest for the fulltext that 01112 * resulted from a delta application, see @c apply_textdelta and 01113 * @c apply_textdelta_stream. The checksum is ignored if NULL. 01114 * If not null, it is compared to the checksum of the new fulltext, 01115 * and the error SVN_ERR_CHECKSUM_MISMATCH is returned if they do 01116 * not match. If there is no new fulltext, @a text_checksum is ignored. 01117 * 01118 * Any temporary allocations may be performed in @a scratch_pool. 01119 */ 01120 svn_error_t *(*close_file)(void *file_baton, 01121 const char *text_checksum, 01122 apr_pool_t *scratch_pool); 01123 01124 /** In the directory represented by @a parent_baton, indicate that 01125 * @a path is present as a file in the edit source, but cannot be 01126 * cannot be conveyed to the edit consumer. Currently, this would 01127 * only occur because of authorization restrictions, but may change 01128 * in the future. 01129 * 01130 * Any temporary allocations may be performed in @a scratch_pool. 01131 */ 01132 svn_error_t *(*absent_file)(const char *path, 01133 void *parent_baton, 01134 apr_pool_t *scratch_pool); 01135 01136 /** All delta processing is done. Call this, with the @a edit_baton for 01137 * the entire edit. 01138 * 01139 * Any temporary allocations may be performed in @a scratch_pool. 01140 */ 01141 svn_error_t *(*close_edit)(void *edit_baton, 01142 apr_pool_t *scratch_pool); 01143 01144 /** The editor-driver has decided to bail out. Allow the editor to 01145 * gracefully clean up things if it needs to. 01146 * 01147 * Any temporary allocations may be performed in @a scratch_pool. 01148 */ 01149 svn_error_t *(*abort_edit)(void *edit_baton, 01150 apr_pool_t *scratch_pool); 01151 01152 /** Apply a text delta stream, yielding the new revision of a file. 01153 * This callback operates on the passed-in @a editor instance. 01154 * 01155 * @a file_baton indicates the file we're creating or updating, and the 01156 * ancestor file on which it is based; it is the baton set by some 01157 * prior @c add_file or @c open_file callback. 01158 * 01159 * @a open_func is a function that opens a #svn_txdelta_stream_t object. 01160 * @a open_baton is provided by the caller. 01161 * 01162 * @a base_checksum is the hex MD5 digest for the base text against 01163 * which the delta is being applied; it is ignored if NULL, and may 01164 * be ignored even if not NULL. If it is not ignored, it must match 01165 * the checksum of the base text against which svndiff data is being 01166 * applied; if it does not, @c apply_textdelta_stream call which detects 01167 * the mismatch will return the error #SVN_ERR_CHECKSUM_MISMATCH 01168 * (if there is no base text, there may still be an error if 01169 * @a base_checksum is neither NULL nor the hex MD5 checksum of the 01170 * empty string). 01171 * 01172 * Any temporary allocations may be performed in @a scratch_pool. 01173 * 01174 * @since New in 1.10. 01175 */ 01176 svn_error_t *(*apply_textdelta_stream)( 01177 const struct svn_delta_editor_t *editor, 01178 void *file_baton, 01179 const char *base_checksum, 01180 svn_txdelta_stream_open_func_t open_func, 01181 void *open_baton, 01182 apr_pool_t *scratch_pool); 01183 01184 /* Be sure to update svn_delta_get_cancellation_editor() and 01185 * svn_delta_default_editor() if you add a new callback here. */ 01186 } svn_delta_editor_t; 01187 01188 01189 /** Return a default delta editor template, allocated in @a pool. 01190 * 01191 * The editor functions in the template do only the most basic 01192 * baton-swapping: each editor function that produces a baton does so 01193 * by copying its incoming baton into the outgoing baton reference. 01194 * 01195 * This editor is not intended to be useful by itself, but is meant to 01196 * be the basis for a useful editor. After getting a default editor, 01197 * you substitute in your own implementations for the editor functions 01198 * you care about. The ones you don't care about, you don't have to 01199 * implement -- you can rely on the template's implementation to 01200 * safely do nothing of consequence. 01201 */ 01202 svn_delta_editor_t * 01203 svn_delta_default_editor(apr_pool_t *pool); 01204 01205 /** A text-delta window handler which does nothing. 01206 * 01207 * Editors can return this handler from @c apply_textdelta if they don't 01208 * care about text delta windows. 01209 */ 01210 svn_error_t * 01211 svn_delta_noop_window_handler(svn_txdelta_window_t *window, 01212 void *baton); 01213 01214 /** Set @a *editor and @a *edit_baton to a cancellation editor that 01215 * wraps @a wrapped_editor and @a wrapped_baton. 01216 * 01217 * The @a editor will call @a cancel_func with @a cancel_baton when each of 01218 * its functions is called, continuing on to call the corresponding wrapped 01219 * function if @a cancel_func returns #SVN_NO_ERROR. 01220 * 01221 * If @a cancel_func is @c NULL, set @a *editor to @a wrapped_editor and 01222 * @a *edit_baton to @a wrapped_baton. 01223 */ 01224 svn_error_t * 01225 svn_delta_get_cancellation_editor(svn_cancel_func_t cancel_func, 01226 void *cancel_baton, 01227 const svn_delta_editor_t *wrapped_editor, 01228 void *wrapped_baton, 01229 const svn_delta_editor_t **editor, 01230 void **edit_baton, 01231 apr_pool_t *pool); 01232 01233 /** Set @a *editor and @a *edit_baton to an depth-based filtering 01234 * editor that wraps @a wrapped_editor and @a wrapped_baton. 01235 * 01236 * The @a editor will track the depth of this drive against the @a 01237 * requested_depth, taking into account whether not the edit drive is 01238 * making use of a target (via @a has_target), and forward editor 01239 * calls which operate "within" the request depth range through to @a 01240 * wrapped_editor. 01241 * 01242 * @a requested_depth must be one of the following depth values: 01243 * #svn_depth_infinity, #svn_depth_empty, #svn_depth_files, 01244 * #svn_depth_immediates, or #svn_depth_unknown. 01245 * 01246 * If filtering is deemed unnecessary (or if @a requested_depth is 01247 * #svn_depth_unknown), @a *editor and @a *edit_baton will be set to @a 01248 * wrapped_editor and @a wrapped_baton, respectively; otherwise, 01249 * they'll be set to new objects allocated from @a pool. 01250 * 01251 * @note Because the svn_delta_editor_t interface's @c delete_entry() 01252 * function doesn't carry node kind information, a depth-based 01253 * filtering editor being asked to filter for #svn_depth_files but 01254 * receiving a @c delete_entry() call on an immediate child of the 01255 * editor's target is unable to know if that deletion should be 01256 * allowed or filtered out -- a delete of a top-level file is okay in 01257 * this case, a delete of a top-level subdirectory is not. As such, 01258 * this filtering editor takes a conservative approach, and ignores 01259 * top-level deletion requests when filtering for #svn_depth_files. 01260 * Fortunately, most non-depth-aware (pre-1.5) Subversion editor 01261 * drivers can be told to drive non-recursively (where non-recursive 01262 * means essentially #svn_depth_files), which means they won't 01263 * transmit out-of-scope editor commands anyway. 01264 * 01265 * @since New in 1.5. 01266 */ 01267 svn_error_t * 01268 svn_delta_depth_filter_editor(const svn_delta_editor_t **editor, 01269 void **edit_baton, 01270 const svn_delta_editor_t *wrapped_editor, 01271 void *wrapped_edit_baton, 01272 svn_depth_t requested_depth, 01273 svn_boolean_t has_target, 01274 apr_pool_t *pool); 01275 01276 /** @} */ 01277 01278 01279 /** Path-based editor drives. 01280 * 01281 * @defgroup svn_delta_path_delta_drivers Path-based delta drivers 01282 * @{ 01283 */ 01284 01285 /** Callback function type for svn_delta_path_driver(). 01286 * 01287 * The handler of this callback is given the callback baton @a 01288 * callback_baton, @a path which is a relpath relative to the 01289 * root of the edit, and the @a parent_baton which represents 01290 * path's parent directory as created by the editor passed to 01291 * svn_delta_path_driver(). 01292 * 01293 * If @a path represents a directory, the handler must return a @a 01294 * *dir_baton for @a path, generated from the same editor (so that the 01295 * driver can later close that directory). 01296 * 01297 * If, however, @a path represents a file, the handler should NOT 01298 * return any file batons. It can close any opened or added files 01299 * immediately, or delay that close until the end of the edit when 01300 * svn_delta_path_driver() returns. 01301 * 01302 * Finally, if @a parent_baton is @c NULL, then the root of the edit 01303 * is also one of the paths passed to svn_delta_path_driver(). The 01304 * handler of this callback must call the editor's open_root() 01305 * function and return the top-level root dir baton in @a *dir_baton. 01306 */ 01307 typedef svn_error_t *(*svn_delta_path_driver_cb_func_t)( 01308 void **dir_baton, 01309 void *parent_baton, 01310 void *callback_baton, 01311 const char *path, 01312 apr_pool_t *pool); 01313 01314 01315 /** Drive @a editor (with its @a edit_baton) to visit each path in @a paths. 01316 * As each path is hit as part of the editor drive, use 01317 * @a callback_func and @a callback_baton to allow the caller to handle 01318 * the portion of the editor drive related to that path. 01319 * 01320 * Each path in @a paths is a (const char *) relpath, relative 01321 * to the root path of the @a edit. The editor drive will be 01322 * performed in the same order as @a paths. The paths should be sorted 01323 * using something like svn_sort_compare_paths to ensure that a depth-first 01324 * pattern is observed for directory/file baton creation. If @a sort_paths 01325 * is set, the function will sort the paths for you. Some callers may need 01326 * further customization of the order (ie. libsvn_delta/compat.c). 01327 * 01328 * Use @a scratch_pool for all necessary allocations. 01329 * 01330 * @since New in 1.8. 01331 */ 01332 svn_error_t * 01333 svn_delta_path_driver2(const svn_delta_editor_t *editor, 01334 void *edit_baton, 01335 const apr_array_header_t *paths, 01336 svn_boolean_t sort_paths, 01337 svn_delta_path_driver_cb_func_t callback_func, 01338 void *callback_baton, 01339 apr_pool_t *scratch_pool); 01340 01341 01342 /** Similar to svn_delta_path_driver2, but takes an (unused) revision, 01343 * and will sort the provided @a paths using svn_sort_compare_paths. 01344 * 01345 * @note In versions prior to 1.8, this function would modify the order 01346 * of elements in @a paths, despite the 'const' marker on the parameter. 01347 * This has been fixed in 1.8. 01348 * 01349 * @deprecated Provided for backward compatibility with the 1.7 API. 01350 */ 01351 SVN_DEPRECATED 01352 svn_error_t * 01353 svn_delta_path_driver(const svn_delta_editor_t *editor, 01354 void *edit_baton, 01355 svn_revnum_t revision, 01356 const apr_array_header_t *paths, 01357 svn_delta_path_driver_cb_func_t callback_func, 01358 void *callback_baton, 01359 apr_pool_t *scratch_pool); 01360 01361 /** @} */ 01362 01363 01364 /*** File revision iterator types ***/ 01365 01366 /** 01367 * The callback invoked by file rev loopers, such as 01368 * svn_ra_plugin_t.get_file_revs2() and svn_repos_get_file_revs2(). 01369 * 01370 * @a baton is provided by the caller, @a path is the pathname of the file 01371 * in revision @a rev and @a rev_props are the revision properties. 01372 * 01373 * If @a delta_handler and @a delta_baton are non-NULL, they may be set to a 01374 * handler/baton which will be called with the delta between the previous 01375 * revision and this one after the return of this callback. They may be 01376 * left as NULL/NULL. 01377 * 01378 * @a result_of_merge will be @c TRUE if the revision being returned was 01379 * included as the result of a merge. 01380 * 01381 * @a prop_diffs is an array of svn_prop_t elements indicating the property 01382 * delta for this and the previous revision. 01383 * 01384 * @a pool may be used for temporary allocations, but you can't rely 01385 * on objects allocated to live outside of this particular call and 01386 * the immediately following calls to @a *delta_handler if any. (Pass 01387 * in a pool via @a baton if need be.) 01388 * 01389 * @since New in 1.5. 01390 */ 01391 typedef svn_error_t *(*svn_file_rev_handler_t)( 01392 void *baton, 01393 const char *path, 01394 svn_revnum_t rev, 01395 apr_hash_t *rev_props, 01396 svn_boolean_t result_of_merge, 01397 svn_txdelta_window_handler_t *delta_handler, 01398 void **delta_baton, 01399 apr_array_header_t *prop_diffs, 01400 apr_pool_t *pool); 01401 01402 /** 01403 * The old file rev handler interface. 01404 * 01405 * @note #svn_file_rev_handler_old_t is a placeholder type for both 01406 * #svn_repos_file_rev_handler_t and #svn_ra_file_rev_handler_t. It is 01407 * reproduced here for dependency reasons. 01408 * 01409 * @deprecated This type is provided for the svn_compat_wrap_file_rev_handler() 01410 * compatibility wrapper, and should not be used for new development. 01411 * @since New in 1.5. 01412 */ 01413 typedef svn_error_t *(*svn_file_rev_handler_old_t)( 01414 void *baton, 01415 const char *path, 01416 svn_revnum_t rev, 01417 apr_hash_t *rev_props, 01418 svn_txdelta_window_handler_t *delta_handler, 01419 void **delta_baton, 01420 apr_array_header_t *prop_diffs, 01421 apr_pool_t *pool); 01422 01423 /** Return, in @a *handler2 and @a *handler2_baton a function/baton that 01424 * will call @a handler/@a handler_baton, allocating the @a *handler2_baton 01425 * in @a pool. 01426 * 01427 * @note This is used by compatibility wrappers, which exist in more than 01428 * Subversion core library. 01429 * 01430 * @note #svn_file_rev_handler_old_t is a placeholder type for both 01431 * #svn_repos_file_rev_handler_t and #svn_ra_file_rev_handler_t. It is 01432 * reproduced here for dependency reasons. 01433 * 01434 * @since New in 1.5. 01435 */ 01436 void 01437 svn_compat_wrap_file_rev_handler(svn_file_rev_handler_t *handler2, 01438 void **handler2_baton, 01439 svn_file_rev_handler_old_t handler, 01440 void *handler_baton, 01441 apr_pool_t *pool); 01442 01443 /** @} end group: delta_support */ 01444 01445 01446 #ifdef __cplusplus 01447 } 01448 #endif /* __cplusplus */ 01449 01450 #endif /* SVN_DELTA_H */
1.6.1