FreeBSD/contrib/subversion/subversion/libsvn_wc/wc_db_pristine.c
/* Set *CONTENTS to a readable stream from which the pristine text
 * identified by SHA1_CHECKSUM and PRISTINE_ABSPATH can be read from the
 * pristine store of WCROOT.  If SIZE is not null, set *SIZE to the size
 * in bytes of that text. If that text is not in the pristine store,
 * return an error.
 *
 * Even if the pristine text is removed from the store while it is being
 * read, the stream will remain valid and readable until it is closed.
 *
 * Allocate the stream in RESULT_POOL.
 *
 * This function expects to be executed inside a SQLite txn.
 *
 * Implements 'notes/wc-ng/pristine-store' section A-3(d).
 */
Set *CONTENTS to a readable stream from which the pristine text
identified by SHA1_CHECKSUM and PRISTINE_ABSPATH can be read from the
pristine store of WCROOT.  If SIZE is not null, set *SIZE to the size
in bytes of that text. If that text is not in the pristine store,
return an error.

Even if the pristine text is removed from the store while it is being
read, the stream will remain valid and readable until it is closed.

Allocate the stream in RESULT_POOL.

This function expects to be executed inside a SQLite txn.


Set * CONTENTS to a readable stream from which the pristine text identified by SHA1_CHECKSUM and PRISTINE_ABSPATH can be read from the pristine store of WCROOT . If SIZE is not null set * SIZE to the size in bytes of that text . If that text is not in the pristine store return an error . Even if the pristine text is removed from the store while it is being read the stream will remain valid and readable until it is closed . Allocate the stream in RESULT_POOL . This function expects to be executed inside a SQLite txn .
static svn_error_t *
pristine_read_txn(svn_stream_t **contents,
                  svn_filesize_t *size,
                  svn_wc__db_wcroot_t *wcroot,
                  const svn_checksum_t *sha1_checksum,
                  const char *pristine_abspath,
                  apr_pool_t *result_pool,
                  apr_pool_t *scratch_pool)
{
  svn_sqlite__stmt_t *stmt;
  svn_boolean_t have_row;
  SVN_ERR(svn_sqlite__get_statement(&stmt, wcroot->sdb,
                                    STMT_SELECT_PRISTINE_SIZE));
  SVN_ERR(svn_sqlite__bind_checksum(stmt, 1, sha1_checksum, scratch_pool));
  SVN_ERR(svn_sqlite__step(&have_row, stmt));
  if (size)
    *size = svn_sqlite__column_int64(stmt, 0);
  SVN_ERR(svn_sqlite__reset(stmt));
  if (! have_row)
    {
      return svn_error_createf(SVN_ERR_WC_PATH_NOT_FOUND, NULL,
                               _("Pristine text '%s' not present"),
                               svn_checksum_to_cstring_display(
                                 sha1_checksum, scratch_pool));
    }
  if (contents)
    {
      apr_file_t *file;
      SVN_ERR(svn_io_file_open(&file, pristine_abspath, APR_READ,
                               APR_OS_DEFAULT, result_pool));
      *contents = svn_stream_from_aprfile2(file, FALSE, result_pool);
    }
  return SVN_NO_ERROR;
}
static svn_error_t * pristine_read_txn ( svn_stream_t * * contents , svn_filesize_t * size , svn_wc__db_wcroot_t * wcroot , const svn_checksum_t * sha1_checksum , const char * pristine_abspath , apr_pool_t * result_pool , apr_pool_t * scratch_pool ) { svn_sqlite__stmt_t * stmt ; svn_boolean_t have_row ; SVN_ERR ( svn_sqlite__get_statement ( & stmt , wcroot -> sdb , STMT_SELECT_PRISTINE_SIZE ) ) ; SVN_ERR ( svn_sqlite__bind_checksum ( stmt , 1 , sha1_checksum , scratch_pool ) ) ; SVN_ERR ( svn_sqlite__step ( & have_row , stmt ) ) ; if ( size ) * size = svn_sqlite__column_int64 ( stmt , 0 ) ; SVN_ERR ( svn_sqlite__reset ( stmt ) ) ; if ( ! have_row ) { return svn_error_createf ( SVN_ERR_WC_PATH_NOT_FOUND , NULL , _ ( " " ) , svn_checksum_to_cstring_display ( sha1_checksum , scratch_pool ) ) ; } if ( contents ) { apr_file_t * file ; SVN_ERR ( svn_io_file_open ( & file , pristine_abspath , APR_READ , APR_OS_DEFAULT , result_pool ) ) ; * contents = svn_stream_from_aprfile2 ( file , FALSE , result_pool ) ; } return SVN_NO_ERROR ; }
Set *CONTENTS to a readable stream from which the pristine text
 identified by SHA1_CHECKSUM and PRISTINE_ABSPATH can be read from the
 pristine store of WCROOT.
Set * CONTENTS to a readable stream from which the pristine text identified by SHA1_CHECKSUM and PRISTINE_ABSPATH can be read from the pristine store of WCROOT .
/* Check that this pristine text is present in the store.  (The presence
   * of the file is not sufficient.) */ /* Open the file as a readable stream.  It will remain readable even when
   * deleted from disk; APR guarantees that on Windows as well as Unix.
   *
   * We also don't enable APR_BUFFERED on this file to maximize throughput
   * e.g. for fulltext comparison.  As we use SVN__STREAM_CHUNK_SIZE buffers
   * where needed in streams, there is no point in having another layer of
   * buffers. */