FreeBSD/contrib/subversion/subversion/libsvn_fs_fs/transaction.c
/* Close handler for the representation write stream.  BATON is a
   rep_write_baton.  Writes out a new node-rev that correctly
   references the representation we just finished writing. */
Close handler for the representation write stream.  BATON is a
rep_write_baton.  Writes out a new node-rev that correctly
references the representation we just finished writing.
Close handler for the representation write stream . BATON is a rep_write_baton . Writes out a new node - rev that correctly references the representation we just finished writing .
static svn_error_t *
rep_write_contents_close(void *baton)
{
  struct rep_write_baton *b = baton;
  representation_t *rep;
  representation_t *old_rep;
  apr_off_t offset;
  rep = apr_pcalloc(b->result_pool, sizeof(*rep));
  if (b->delta_stream)
    SVN_ERR(svn_stream_close(b->delta_stream));
  SVN_ERR(svn_fs_fs__get_file_offset(&offset, b->file, b->scratch_pool));
  rep->size = offset - b->delta_start;
  rep->expanded_size = b->rep_size;
  rep->txn_id = *svn_fs_fs__id_txn_id(b->noderev->id);
  SVN_ERR(set_uniquifier(b->fs, rep, b->scratch_pool));
  rep->revision = SVN_INVALID_REVNUM;
  SVN_ERR(digests_final(rep, b->md5_checksum_ctx, b->sha1_checksum_ctx,
                        b->result_pool));
  SVN_ERR(get_shared_rep(&old_rep, b->fs, rep, NULL, b->result_pool,
                         b->scratch_pool));
  if (old_rep)
    {
      SVN_ERR(svn_io_file_trunc(b->file, b->rep_offset, b->scratch_pool));
      b->noderev->data_rep = old_rep;
    }
  else
    {
      SVN_ERR(svn_stream_puts(b->rep_stream, "ENDREP\n"));
      SVN_ERR(allocate_item_index(&rep->item_index, b->fs, &rep->txn_id,
                                  b->rep_offset, b->scratch_pool));
      b->noderev->data_rep = rep;
    }
  apr_pool_cleanup_kill(b->scratch_pool, b, rep_write_cleanup);
  SVN_ERR(svn_fs_fs__put_node_revision(b->fs, b->noderev->id, b->noderev,
                                       FALSE, b->scratch_pool));
  if (!old_rep)
    {
      svn_fs_fs__p2l_entry_t entry;
      entry.offset = b->rep_offset;
      SVN_ERR(svn_fs_fs__get_file_offset(&offset, b->file, b->scratch_pool));
      entry.size = offset - b->rep_offset;
      entry.type = SVN_FS_FS__ITEM_TYPE_FILE_REP;
      entry.item.revision = SVN_INVALID_REVNUM;
      entry.item.number = rep->item_index;
      SVN_ERR(fnv1a_checksum_finalize(&entry.fnv1_checksum,
                                      b->fnv1a_checksum_ctx,
                                      b->scratch_pool));
      SVN_ERR(store_sha1_rep_mapping(b->fs, b->noderev, b->scratch_pool));
      SVN_ERR(store_p2l_index_entry(b->fs, &rep->txn_id, &entry,
                                    b->scratch_pool));
    }
  SVN_ERR(svn_io_file_close(b->file, b->scratch_pool));
  SVN_ERR(unlock_proto_rev(b->fs, &rep->txn_id, b->lockcookie,
                           b->scratch_pool));
  svn_pool_destroy(b->scratch_pool);
  return SVN_NO_ERROR;
}
static svn_error_t * rep_write_contents_close ( void * baton ) { struct rep_write_baton * b = baton ; representation_t * rep ; representation_t * old_rep ; apr_off_t offset ; rep = apr_pcalloc ( b -> result_pool , sizeof ( * rep ) ) ; if ( b -> delta_stream ) SVN_ERR ( svn_stream_close ( b -> delta_stream ) ) ; SVN_ERR ( svn_fs_fs__get_file_offset ( & offset , b -> file , b -> scratch_pool ) ) ; rep -> size = offset - b -> delta_start ; rep -> expanded_size = b -> rep_size ; rep -> txn_id = * svn_fs_fs__id_txn_id ( b -> noderev -> id ) ; SVN_ERR ( set_uniquifier ( b -> fs , rep , b -> scratch_pool ) ) ; rep -> revision = SVN_INVALID_REVNUM ; SVN_ERR ( digests_final ( rep , b -> md5_checksum_ctx , b -> sha1_checksum_ctx , b -> result_pool ) ) ; SVN_ERR ( get_shared_rep ( & old_rep , b -> fs , rep , NULL , b -> result_pool , b -> scratch_pool ) ) ; if ( old_rep ) { SVN_ERR ( svn_io_file_trunc ( b -> file , b -> rep_offset , b -> scratch_pool ) ) ; b -> noderev -> data_rep = old_rep ; } else { SVN_ERR ( svn_stream_puts ( b -> rep_stream , " \n " ) ) ; SVN_ERR ( allocate_item_index ( & rep -> item_index , b -> fs , & rep -> txn_id , b -> rep_offset , b -> scratch_pool ) ) ; b -> noderev -> data_rep = rep ; } apr_pool_cleanup_kill ( b -> scratch_pool , b , rep_write_cleanup ) ; SVN_ERR ( svn_fs_fs__put_node_revision ( b -> fs , b -> noderev -> id , b -> noderev , FALSE , b -> scratch_pool ) ) ; if ( ! old_rep ) { svn_fs_fs__p2l_entry_t entry ; entry . offset = b -> rep_offset ; SVN_ERR ( svn_fs_fs__get_file_offset ( & offset , b -> file , b -> scratch_pool ) ) ; entry . size = offset - b -> rep_offset ; entry . type = SVN_FS_FS__ITEM_TYPE_FILE_REP ; entry . item . revision = SVN_INVALID_REVNUM ; entry . item . number = rep -> item_index ; SVN_ERR ( fnv1a_checksum_finalize ( & entry . fnv1_checksum , b -> fnv1a_checksum_ctx , b -> scratch_pool ) ) ; SVN_ERR ( store_sha1_rep_mapping ( b -> fs , b -> noderev , b -> scratch_pool ) ) ; SVN_ERR ( store_p2l_index_entry ( b -> fs , & rep -> txn_id , & entry , b -> scratch_pool ) ) ; } SVN_ERR ( svn_io_file_close ( b -> file , b -> scratch_pool ) ) ; SVN_ERR ( unlock_proto_rev ( b -> fs , & rep -> txn_id , b -> lockcookie , b -> scratch_pool ) ) ; svn_pool_destroy ( b -> scratch_pool ) ; return SVN_NO_ERROR ; }
Close handler for the representation write stream.
Close handler for the representation write stream .
/* Close our delta stream so the last bits of svndiff are written
     out. */ /* Determine the length of the svndiff data. */ /* Fill in the rest of the representation field. */ /* Finalize the checksum. */ /* 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. */ /* Remove cleanup callback. */ /* Write out the new node-rev information. */