FreeBSD/contrib/subversion/subversion/libsvn_fs_fs/cached_data.c
/* Skip forwards to THIS_CHUNK in REP_STATE and then read the next delta
   window into *NWIN.  Note that RS->CHUNK_INDEX will be THIS_CHUNK rather
   than THIS_CHUNK + 1 when this function returns. */
Skip forwards to THIS_CHUNK in REP_STATE and then read the next delta
window into *NWIN.  Note that RS->CHUNK_INDEX will be THIS_CHUNK rather
than THIS_CHUNK + 1 when this function returns.
Skip forwards to THIS_CHUNK in REP_STATE and then read the next delta window into * NWIN . Note that RS - > CHUNK_INDEX will be THIS_CHUNK rather than THIS_CHUNK + 1 when this function returns .
static svn_error_t *
read_delta_window(svn_txdelta_window_t **nwin, int this_chunk,
                  rep_state_t *rs, apr_pool_t *result_pool,
                  apr_pool_t *scratch_pool)
{
  svn_boolean_t is_cached;
  apr_off_t start_offset;
  apr_off_t end_offset;
  apr_pool_t *iterpool;
  SVN_ERR_ASSERT(rs->chunk_index <= this_chunk);
  SVN_ERR(dbg_log_access(rs->sfile->fs, rs->revision, rs->item_index,
                         NULL, SVN_FS_FS__ITEM_TYPE_ANY_REP, scratch_pool));
  SVN_ERR(get_cached_window(nwin, rs, this_chunk, &is_cached,
                            result_pool, scratch_pool));
  if (is_cached)
    return SVN_NO_ERROR;
  SVN_ERR(auto_open_shared_file(rs->sfile));
  if (   rs->chunk_index == 0
      && SVN_IS_VALID_REVNUM(rs->revision)
      && use_block_read(rs->sfile->fs)
      && rs->raw_window_cache)
    {
      SVN_ERR(block_read(NULL, rs->sfile->fs, rs->revision, rs->item_index,
                         rs->sfile->rfile, result_pool, scratch_pool));
      SVN_ERR(get_cached_window(nwin, rs, this_chunk, &is_cached,
                                result_pool, scratch_pool));
      if (is_cached)
        return SVN_NO_ERROR;
    }
  SVN_ERR(auto_set_start_offset(rs, scratch_pool));
  SVN_ERR(auto_read_diff_version(rs, scratch_pool));
  start_offset = rs->start + rs->current;
  SVN_ERR(rs_aligned_seek(rs, NULL, start_offset, scratch_pool));
  iterpool = svn_pool_create(scratch_pool);
  while (rs->chunk_index < this_chunk)
    {
      svn_pool_clear(iterpool);
      SVN_ERR(svn_txdelta_skip_svndiff_window(rs->sfile->rfile->file,
                                              rs->ver, iterpool));
      rs->chunk_index++;
      SVN_ERR(get_file_offset(&start_offset, rs, iterpool));
      rs->current = start_offset - rs->start;
      if (rs->current >= rs->size)
        return svn_error_create(SVN_ERR_FS_CORRUPT, NULL,
                                _("Reading one svndiff window read "
                                  "beyond the end of the "
                                  "representation"));
    }
  svn_pool_destroy(iterpool);
  SVN_ERR(svn_txdelta_read_svndiff_window(nwin, rs->sfile->rfile->stream,
                                          rs->ver, result_pool));
  SVN_ERR(get_file_offset(&end_offset, rs, scratch_pool));
  rs->current = end_offset - rs->start;
  if (rs->current > rs->size)
    return svn_error_create(SVN_ERR_FS_CORRUPT, NULL,
                            _("Reading one svndiff window read beyond "
                              "the end of the representation"));
  if (SVN_IS_VALID_REVNUM(rs->revision))
    SVN_ERR(set_cached_window(*nwin, rs, scratch_pool));
  return SVN_NO_ERROR;
}
static svn_error_t * read_delta_window ( svn_txdelta_window_t * * nwin , int this_chunk , rep_state_t * rs , apr_pool_t * result_pool , apr_pool_t * scratch_pool ) { svn_boolean_t is_cached ; apr_off_t start_offset ; apr_off_t end_offset ; apr_pool_t * iterpool ; SVN_ERR_ASSERT ( rs -> chunk_index <= this_chunk ) ; SVN_ERR ( dbg_log_access ( rs -> sfile -> fs , rs -> revision , rs -> item_index , NULL , SVN_FS_FS__ITEM_TYPE_ANY_REP , scratch_pool ) ) ; SVN_ERR ( get_cached_window ( nwin , rs , this_chunk , & is_cached , result_pool , scratch_pool ) ) ; if ( is_cached ) return SVN_NO_ERROR ; SVN_ERR ( auto_open_shared_file ( rs -> sfile ) ) ; if ( rs -> chunk_index == 0 && SVN_IS_VALID_REVNUM ( rs -> revision ) && use_block_read ( rs -> sfile -> fs ) && rs -> raw_window_cache ) { SVN_ERR ( block_read ( NULL , rs -> sfile -> fs , rs -> revision , rs -> item_index , rs -> sfile -> rfile , result_pool , scratch_pool ) ) ; SVN_ERR ( get_cached_window ( nwin , rs , this_chunk , & is_cached , result_pool , scratch_pool ) ) ; if ( is_cached ) return SVN_NO_ERROR ; } SVN_ERR ( auto_set_start_offset ( rs , scratch_pool ) ) ; SVN_ERR ( auto_read_diff_version ( rs , scratch_pool ) ) ; start_offset = rs -> start + rs -> current ; SVN_ERR ( rs_aligned_seek ( rs , NULL , start_offset , scratch_pool ) ) ; iterpool = svn_pool_create ( scratch_pool ) ; while ( rs -> chunk_index < this_chunk ) { svn_pool_clear ( iterpool ) ; SVN_ERR ( svn_txdelta_skip_svndiff_window ( rs -> sfile -> rfile -> file , rs -> ver , iterpool ) ) ; rs -> chunk_index ++ ; SVN_ERR ( get_file_offset ( & start_offset , rs , iterpool ) ) ; rs -> current = start_offset - rs -> start ; if ( rs -> current >= rs -> size ) return svn_error_create ( SVN_ERR_FS_CORRUPT , NULL , _ ( " " " " " " ) ) ; } svn_pool_destroy ( iterpool ) ; SVN_ERR ( svn_txdelta_read_svndiff_window ( nwin , rs -> sfile -> rfile -> stream , rs -> ver , result_pool ) ) ; SVN_ERR ( get_file_offset ( & end_offset , rs , scratch_pool ) ) ; rs -> current = end_offset - rs -> start ; if ( rs -> current > rs -> size ) return svn_error_create ( SVN_ERR_FS_CORRUPT , NULL , _ ( " " " " ) ) ; if ( SVN_IS_VALID_REVNUM ( rs -> revision ) ) SVN_ERR ( set_cached_window ( * nwin , rs , scratch_pool ) ) ; return SVN_NO_ERROR ; }
Skip forwards to THIS_CHUNK in REP_STATE and then read the next delta
window into *NWIN.
Skip forwards to THIS_CHUNK in REP_STATE and then read the next delta window into * NWIN .
/* Read the next window.  But first, try to find it in the cache. */ /* someone has to actually read the data from file.  Open it */ /* invoke the 'block-read' feature for non-txn data.
     However, don't do that if we are in the middle of some representation,
     because the block is unlikely to contain other data. */ /* reading the whole block probably also provided us with the
         desired txdelta window */ /* data is still not cached -> we need to read it.
     Make sure we have all the necessary info. */ /* RS->FILE may be shared between RS instances -> make sure we point
   * to the right data. */ /* Skip windows to reach the current chunk if we aren't there yet. */ /* Actually read the next window. */ /* the window has not been cached before, thus cache it now
   * (if caching is used for them at all) */