FreeBSD/contrib/subversion/subversion/libsvn_delta/text_delta.c
/* Apply WINDOW to the streams given by APPL.  */
Apply WINDOW to the streams given by APPL.
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)
    {
      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;
    }
  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)));
  SVN_ERR(size_buffer(&ab->tbuf, &ab->tbuf_size, window->tview_len, ab->pool));
  if (window->sview_offset != ab->sbuf_offset
      || window->sview_len > ab->sbuf_size)
    {
      char *old_sbuf = ab->sbuf;
      SVN_ERR(size_buffer(&ab->sbuf, &ab->sbuf_size, window->sview_len,
              ab->pool));
      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;
    }
  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;
    }
  len = window->tview_len;
  svn_txdelta_apply_instructions(window, ab->sbuf, ab->tbuf, &len);
  SVN_ERR_ASSERT(len == window->tview_len);
  if (ab->result_digest)
    apr_md5_update(&(ab->md5_context), ab->tbuf, len);
  return svn_stream_write(ab->target, ab->tbuf, &len);
}
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 ) { 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 ; } 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 ) ) ) ; SVN_ERR ( size_buffer ( & ab -> tbuf , & ab -> tbuf_size , window -> tview_len , ab -> pool ) ) ; if ( window -> sview_offset != ab -> sbuf_offset || window -> sview_len > ab -> sbuf_size ) { char * old_sbuf = ab -> sbuf ; SVN_ERR ( size_buffer ( & ab -> sbuf , & ab -> sbuf_size , window -> sview_len , ab -> pool ) ) ; 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 ; } 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 , " " ) ; if ( err != SVN_NO_ERROR ) return err ; ab -> sbuf_len = window -> sview_len ; } len = window -> tview_len ; svn_txdelta_apply_instructions ( window , ab -> sbuf , ab -> tbuf , & len ) ; SVN_ERR_ASSERT ( len == window -> tview_len ) ; 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.
Apply WINDOW to the streams given by APPL .
/* We're done; just clean up.  */ /* Make sure the source view didn't slide backwards.  */ /* Make sure there's enough room in the target buffer.  */ /* Prepare the source buffer for reading from the input stream.  */ /* Make sure there's enough room.  */ /* If the existing view overlaps with the new view, copy the
       * overlap to the beginning of the new buffer.  */ /* Read the remainder of the source view into the buffer.  */ /* Apply the window instructions to the source view to generate
     the target view.  */ /* Write out the output. */ /* Just update the context here. */