Example #1
0
 def create_file(self, file_name, content, author, comment):
     """
     Creates a file in the SVN repository with the given
     name and content (text). Returns the committed revision
     """
     assert self.svn_repos is not None, "SVN repository not set..."
     # Get an SVN file system pointer
     fs_ptr = repos.fs(self.svn_repos)
     rev = fs.youngest_rev(fs_ptr)
     # Create and SVN transaction
     txn = fs.begin_txn(fs_ptr, rev)
     txn_root = fs.txn_root(txn)
     # Create a file in the root transaction
     fs.make_file(txn_root, file_name)
     stream = fs.apply_text(txn_root, file_name, None)
     core.svn_stream_write(stream, "%s\n" % content)
     core.svn_stream_close(stream)
     # Now set the properties svn:log and svn:author to
     # the newly created node (file)
     fs.change_txn_prop(txn, 'svn:author', author)
     fs.change_txn_prop(txn, 'svn:log', comment)
     # Commit the transaction
     fs.commit_txn(txn)
     # Add teh file to the list of created files
     self.files.append(file_name)
     # Returns therevision number
     return rev + 1
Example #2
0
 def create_file(self, file_name, content, author, comment):
     """
     Creates a file in the SVN repository with the given
     name and content (text). Returns the committed revision
     """
     assert self.svn_repos is not None, "SVN repository not set..."
     # Get an SVN file system pointer
     fs_ptr = repos.fs(self.svn_repos)
     rev = fs.youngest_rev(fs_ptr)
     # Create and SVN transaction
     txn = fs.begin_txn(fs_ptr, rev)
     txn_root = fs.txn_root(txn)
     # Create a file in the root transaction
     fs.make_file(txn_root, file_name)
     stream = fs.apply_text(txn_root, file_name, None)
     core.svn_stream_write(stream, "%s\n" % content)
     core.svn_stream_close(stream)
     # Now set the properties svn:log and svn:author to
     # the newly created node (file)
     fs.change_txn_prop(txn, 'svn:author', author)
     fs.change_txn_prop(txn, 'svn:log', comment)
     # Commit the transaction
     fs.commit_txn(txn)
     # Add teh file to the list of created files
     self.files.append(file_name)
     # Returns therevision number
     return rev + 1
Example #3
0
 def delete_file(self, file_name):
     """Deletes the given file from the repository"""
     assert self.svn_repos is not None, "SVN repository not set..."
     # Get an SVN file system pointer
     fs_ptr = repos.fs(self.svn_repos)
     rev = fs.youngest_rev(fs_ptr)
     # Create and SVN transaction
     txn = fs.begin_txn(fs_ptr, rev)
     txn_root = fs.txn_root(txn)
     # Create a file in the root transaction
     fs.delete(txn_root, file_name)
     # Commit the transaction
     fs.commit_txn(txn)
Example #4
0
 def delete_file(self, file_name):
     """Deletes the given file from the repository"""
     assert self.svn_repos is not None, "SVN repository not set..."
     # Get an SVN file system pointer
     fs_ptr = repos.fs(self.svn_repos)
     rev = fs.youngest_rev(fs_ptr)
     # Create and SVN transaction
     txn = fs.begin_txn(fs_ptr, rev)
     txn_root = fs.txn_root(txn)
     # Create a file in the root transaction
     fs.delete(txn_root, file_name)
     # Commit the transaction
     fs.commit_txn(txn)
Example #5
0
 def delete_files(self):
     """Deletes all the files created by the helper"""
     if self.svn_repos is not None:
         # Get an SVN file system pointer
         fs_ptr = repos.fs(self.svn_repos)
         rev = fs.youngest_rev(fs_ptr)
         # Create and SVN transaction
         txn = fs.begin_txn(fs_ptr, rev)
         txn_root = fs.txn_root(txn)
         # Create a file in the root transaction
         for svn_file in self.files:
             fs.delete(txn_root, svn_file)
         # Commit the transaction
         fs.commit_txn(txn)
Example #6
0
 def delete_files(self):
     """Deletes all the files created by the helper"""
     if self.svn_repos is not None:
         # Get an SVN file system pointer
         fs_ptr = repos.fs(self.svn_repos)
         rev = fs.youngest_rev(fs_ptr)
         # Create and SVN transaction
         txn = fs.begin_txn(fs_ptr, rev)
         txn_root = fs.txn_root(txn)
         # Create a file in the root transaction
         for svn_file in self.files:
             fs.delete(txn_root, svn_file)
         # Commit the transaction
         fs.commit_txn(txn)
def putfile(fname, rpath, home='.'):
    _util.apr_initialize()
    pool = _util.svn_pool_create(None)

    db_path = os.path.join(home, 'db')
    if not os.path.exists(db_path):
        db_path = home

    fsob = fs.new(pool)
    fs.open_berkeley(fsob, db_path)

    # open a transaction against HEAD
    rev = fs.youngest_rev(fsob, pool)

    txn = fs.begin_txn(fsob, rev, pool)
    print ` txn `

    root = fs.txn_root(txn, pool)
    fs.make_file(root, rpath, pool)

    handler, baton = fs.apply_textdelta(root, rpath, pool)

    ### it would be nice to get an svn_stream_t. for now, just load in the
    ### whole file and shove it into the FS.
    _delta.svn_txdelta_send_string(
        open(fname, 'rb').read(), handler, baton, pool)

    conflicts, new_rev = fs.commit_txn(txn)
    if conflicts:
        print 'conflicts:', conflicts
    print 'New revision:', new_rev

    _util.svn_pool_destroy(pool)
    _util.apr_terminate()
Example #8
0
 def commit(self):
   values = fs.commit_txn(self.txnp, self.pool)
   return values[1]
    def commit(self, t_fs, ctx):
        # commit this transaction
        print 'committing: %s, over %d seconds' % (time.ctime(
            self.t_min), self.t_max - self.t_min)

        # create a pool for the entire commit
        c_pool = util.svn_pool_create(ctx.pool)

        rev = fs.youngest_rev(t_fs, c_pool)
        txn = fs.begin_txn(t_fs, rev, c_pool)
        root = fs.txn_root(txn, c_pool)

        lastcommit = (None, None)

        # create a pool for each file; it will be cleared on each iteration
        f_pool = util.svn_pool_create(c_pool)

        for f, r in self.changes:
            # compute a repository path. ensure we have a leading "/" and drop
            # the ,v from the file name
            repos_path = '/' + relative_name(ctx.cvsroot, f[:-2])
            #print 'DEBUG:', repos_path

            print '    changing %s : %s' % (r, repos_path)

            ### hmm. need to clarify OS path separators vs FS path separators
            dirname = os.path.dirname(repos_path)
            if dirname != '/':
                # get the components of the path (skipping the leading '/')
                parts = string.split(dirname[1:], os.sep)
                for i in range(1, len(parts) + 1):
                    # reassemble the pieces, adding a leading slash
                    parent_dir = '/' + string.join(parts[:i], '/')
                    if fs.check_path(root, parent_dir,
                                     f_pool) == svn_node_none:
                        print '    making dir:', parent_dir
                        fs.make_dir(root, parent_dir, f_pool)

            if fs.check_path(root, repos_path, f_pool) == svn_node_none:
                created_file = 1
                fs.make_file(root, repos_path, f_pool)
            else:
                created_file = 0

            handler, baton = fs.apply_textdelta(root, repos_path, f_pool)

            # figure out the real file path for "co"
            try:
                statcache.stat(f)
            except os.error:
                dirname, fname = os.path.split(f)
                f = os.path.join(dirname, 'Attic', fname)
                statcache.stat(f)

            pipe = os.popen('co -q -p%s %s' % (r, f), 'r', 102400)

            # if we just made the file, we can send it in one big hunk, rather
            # than streaming it in.
            ### we should watch out for file sizes here; we don't want to yank
            ### in HUGE files...
            if created_file:
                _delta.svn_txdelta_send_string(pipe.read(), handler, baton,
                                               f_pool)
            else:
                # open an SVN stream onto the pipe
                stream2 = util.svn_stream_from_stdio(pipe, f_pool)

                # Get the current file contents from the repo, or, if we have
                # multiple CVS revisions to the same file being done in this
                # single commit, then get the contents of the previous
                # revision from co, or else the delta won't be correct because
                # the contents in the repo won't have changed yet.
                if repos_path == lastcommit[0]:
                    infile2 = os.popen("co -q -p%s %s" % (lastcommit[1], f),
                                       "r", 102400)
                    stream1 = util.svn_stream_from_stdio(infile2, f_pool)
                else:
                    stream1 = fs.file_contents(root, repos_path, f_pool)

                txstream = _delta.svn_txdelta(stream1, stream2, f_pool)
                _delta.svn_txdelta_send_txstream(txstream, handler, baton,
                                                 f_pool)

                # shut down the previous-rev pipe, if we opened it
                infile2 = None

            # shut down the current-rev pipe
            pipe.close()

            # wipe the pool. this will get rid of the pipe streams and the delta
            # stream, and anything the FS may have done.
            util.svn_pool_clear(f_pool)

            # remember what we just did, for the next iteration
            lastcommit = (repos_path, r)

        for f, r in self.deletes:
            # compute a repository path. ensure we have a leading "/" and drop
            # the ,v from the file name
            repos_path = '/' + relative_name(ctx.cvsroot, f[:-2])

            print '    deleting %s : %s' % (r, repos_path)

            # If the file was initially added on a branch, the first mainline
            # revision will be marked dead, and thus, attempts to delete it will
            # fail, since it doesn't really exist.
            if r != '1.1':
                ### need to discriminate between OS paths and FS paths
                fs.delete(root, repos_path, f_pool)

            # wipe the pool, in case the delete loads it up
            util.svn_pool_clear(f_pool)

        # get the metadata for this commit
        author, log, date = self.get_metadata(c_pool)
        fs.change_txn_prop(txn, 'svn:author', author, c_pool)
        fs.change_txn_prop(txn, 'svn:log', log, c_pool)

        conflicts, new_rev = fs.commit_txn(txn)

        # set the time to the proper (past) time
        fs.change_rev_prop(t_fs, new_rev, 'svn:date', date, c_pool)

        ### how come conflicts is a newline?
        if conflicts != '\n':
            print '    CONFLICTS:', ` conflicts `
        print '    new revision:', new_rev

        # done with the commit and file pools
        util.svn_pool_destroy(c_pool)