Exemple #1
0
    def save(self, req, text, comment):
        """
        Save the specified text into this document.
        """
        if not isinstance(self.node.repos, SubversionRepository):
            raise TracError("The '%s' repository is not supported" % type(self.node.repos))

        from svn import core as _core
        from svn import fs as _fs
        from svn import repos as _repos

        repos = self.node.repos.repos #.repos
        revnum = self.node._requested_rev
        author = req.authname
        message = 'Edited %s' % self.base[1:]
        if comment:
            message += ' (%s)' % comment

        pool = _core.Pool()
        fs_txn = _repos.fs_begin_txn_for_commit(repos, revnum, author, message, pool)
        fs_root = _fs.svn_fs_txn_root(fs_txn, pool)
        if hasattr(self.node, '_scoped_svn_path'):
            fs_path = self.node._scoped_svn_path
        else:
            fs_path = self.node._scoped_path_utf8
        stream = _fs.svn_fs_apply_text(fs_root, fs_path, None, pool)
        _core.svn_stream_write(stream, text)
        _core.svn_stream_close(stream) 
        return _repos.fs_commit_txn(repos, fs_txn, pool)
Exemple #2
0
def putfile(fname, rpath, uname="", commitmsg=""):
    rpath = core.svn_path_canonicalize(rpath)
    repos_ptr = repos.open(rpath)
    fsob = repos.fs(repos_ptr)

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

    txn = repos.fs_begin_txn_for_commit(repos_ptr, rev, uname, commitmsg)

    root = fs.txn_root(txn)
    rev_root = fs.revision_root(fsob, rev)

    kind = fs.check_path(root, fname)
    if kind == core.svn_node_none:
        print("file '%s' does not exist, creating..." % fname)
        fs.make_file(root, fname)
    elif kind == core.svn_node_dir:
        print("File '%s' is a dir." % fname)
        return
    else:
        print("Updating file '%s'" % fname)

    handler, baton = fs.apply_textdelta(root, fname, None, None)

    ### 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)

    newrev = repos.fs_commit_txn(repos_ptr, txn)
    print("revision: %s" % newrev)
Exemple #3
0
def putfile(fname, rpath, uname="", commitmsg=""):
  rpath = core.svn_path_canonicalize(rpath)
  repos_ptr = repos.open(rpath)
  fsob = repos.fs(repos_ptr)

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

  txn = repos.fs_begin_txn_for_commit(repos_ptr, rev, uname, commitmsg)

  root = fs.txn_root(txn)
  rev_root = fs.revision_root(fsob, rev)

  kind = fs.check_path(root, fname)
  if kind == core.svn_node_none:
    print("file '%s' does not exist, creating..." % fname)
    fs.make_file(root, fname)
  elif kind == core.svn_node_dir:
    print("File '%s' is a dir." % fname)
    return
  else:
    print("Updating file '%s'" % fname)

  handler, baton = fs.apply_textdelta(root, fname, None, None)

  ### 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)

  newrev = repos.fs_commit_txn(repos_ptr, txn)
  print("revision: %s" % newrev)
Exemple #4
0
    def write(self, data, uname='', commitmsg='',istext=False):
        txn = repos.fs_begin_txn_for_commit(self._repo.repos_ptr, self.revno, uname, commitmsg)
        r = None
        try:
            txn_root = fs.txn_root(txn)

            kind = fs.check_path(txn_root, self.path)

            if kind == core.svn_node_none:
                if not _create_file(txn_root, self.path):
                    raise 'attempt to create file, but file creation error: %s'%path
                pass

            elif kind == core.svn_node_dir:
                raise 'attempt to create file, but directory already exists: %s'%self.path

            if istext:
                fs.change_node_prop(txn_root, self.path, 'svn:eol-style', 'native')
                pass


            handler, baton = fs.apply_textdelta(txn_root, self.path, None, None)
            delta.svn_txdelta_send_string(data, handler, baton)

            r = repos.fs_commit_txn(self._repo.repos_ptr, txn)
        except Exception, a:
            fs.abort_txn(txn)
            raise