FreeBSD/contrib/subversion/subversion/libsvn_fs_fs/transaction.c
/* Write out the COLLECTION as a text representation to file FILE using
   WRITER.  In the process, record position, the total size of the dump and
   MD5 as well as SHA1 in REP.   Add the representation of type ITEM_TYPE to
   the indexes if necessary.  If rep sharing has been enabled and REPS_HASH
   is not NULL, it will be used in addition to the on-disk cache to find
   earlier reps with the same content.  When such existing reps can be
   found, we will truncate the one just written from the file and return
   the existing rep.  Perform temporary allocations in SCRATCH_POOL. */
Write out the COLLECTION as a text representation to file FILE using
WRITER.  In the process, record position, the total size of the dump and
MD5 as well as SHA1 in REP.   Add the representation of type ITEM_TYPE to
the indexes if necessary.  If rep sharing has been enabled and REPS_HASH
is not NULL, it will be used in addition to the on-disk cache to find
earlier reps with the same content.  When such existing reps can be
found, we will truncate the one just written from the file and return
the existing rep.  Perform temporary allocations in SCRATCH_POOL.
Write out the COLLECTION as a text representation to file FILE using WRITER . In the process record position the total size of the dump and MD5 as well as SHA1 in REP . Add the representation of type ITEM_TYPE to the indexes if necessary . If rep sharing has been enabled and REPS_HASH is not NULL it will be used in addition to the on - disk cache to find earlier reps with the same content . When such existing reps can be found we will truncate the one just written from the file and return the existing rep . Perform temporary allocations in SCRATCH_POOL .
static svn_error_t *
write_container_rep(representation_t *rep,
                    apr_file_t *file,
                    void *collection,
                    collection_writer_t writer,
                    svn_fs_t *fs,
                    apr_hash_t *reps_hash,
                    apr_uint32_t item_type,
                    apr_pool_t *scratch_pool)
{
  svn_stream_t *stream;
  struct write_container_baton *whb;
  svn_checksum_ctx_t *fnv1a_checksum_ctx;
  representation_t *old_rep;
  apr_off_t offset = 0;
  SVN_ERR(svn_fs_fs__get_file_offset(&offset, file, scratch_pool));
  whb = apr_pcalloc(scratch_pool, sizeof(*whb));
  whb->stream = fnv1a_wrap_stream(&fnv1a_checksum_ctx,
                                  svn_stream_from_aprfile2(file, TRUE,
                                                           scratch_pool),
                                  scratch_pool);
  whb->size = 0;
  whb->md5_ctx = svn_checksum_ctx_create(svn_checksum_md5, scratch_pool);
  whb->sha1_ctx = svn_checksum_ctx_create(svn_checksum_sha1, scratch_pool);
  stream = svn_stream_create(whb, scratch_pool);
  svn_stream_set_write(stream, write_container_handler);
  SVN_ERR(svn_stream_puts(whb->stream, "PLAIN\n"));
  SVN_ERR(writer(stream, collection, scratch_pool));
  SVN_ERR(digests_final(rep, whb->md5_ctx, whb->sha1_ctx, scratch_pool));
  SVN_ERR(get_shared_rep(&old_rep, fs, rep, reps_hash, scratch_pool,
                         scratch_pool));
  if (old_rep)
    {
      SVN_ERR(svn_io_file_trunc(file, offset, scratch_pool));
      memcpy(rep, old_rep, sizeof (*rep));
    }
  else
    {
      svn_fs_fs__p2l_entry_t entry;
      SVN_ERR(svn_stream_puts(whb->stream, "ENDREP\n"));
      SVN_ERR(allocate_item_index(&rep->item_index, fs, &rep->txn_id,
                                  offset, scratch_pool));
      entry.offset = offset;
      SVN_ERR(svn_fs_fs__get_file_offset(&offset, file, scratch_pool));
      entry.size = offset - entry.offset;
      entry.type = item_type;
      entry.item.revision = SVN_INVALID_REVNUM;
      entry.item.number = rep->item_index;
      SVN_ERR(fnv1a_checksum_finalize(&entry.fnv1_checksum,
                                      fnv1a_checksum_ctx,
                                      scratch_pool));
      SVN_ERR(store_p2l_index_entry(fs, &rep->txn_id, &entry, scratch_pool));
      rep->size = whb->size;
      rep->expanded_size = whb->size;
    }
  return SVN_NO_ERROR;
}
static svn_error_t * write_container_rep ( representation_t * rep , apr_file_t * file , void * collection , collection_writer_t writer , svn_fs_t * fs , apr_hash_t * reps_hash , apr_uint32_t item_type , apr_pool_t * scratch_pool ) { svn_stream_t * stream ; struct write_container_baton * whb ; svn_checksum_ctx_t * fnv1a_checksum_ctx ; representation_t * old_rep ; apr_off_t offset = 0 ; SVN_ERR ( svn_fs_fs__get_file_offset ( & offset , file , scratch_pool ) ) ; whb = apr_pcalloc ( scratch_pool , sizeof ( * whb ) ) ; whb -> stream = fnv1a_wrap_stream ( & fnv1a_checksum_ctx , svn_stream_from_aprfile2 ( file , TRUE , scratch_pool ) , scratch_pool ) ; whb -> size = 0 ; whb -> md5_ctx = svn_checksum_ctx_create ( svn_checksum_md5 , scratch_pool ) ; whb -> sha1_ctx = svn_checksum_ctx_create ( svn_checksum_sha1 , scratch_pool ) ; stream = svn_stream_create ( whb , scratch_pool ) ; svn_stream_set_write ( stream , write_container_handler ) ; SVN_ERR ( svn_stream_puts ( whb -> stream , " \n " ) ) ; SVN_ERR ( writer ( stream , collection , scratch_pool ) ) ; SVN_ERR ( digests_final ( rep , whb -> md5_ctx , whb -> sha1_ctx , scratch_pool ) ) ; SVN_ERR ( get_shared_rep ( & old_rep , fs , rep , reps_hash , scratch_pool , scratch_pool ) ) ; if ( old_rep ) { SVN_ERR ( svn_io_file_trunc ( file , offset , scratch_pool ) ) ; memcpy ( rep , old_rep , sizeof ( * rep ) ) ; } else { svn_fs_fs__p2l_entry_t entry ; SVN_ERR ( svn_stream_puts ( whb -> stream , " \n " ) ) ; SVN_ERR ( allocate_item_index ( & rep -> item_index , fs , & rep -> txn_id , offset , scratch_pool ) ) ; entry . offset = offset ; SVN_ERR ( svn_fs_fs__get_file_offset ( & offset , file , scratch_pool ) ) ; entry . size = offset - entry . offset ; entry . type = item_type ; entry . item . revision = SVN_INVALID_REVNUM ; entry . item . number = rep -> item_index ; SVN_ERR ( fnv1a_checksum_finalize ( & entry . fnv1_checksum , fnv1a_checksum_ctx , scratch_pool ) ) ; SVN_ERR ( store_p2l_index_entry ( fs , & rep -> txn_id , & entry , scratch_pool ) ) ; rep -> size = whb -> size ; rep -> expanded_size = whb -> size ; } return SVN_NO_ERROR ; }
Write out the COLLECTION as a text representation to file FILE using
WRITER.
Write out the COLLECTION as a text representation to file FILE using WRITER .
/* Store the results. */ /* Check and see if we already have a representation somewhere that's
     identical to the one we just wrote out. */ /* We need to erase from the protorev the data we just wrote. */ /* Use the old rep for this content. */ /* Write out our cosmetic end marker. */ /* update the representation */