示例#1
0
    def close_file(self, file_baton, text_checksum):
        changed, path = file_baton
        if len(path) < 3 or path[-3:] != '.po' or not changed:
            # This is not a .po file, or it hasn't changed
            return

        try:
            # Read the file contents through a validating UTF-8 decoder
            subpool = core.svn_pool_create(self.pool)
            checker = MsgFmtChecker()
            try:
                stream = core.Stream(
                    fs.file_contents(self.txn_root, path, subpool))
                reader = codecs.getreader('UTF-8')(stream, 'strict')
                writer = codecs.getwriter('UTF-8')(checker, 'strict')
                while 1:
                    data = reader.read(core.SVN_STREAM_CHUNK_SIZE)
                    if not data:
                        break
                    writer.write(data)
                if not checker.close():
                    sys.exit("PO format check failed for '" + path + "'")
            except UnicodeError:
                sys.exit("PO file is not in UTF-8: '" + path + "'")
        finally:
            core.svn_pool_destroy(subpool)
示例#2
0
文件: blame.py 项目: pirapu/raj
def blame(path, filename, rev=None):

    annotresult = {}
    path = core.svn_path_canonicalize(path)

    repos_ptr = repos.open(path)
    fsob = repos.fs(repos_ptr)

    if rev is None:
        rev = fs.youngest_rev(fsob)
    filedata = ''
    for i in xrange(0, rev + 1):
        root = fs.revision_root(fsob, i)
        if fs.check_path(root, filename) != core.svn_node_none:
            first = i
            break
    print "First revision is %d" % first
    print "Last revision is %d" % rev
    for i in xrange(first, rev + 1):
        previousroot = root
        root = fs.revision_root(fsob, i)
        if i != first:
            if not fs.contents_changed(root, filename, previousroot, filename):
                continue

        file = fs.file_contents(root, filename)
        previousdata = filedata
        filedata = ''
        while 1:
            data = core.svn_stream_read(file, CHUNK_SIZE)
            if not data:
                break
            filedata = filedata + data

        print "Current revision is %d" % i
        diffresult = difflib.ndiff(previousdata.splitlines(1),
                                   filedata.splitlines(1))
        #    print ''.join(diffresult)
        k = 0
        for j in diffresult:
            if j[0] == ' ':
                if annotresult.has_key(k):
                    k = k + 1
                    continue
                else:
                    annotresult[k] = (i, j[2:])
                    k = k + 1
                    continue
            elif j[0] == '?':
                continue
            annotresult[k] = (i, j[2:])
            if j[0] != '-':
                k = k + 1


#    print ''.join(diffresult)
#  print annotresult
    for x in xrange(len(annotresult.keys())):
        sys.stdout.write("Line %d (rev %d):%s" %
                         (x, annotresult[x][0], annotresult[x][1]))
示例#3
0
  def get_symlink_target(self, path_parts, rev):
    """Return the target of the symbolic link versioned at PATH_PARTS
    in REV, or None if that object is not a symlink."""

    path = self._getpath(path_parts)
    rev = self._getrev(rev)
    path_type = self.itemtype(path_parts, rev)  # does auth-check
    fsroot = self._getroot(rev)

    # Symlinks must be files with the svn:special property set on them
    # and with file contents which read "link SOME_PATH".
    if path_type != vclib.FILE:
      return None
    props = fs.node_proplist(fsroot, path)
    if not props.has_key(core.SVN_PROP_SPECIAL):
      return None
    pathspec = ''
    ### FIXME: We're being a touch sloppy here, only checking the first line
    ### of the file.
    stream = fs.file_contents(fsroot, path)
    try:
      pathspec, eof = core.svn_stream_readline(stream, '\n')
    finally:
      core.svn_stream_close(stream)
    if pathspec[:5] != 'link ':
      return None
    return pathspec[5:]
示例#4
0
    def close_file(self, file_baton, text_checksum):
        changed, path = file_baton
        if len(path) < 3 or path[-3:] != ".po" or not changed:
            # This is not a .po file, or it hasn't changed
            return

        try:
            # Read the file contents through a validating UTF-8 decoder
            subpool = core.svn_pool_create(self.pool)
            checker = MsgFmtChecker()
            try:
                stream = core.Stream(fs.file_contents(self.txn_root, path, subpool))
                reader = codecs.getreader("UTF-8")(stream, "strict")
                writer = codecs.getwriter("UTF-8")(checker, "strict")
                while 1:
                    data = reader.read(core.SVN_STREAM_CHUNK_SIZE)
                    if not data:
                        break
                    writer.write(data)
                if not checker.close():
                    sys.exit("PO format check failed for '" + path + "'")
            except UnicodeError:
                sys.exit("PO file is not in UTF-8: '" + path + "'")
        finally:
            core.svn_pool_destroy(subpool)
示例#5
0
    def get_symlink_target(self, path_parts, rev):
        """Return the target of the symbolic link versioned at PATH_PARTS
        in REV, or None if that object is not a symlink."""

        path = self._getpath(path_parts)
        rev = self._getrev(rev)
        path_type = self.itemtype(path_parts, rev)  # does auth-check
        fsroot = self._getroot(rev)

        # Symlinks must be files with the svn:special property set on them
        # and with file contents which read "link SOME_PATH".
        if path_type != vclib.FILE:
            return None
        props = fs.node_proplist(fsroot, path)
        if core.SVN_PROP_SPECIAL not in props:
            return None
        pathspec = ""
        # FIXME: We're being a touch sloppy here, only checking the first
        # line of the file.
        stream = fs.file_contents(fsroot, path)
        try:
            pathspec, eof = core.svn_stream_readline(stream, b"\n")
        finally:
            core.svn_stream_close(stream)
        if pathspec[:5] != "link ":
            return None
        return pathspec[5:]
示例#6
0
文件: blame.py 项目: Ranga123/test1
def blame(path, filename, rev=None):

  annotresult = {}
  path = core.svn_path_canonicalize(path)

  repos_ptr = repos.open(path)
  fsob = repos.fs(repos_ptr)

  if rev is None:
    rev = fs.youngest_rev(fsob)
  filedata = ''
  for i in range(0, rev+1):
    root = fs.revision_root(fsob, i)
    if fs.check_path(root, filename) != core.svn_node_none:
      first = i
      break
  print("First revision is %d" % first)
  print("Last revision is %d" % rev)
  for i in range(first, rev+1):
    previousroot = root
    root = fs.revision_root(fsob, i)
    if i != first:
      if not fs.contents_changed(root, filename, previousroot, filename):
        continue

    file = fs.file_contents(root, filename)
    previousdata = filedata
    filedata = ''
    while True:
      data = core.svn_stream_read(file, CHUNK_SIZE)
      if not data:
        break
      filedata = filedata + data

    print("Current revision is %d" % i)
    diffresult = difflib.ndiff(previousdata.splitlines(1),
                               filedata.splitlines(1))
    #    print ''.join(diffresult)
    k = 0
    for j in diffresult:
      if j[0] == ' ':
        if k in annotresult:
          k = k + 1
          continue
        else:
          annotresult[k] = (i, j[2:])
          k = k + 1
          continue
      elif j[0] == '?':
        continue
      annotresult[k] = (i, j[2:])
      if j[0] != '-':
        k = k + 1
#    print ''.join(diffresult)
#  print annotresult
  for x in range(len(annotresult.keys())):
     sys.stdout.write("Line %d (r%d):%s" % (x,
                                            annotresult[x][0],
                                            annotresult[x][1]))
示例#7
0
 def get_content(self):
     if self.isdir:
         return None
     s = core.Stream(fs.file_contents(self.root, self._scoped_path_utf8, self.pool()))
     # Make sure the stream object references the pool to make sure the pool
     # is not destroyed before the stream object.
     s._pool = self.pool
     return s
示例#8
0
 def get_content(self):
     if self.isdir:
         return None
     s = core.Stream(fs.file_contents(self.root, self._scoped_svn_path,
                                      self.pool()))
     
     s._pool = self.pool
     return s
示例#9
0
 def get_content(self):
     if self.isdir:
         return None
     s = core.Stream(fs.file_contents(self.root, self._scoped_path_utf8,
                                      self.pool()))
     # Make sure the stream object references the pool to make sure the pool
     # is not destroyed before the stream object.
     s._pool = self.pool
     return s
示例#10
0
 def get_content(self):
     """Retrieve raw content as a "read()"able object."""
     if self.isdir:
         return None
     s = core.Stream(
         fs.file_contents(self.root, self._scoped_path_utf8, self.pool()))
     # The stream object needs to reference the pool to make sure the pool
     # is not destroyed before the former.
     s._pool = self.pool
     return s
示例#11
0
文件: svn_fs.py 项目: trac-ja/trac-ja
 def get_content(self):
     """Retrieve raw content as a "read()"able object."""
     if self.isdir:
         return None
     s = core.Stream(fs.file_contents(self.root, self._scoped_path_utf8,
                                      self.pool()))
     # The stream object needs to reference the pool to make sure the pool
     # is not destroyed before the former.
     s._pool = self.pool
     return s
示例#12
0
 def retrieve_file(self, file_name, rev=None):
     """
     Retrieves the given file name, at the specified revision or
     the latest available from the SVN 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)
     if rev is None:
         rev = fs.youngest_rev(fs_ptr)
     root = fs.revision_root(fs_ptr, rev)
     stream = fs.file_contents(root, file_name)
     svn_file = core.Stream(stream)
     core.svn_stream_close(stream)
     return svn_file
示例#13
0
 def retrieve_file(self, file_name, rev=None):
     """
     Retrieves the given file name, at the specified revision or
     the latest available from the SVN 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)
     if rev is None:
         rev = fs.youngest_rev(fs_ptr)
     root = fs.revision_root(fs_ptr, rev)
     stream = fs.file_contents(root, file_name)
     svn_file = core.Stream(stream)
     core.svn_stream_close(stream)
     return svn_file
示例#14
0
def getfile(path, filename, rev=None):
    path = core.svn_path_canonicalize(path)
    repos_ptr = repos.open(path)
    fsob = repos.fs(repos_ptr)

    if rev is None:
        rev = fs.youngest_rev(fsob)
        print("Using youngest revision %s" % rev)

    root = fs.revision_root(fsob, rev)
    file = fs.file_contents(root, filename)
    while True:
        data = core.svn_stream_read(file, CHUNK_SIZE)
        if not data:
            break
        sys.stdout.write(data)
示例#15
0
def getfile(path, filename, rev=None):
  path = core.svn_path_canonicalize(path)
  repos_ptr = repos.open(path)
  fsob = repos.fs(repos_ptr)

  if rev is None:
    rev = fs.youngest_rev(fsob)
    print("Using youngest revision %s" % rev)

  root = fs.revision_root(fsob, rev)
  file = fs.file_contents(root, filename)
  while 1:
    data = core.svn_stream_read(file, CHUNK_SIZE)
    if not data:
      break
    sys.stdout.write(data)
示例#16
0
def temp_checkout(svnrepos, path, rev):
  """Check out file revision to temporary file"""
  temp = tempfile.mktemp()
  fp = open(temp, 'wb')
  try:
    root = svnrepos._getroot(rev)
    stream = fs.file_contents(root, path)
    try:
      while 1:
        chunk = core.svn_stream_read(stream, core.SVN_STREAM_CHUNK_SIZE)
        if not chunk:
          break
        fp.write(chunk)
    finally:
      core.svn_stream_close(stream)
  finally:
    fp.close()
  return temp
示例#17
0
def temp_checkout(svnrepos, path, rev):
  """Check out file revision to temporary file"""
  temp = tempfile.mktemp()
  fp = open(temp, 'wb')
  try:
    root = svnrepos._getroot(rev)
    stream = fs.file_contents(root, path)
    try:
      while 1:
        chunk = core.svn_stream_read(stream, core.SVN_STREAM_CHUNK_SIZE)
        if not chunk:
          break
        fp.write(chunk)
    finally:
      core.svn_stream_close(stream)
  finally:
    fp.close()
  return temp
示例#18
0
 def itemreadme(self, path_parts, rev):
   path = self._getpath(path_parts)
   path_type = self.itemtype(path_parts, rev)  # does auth-check
   rev = self._getrev(rev)
   fsroot = self._getroot(rev)
   try:
     contenido = fs.file_contents(fsroot, path + '/Readme.md')
   except Exception:
     return None 
   texto = ""
   while 1:
     # int() waiting for proper fix http://trac.edgewall.org/ticket/10722
     data = core.svn_stream_read(contenido, int(core.SVN_STREAM_CHUNK_SIZE))
     texto = texto + data
     if len(data) < core.SVN_STREAM_CHUNK_SIZE:
         break
   core.svn_stream_close(contenido)
   return texto
示例#19
0
def getfile(pool, path, rev=None, home='.'):

    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)

    if rev is None:
        rev = fs.youngest_rev(fsob, pool)

    root = fs.revision_root(fsob, rev, pool)
    file = fs.file_contents(root, path, pool)
    while 1:
        data = util.svn_stream_read(file, CHUNK_SIZE)
        if not data:
            break
        sys.stdout.write(data)
示例#20
0
文件: svn_fs.py 项目: pkdevbox/trac
 def __init__(self, node, keyword_substitution=None, eol=None):
     self.translated = ''
     self.buffer = ''
     self.repos = node.repos
     self.node = node
     self.fs_ptr = node.fs_ptr
     self.pool = Pool()
     # Note: we _must_ use a detached pool here, as the lifetime of
     # this object can exceed those of the node or even the repository
     if keyword_substitution:
         self.keywords = self._get_keyword_values(
                                     node._get_prop(core.SVN_PROP_KEYWORDS))
         self.keywords_re = self._build_keywords_re(self.keywords)
     if self.NEWLINES.get(eol, '\n') != '\n' and \
        node._get_prop(core.SVN_PROP_EOL_STYLE) == 'native':
         self.native_eol = True
         self.newline = self.NEWLINES[eol]
     self.stream = core.Stream(fs.file_contents(node.root,
                                                node._scoped_path_utf8,
                                                self.pool()))
示例#21
0
文件: svnshell.py 项目: lysine/wasp
 def do_cat(self, arg):
   """dump the contents of a file"""
   if not len(arg):
     print("You must supply a file path.")
     return
   catpath = self._parse_path(arg)
   kind = fs.check_path(self.root, catpath)
   if kind == core.svn_node_none:
     print("Path '%s' does not exist." % catpath)
     return
   if kind == core.svn_node_dir:
     print("Path '%s' is not a file." % catpath)
     return
   ### be nice to get some paging in here.
   stream = fs.file_contents(self.root, catpath)
   while True:
     data = core.svn_stream_read(stream, core.SVN_STREAM_CHUNK_SIZE)
     sys.stdout.write(data)
     if len(data) < core.SVN_STREAM_CHUNK_SIZE:
       break
示例#22
0
 def __init__(self, node, keyword_substitution=None, eol=None):
     self.translated = ''
     self.buffer = ''
     self.repos = node.repos
     self.node = node
     self.fs_ptr = node.fs_ptr
     self.pool = Pool()
     # Note: we _must_ use a detached pool here, as the lifetime of
     # this object can exceed those of the node or even the repository
     if keyword_substitution:
         keywords = (node._get_prop(core.SVN_PROP_KEYWORDS) or '').split()
         self.keywords = self._get_keyword_values(
             set(keywords) & set(self.KEYWORDS))
         self.keywords_re = self._build_keywords_re(self.keywords)
     if self.NEWLINES.get(eol, '\n') != '\n' and \
        node._get_prop(core.SVN_PROP_EOL_STYLE) == 'native':
         self.native_eol = True
         self.newline = self.NEWLINES[eol]
     self.stream = core.Stream(
         fs.file_contents(node.root, node._scoped_path_utf8, self.pool()))
示例#23
0
 def do_cat(self, arg):
   """dump the contents of a file"""
   if not len(arg):
     print("You must supply a file path.")
     return
   catpath = self._parse_path(arg)
   kind = fs.check_path(self.root, catpath)
   if kind == core.svn_node_none:
     print("Path '%s' does not exist." % catpath)
     return
   if kind == core.svn_node_dir:
     print("Path '%s' is not a file." % catpath)
     return
   ### be nice to get some paging in here.
   stream = fs.file_contents(self.root, catpath)
   while True:
     data = core.svn_stream_read(stream, core.SVN_STREAM_CHUNK_SIZE)
     sys.stdout.write(data)
     if len(data) < core.SVN_STREAM_CHUNK_SIZE:
       break
示例#24
0
    def close_file(self, file_baton, text_checksum):
        changed, path = file_baton
        if len(path) < 3 or path.lower()[-3:] != '.py' or not changed:
            # This is not a .py file, don't care about tabs
            # TODO - only look inside trunk
            return
 
        # Read the file contents through a tab-finder
        subpool = core.svn_pool_create(self.pool)
 
        stream = core.Stream(fs.file_contents(self.txn_root, path, subpool))
 
        data = stream.read()  # core.SVN_STREAM_CHUNK_SIZE)
        for line in data.splitlines():
            if _tabs.match(line):
                core.svn_pool_destroy(subpool)
                msg = ("Python file contains lines that begin with tabs: '%s'\n" 
                       "There may be others as well." % (path,))
                sys.stderr.write(msg)
                sys.exit(1)
 
        core.svn_pool_destroy(subpool)
示例#25
0
    def close_file(self, file_baton, text_checksum):
        changed, path = file_baton
        if len(path) < 3 or path.lower()[-3:] != '.py' or not changed:
            # This is not a .py file, don't care about tabs
            # TODO - only look inside trunk
            return

        # Read the file contents through a tab-finder
        subpool = core.svn_pool_create(self.pool)

        stream = core.Stream(fs.file_contents(self.txn_root, path, subpool))

        data = stream.read()  # core.SVN_STREAM_CHUNK_SIZE)
        for line in data.splitlines():
            if _tabs.match(line):
                core.svn_pool_destroy(subpool)
                msg = (
                    "Python file contains lines that begin with tabs: '%s'\n"
                    "There may be others as well." % (path, ))
                sys.stderr.write(msg)
                sys.exit(1)

        core.svn_pool_destroy(subpool)
示例#26
0
    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)
示例#27
0
 def __init__(self, root, path, pool):
     self._pool = core.svn_pool_create(pool)
     self._stream = fs.file_contents(root, path, self._pool)
     self._eof = 0
示例#28
0
 def get_content(self):
     if self.isdir:
         return None
     return core.Stream(fs.file_contents(self.root, self.scoped_path))
示例#29
0
 def __init__(self, root, path):
     self.readable = True
     self._stream = fs.file_contents(root, path)
     self._eof = 0