FreeBSD/contrib/subversion/subversion/libsvn_fs_x/cached_data.c
/* See create_rep_state, which wraps this and adds another error. */
See create_rep_state, which wraps this and adds another error.
See create_rep_state which wraps this and adds another error .
static svn_error_t *
create_rep_state_body(rep_state_t **rep_state,
                      svn_fs_x__rep_header_t **rep_header,
                      shared_file_t **shared_file,
                      svn_fs_x__representation_t *rep,
                      svn_fs_t *fs,
                      apr_pool_t *result_pool,
                      apr_pool_t *scratch_pool)
{
  svn_fs_x__data_t *ffd = fs->fsap_data;
  rep_state_t *rs = apr_pcalloc(result_pool, sizeof(*rs));
  svn_fs_x__rep_header_t *rh;
  svn_boolean_t is_cached = FALSE;
  svn_revnum_t revision = svn_fs_x__get_revnum(rep->id.change_set);
  apr_uint64_t estimated_window_storage;
  svn_boolean_t reuse_shared_file
    =    shared_file && *shared_file && (*shared_file)->rfile
      && SVN_IS_VALID_REVNUM((*shared_file)->revision)
      && (*shared_file)->revision < ffd->min_unpacked_rev
      && revision < ffd->min_unpacked_rev
      && (   ((*shared_file)->revision / ffd->max_files_per_dir)
          == (revision / ffd->max_files_per_dir));
  svn_fs_x__representation_cache_key_t key = { 0 };
  key.revision = revision;
  key.is_packed = revision < ffd->min_unpacked_rev;
  key.item_index = rep->id.number;
  rs->size = rep->size;
  rs->rep_id = rep->id;
  rs->ver = -1;
  rs->start = -1;
  estimated_window_storage
    = 4 * (  (rep->expanded_size ? rep->expanded_size : rep->size)
           + SVN_DELTA_WINDOW_SIZE);
  estimated_window_storage = MIN(estimated_window_storage, APR_SIZE_MAX);
  rs->window_cache =    ffd->txdelta_window_cache
                     && svn_cache__is_cachable(ffd->txdelta_window_cache,
                                       (apr_size_t)estimated_window_storage)
                   ? ffd->txdelta_window_cache
                   : NULL;
  rs->combined_cache =    ffd->combined_window_cache
                       && svn_cache__is_cachable(ffd->combined_window_cache,
                                       (apr_size_t)estimated_window_storage)
                     ? ffd->combined_window_cache
                     : NULL;
  if (ffd->rep_header_cache && SVN_IS_VALID_REVNUM(revision))
    SVN_ERR(svn_cache__get((void **) &rh, &is_cached,
                           ffd->rep_header_cache, &key, result_pool));
  if (reuse_shared_file)
    {
      rs->sfile = *shared_file;
    }
  else
    {
      shared_file_t *file = apr_pcalloc(result_pool, sizeof(*file));
      file->revision = revision;
      file->pool = result_pool;
      file->fs = fs;
      rs->sfile = file;
      if (shared_file)
        *shared_file = file;
    }
  if (!is_cached)
    {
      apr_off_t offset;
      svn_boolean_t in_container = TRUE;
      if (reuse_shared_file)
        {
          rs->sfile = *shared_file;
          SVN_ERR(auto_open_shared_file(rs->sfile));
        }
      else
        {
          SVN_ERR(open_and_seek_representation(&rs->sfile->rfile, fs, rep,
                                               result_pool, scratch_pool));
        }
      if (SVN_IS_VALID_REVNUM(revision))
        {
          apr_uint32_t sub_item;
          SVN_ERR(svn_fs_x__item_offset(&offset, &sub_item, fs,
                                        rs->sfile->rfile, &rep->id,
                                        scratch_pool));
          if (sub_item == 0)
            {
              svn_fs_x__p2l_entry_t *entry;
              SVN_ERR(svn_fs_x__p2l_entry_lookup(&entry, fs, rs->sfile->rfile,
                                                 revision, offset,
                                                 scratch_pool, scratch_pool));
              in_container = entry->type == SVN_FS_X__ITEM_TYPE_REPS_CONT;
            }
          if (in_container)
            {
              *rep_header = apr_pcalloc(result_pool, sizeof(**rep_header));
              (*rep_header)->type = svn_fs_x__rep_container;
              *rep_state = rs;
              return SVN_NO_ERROR;
            }
          SVN_ERR(rs_aligned_seek(rs, NULL, offset, scratch_pool));
        }
      SVN_ERR(svn_fs_x__read_rep_header(&rh, rs->sfile->rfile->stream,
                                        result_pool, scratch_pool));
      SVN_ERR(get_file_offset(&rs->start, rs, result_pool));
      if (SVN_IS_VALID_REVNUM(revision))
        {
          SVN_ERR(block_read(NULL, fs, &rs->rep_id, rs->sfile->rfile,
                             result_pool, scratch_pool));
          if (ffd->rep_header_cache)
            SVN_ERR(svn_cache__set(ffd->rep_header_cache, &key, rh,
                                   scratch_pool));
        }
    }
  SVN_ERR(dgb__log_access(fs, &rs->rep_id, rh, SVN_FS_X__ITEM_TYPE_ANY_REP,
                          scratch_pool));
  rs->header_size = rh->header_size;
  *rep_state = rs;
  *rep_header = rh;
  rs->chunk_index = 0;
  rs->current = 4;
  return SVN_NO_ERROR;
}
static svn_error_t * create_rep_state_body ( rep_state_t * * rep_state , svn_fs_x__rep_header_t * * rep_header , shared_file_t * * shared_file , svn_fs_x__representation_t * rep , svn_fs_t * fs , apr_pool_t * result_pool , apr_pool_t * scratch_pool ) { svn_fs_x__data_t * ffd = fs -> fsap_data ; rep_state_t * rs = apr_pcalloc ( result_pool , sizeof ( * rs ) ) ; svn_fs_x__rep_header_t * rh ; svn_boolean_t is_cached = FALSE ; svn_revnum_t revision = svn_fs_x__get_revnum ( rep -> id . change_set ) ; apr_uint64_t estimated_window_storage ; svn_boolean_t reuse_shared_file = shared_file && * shared_file && ( * shared_file ) -> rfile && SVN_IS_VALID_REVNUM ( ( * shared_file ) -> revision ) && ( * shared_file ) -> revision < ffd -> min_unpacked_rev && revision < ffd -> min_unpacked_rev && ( ( ( * shared_file ) -> revision / ffd -> max_files_per_dir ) == ( revision / ffd -> max_files_per_dir ) ) ; svn_fs_x__representation_cache_key_t key = { 0 } ; key . revision = revision ; key . is_packed = revision < ffd -> min_unpacked_rev ; key . item_index = rep -> id . number ; rs -> size = rep -> size ; rs -> rep_id = rep -> id ; rs -> ver = -1 ; rs -> start = -1 ; estimated_window_storage = 4 * ( ( rep -> expanded_size ? rep -> expanded_size : rep -> size ) + SVN_DELTA_WINDOW_SIZE ) ; estimated_window_storage = MIN ( estimated_window_storage , APR_SIZE_MAX ) ; rs -> window_cache = ffd -> txdelta_window_cache && svn_cache__is_cachable ( ffd -> txdelta_window_cache , ( apr_size_t ) estimated_window_storage ) ? ffd -> txdelta_window_cache : NULL ; rs -> combined_cache = ffd -> combined_window_cache && svn_cache__is_cachable ( ffd -> combined_window_cache , ( apr_size_t ) estimated_window_storage ) ? ffd -> combined_window_cache : NULL ; if ( ffd -> rep_header_cache && SVN_IS_VALID_REVNUM ( revision ) ) SVN_ERR ( svn_cache__get ( ( void * * ) & rh , & is_cached , ffd -> rep_header_cache , & key , result_pool ) ) ; if ( reuse_shared_file ) { rs -> sfile = * shared_file ; } else { shared_file_t * file = apr_pcalloc ( result_pool , sizeof ( * file ) ) ; file -> revision = revision ; file -> pool = result_pool ; file -> fs = fs ; rs -> sfile = file ; if ( shared_file ) * shared_file = file ; } if ( ! is_cached ) { apr_off_t offset ; svn_boolean_t in_container = TRUE ; if ( reuse_shared_file ) { rs -> sfile = * shared_file ; SVN_ERR ( auto_open_shared_file ( rs -> sfile ) ) ; } else { SVN_ERR ( open_and_seek_representation ( & rs -> sfile -> rfile , fs , rep , result_pool , scratch_pool ) ) ; } if ( SVN_IS_VALID_REVNUM ( revision ) ) { apr_uint32_t sub_item ; SVN_ERR ( svn_fs_x__item_offset ( & offset , & sub_item , fs , rs -> sfile -> rfile , & rep -> id , scratch_pool ) ) ; if ( sub_item == 0 ) { svn_fs_x__p2l_entry_t * entry ; SVN_ERR ( svn_fs_x__p2l_entry_lookup ( & entry , fs , rs -> sfile -> rfile , revision , offset , scratch_pool , scratch_pool ) ) ; in_container = entry -> type == SVN_FS_X__ITEM_TYPE_REPS_CONT ; } if ( in_container ) { * rep_header = apr_pcalloc ( result_pool , sizeof ( * * rep_header ) ) ; ( * rep_header ) -> type = svn_fs_x__rep_container ; * rep_state = rs ; return SVN_NO_ERROR ; } SVN_ERR ( rs_aligned_seek ( rs , NULL , offset , scratch_pool ) ) ; } SVN_ERR ( svn_fs_x__read_rep_header ( & rh , rs -> sfile -> rfile -> stream , result_pool , scratch_pool ) ) ; SVN_ERR ( get_file_offset ( & rs -> start , rs , result_pool ) ) ; if ( SVN_IS_VALID_REVNUM ( revision ) ) { SVN_ERR ( block_read ( NULL , fs , & rs -> rep_id , rs -> sfile -> rfile , result_pool , scratch_pool ) ) ; if ( ffd -> rep_header_cache ) SVN_ERR ( svn_cache__set ( ffd -> rep_header_cache , & key , rh , scratch_pool ) ) ; } } SVN_ERR ( dgb__log_access ( fs , & rs -> rep_id , rh , SVN_FS_X__ITEM_TYPE_ANY_REP , scratch_pool ) ) ; rs -> header_size = rh -> header_size ; * rep_state = rs ; * rep_header = rh ; rs -> chunk_index = 0 ; rs -> current = 4 ; return SVN_NO_ERROR ; }
See create_rep_state, which wraps this and adds another error.
See create_rep_state which wraps this and adds another error .
/* If the hint is
   * - given,
   * - refers to a valid revision,
   * - refers to a packed revision,
   * - as does the rep we want to read, and
   * - refers to the same pack file as the rep
   * we can re-use the same, already open file object
   */ /* continue constructing RS and RA */ /* Very long files stored as self-delta will produce a huge number of
     delta windows.  Don't cache them lest we don't thrash the cache.
     Since we don't know the depth of the delta chain, let's assume, the
     whole contents get rewritten 3 times.
   */ /* cache lookup, i.e. skip reading the rep header if possible */ /* initialize the (shared) FILE member in RS */ /* remember the current file, if suggested by the caller */ /* read rep header, if necessary */ /* we will need the on-disk location for non-txn reps */ /* ensure file is open and navigate to the start of rep header */ /* ... we can re-use the same, already open file object.
           * This implies that we don't read from a txn.
           */ /* otherwise, create a new file object.  May or may not be
           * an in-txn file.
           */ /* is rep stored in some star-deltified container? */ /* construct a container rep header */ /* exit to caller */ /* populate the cache if appropriate */ /* finalize */ /* skip "SVNx" diff marker */