void svn_txdelta__apply_instructions(svn_txdelta_window_t *window, const char *sbuf, char *tbuf, apr_size_t *tlen) { svn_txdelta_apply_instructions(window, sbuf, tbuf, tlen); }
/* Apply WINDOW to the streams given by APPL. */ static svn_error_t * apply_window(svn_txdelta_window_t *window, void *baton) { struct apply_baton *ab = (struct apply_baton *) baton; apr_size_t len; svn_error_t *err; if (window == NULL) { /* We're done; just clean up. */ if (ab->result_digest) apr_md5_final(ab->result_digest, &(ab->md5_context)); err = svn_stream_close(ab->target); svn_pool_destroy(ab->pool); return err; } /* Make sure the source view didn't slide backwards. */ SVN_ERR_ASSERT(window->sview_len == 0 || (window->sview_offset >= ab->sbuf_offset && (window->sview_offset + window->sview_len >= ab->sbuf_offset + ab->sbuf_len))); /* Make sure there's enough room in the target buffer. */ SVN_ERR(size_buffer(&ab->tbuf, &ab->tbuf_size, window->tview_len, ab->pool)); /* Prepare the source buffer for reading from the input stream. */ if (window->sview_offset != ab->sbuf_offset || window->sview_len > ab->sbuf_size) { char *old_sbuf = ab->sbuf; /* Make sure there's enough room. */ SVN_ERR(size_buffer(&ab->sbuf, &ab->sbuf_size, window->sview_len, ab->pool)); /* If the existing view overlaps with the new view, copy the * overlap to the beginning of the new buffer. */ if (ab->sbuf_offset + ab->sbuf_len > window->sview_offset) { apr_size_t start = (apr_size_t)(window->sview_offset - ab->sbuf_offset); memmove(ab->sbuf, old_sbuf + start, ab->sbuf_len - start); ab->sbuf_len -= start; } else ab->sbuf_len = 0; ab->sbuf_offset = window->sview_offset; } /* Read the remainder of the source view into the buffer. */ if (ab->sbuf_len < window->sview_len) { len = window->sview_len - ab->sbuf_len; err = svn_stream_read(ab->source, ab->sbuf + ab->sbuf_len, &len); if (err == SVN_NO_ERROR && len != window->sview_len - ab->sbuf_len) err = svn_error_create(SVN_ERR_INCOMPLETE_DATA, NULL, "Delta source ended unexpectedly"); if (err != SVN_NO_ERROR) return err; ab->sbuf_len = window->sview_len; } /* Apply the window instructions to the source view to generate the target view. */ len = window->tview_len; svn_txdelta_apply_instructions(window, ab->sbuf, ab->tbuf, &len); SVN_ERR_ASSERT(len == window->tview_len); /* Write out the output. */ /* ### We've also considered just adding two (optionally null) arguments to svn_stream_create(): read_checksum and write_checksum. Then instead of every caller updating an md5 context when it calls svn_stream_write() or svn_stream_read(), streams would do it automatically, and verify the checksum in svn_stream_closed(). But this might be overkill for issue #689; so for now we just update the context here. */ if (ab->result_digest) apr_md5_update(&(ab->md5_context), ab->tbuf, len); return svn_stream_write(ab->target, ab->tbuf, &len); }
/* Apply WINDOW to the streams given by APPL. */ static svn_error_t * apply_window(svn_txdelta_window_t *window, void *baton) { struct apply_baton *ab = (struct apply_baton *) baton; apr_size_t len; svn_error_t *err; if (window == NULL) { /* We're done; just clean up. */ if (ab->result_digest) apr_md5_final(ab->result_digest, &(ab->md5_context)); err = svn_stream_close(ab->target); svn_pool_destroy(ab->pool); return err; } /* Make sure the source view didn't slide backwards. */ SVN_ERR_ASSERT(window->sview_len == 0 || (window->sview_offset >= ab->sbuf_offset && (window->sview_offset + window->sview_len >= ab->sbuf_offset + ab->sbuf_len))); /* Make sure there's enough room in the target buffer. */ SVN_ERR(size_buffer(&ab->tbuf, &ab->tbuf_size, window->tview_len, ab->pool)); /* Prepare the source buffer for reading from the input stream. */ if (window->sview_offset != ab->sbuf_offset || window->sview_len > ab->sbuf_size) { char *old_sbuf = ab->sbuf; /* Make sure there's enough room. */ SVN_ERR(size_buffer(&ab->sbuf, &ab->sbuf_size, window->sview_len, ab->pool)); /* If the existing view overlaps with the new view, copy the * overlap to the beginning of the new buffer. */ if ( (apr_size_t)ab->sbuf_offset + ab->sbuf_len > (apr_size_t)window->sview_offset) { apr_size_t start = (apr_size_t)(window->sview_offset - ab->sbuf_offset); memmove(ab->sbuf, old_sbuf + start, ab->sbuf_len - start); ab->sbuf_len -= start; } else ab->sbuf_len = 0; ab->sbuf_offset = window->sview_offset; } /* Read the remainder of the source view into the buffer. */ if (ab->sbuf_len < window->sview_len) { len = window->sview_len - ab->sbuf_len; err = svn_stream_read_full(ab->source, ab->sbuf + ab->sbuf_len, &len); if (err == SVN_NO_ERROR && len != window->sview_len - ab->sbuf_len) err = svn_error_create(SVN_ERR_INCOMPLETE_DATA, NULL, "Delta source ended unexpectedly"); if (err != SVN_NO_ERROR) return err; ab->sbuf_len = window->sview_len; } /* Apply the window instructions to the source view to generate the target view. */ len = window->tview_len; svn_txdelta_apply_instructions(window, ab->sbuf, ab->tbuf, &len); SVN_ERR_ASSERT(len == window->tview_len); /* Write out the output. */ /* Just update the context here. */ if (ab->result_digest) apr_md5_update(&(ab->md5_context), ab->tbuf, len); return svn_stream_write(ab->target, ab->tbuf, &len); }