예제 #1
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]))
예제 #2
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]))
예제 #3
0
 def file_contents(self, path):
     """
     Return a string with the content of a file.
     """
     contents = svn_fs_file_contents(self.root, path)
     length = int(svn_fs_file_length(self.root, path))
     data = svn_stream_read(contents, length)
     svn_stream_close(contents)
     return data
예제 #4
0
    def read(self, len=None):
        chunk = None
        if not self._eof:
            if len is None:
                buffer = StringIO()
                try:
                    while 1:
                        hunk = core.svn_stream_read(self._stream, 8192)
                        if not hunk:
                            break
                        buffer.write(hunk)
                    chunk = buffer.getvalue()
                finally:
                    buffer.close()

            else:
                chunk = core.svn_stream_read(self._stream, len)
        if not chunk:
            self._eof = 1
        return chunk
예제 #5
0
  def read(self, len=None):
    chunk = None
    if not self._eof:
      if len is None:
        buffer = cStringIO.StringIO()
        try:
          while 1:
            hunk = core.svn_stream_read(self._stream, 8192)
            if not hunk:
              break
            buffer.write(hunk)
          chunk = buffer.getvalue()
        finally:
          buffer.close()

      else:
        chunk = core.svn_stream_read(self._stream, len)   
    if not chunk:
      self._eof = 1
    return chunk
예제 #6
0
파일: fs.py 프로젝트: svn2github/subversion
 def _dump_contents(self, file, root, path, pool=None):
   fp = builtins.open(file, 'wb') # avoid namespace clash with
                                  # trimmed-down svn_fs_open()
   if path is not None:
     stream = file_contents(root, path, pool)
     try:
       while True:
         chunk = _svncore.svn_stream_read(stream, _svncore.SVN_STREAM_CHUNK_SIZE)
         if not chunk:
           break
         fp.write(chunk)
     finally:
       _svncore.svn_stream_close(stream)
   fp.close()
예제 #7
0
 def _dump_contents(self, file, root, path, pool=None):
   fp = builtins.open(file, 'wb') # avoid namespace clash with
                                  # trimmed-down svn_fs_open()
   if path is not None:
     stream = file_contents(root, path, pool)
     try:
       while True:
         chunk = _svncore.svn_stream_read(stream, _svncore.SVN_STREAM_CHUNK_SIZE)
         if not chunk:
           break
         fp.write(chunk)
     finally:
       _svncore.svn_stream_close(stream)
   fp.close()
예제 #8
0
def main_func(pool, path, filename, rev=None):
  fsobj = fs.open(path, None, pool)

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

  root = fs.revision_root(fsobj, rev, pool)
  filestream = fsobj.file_contents(root, filename, pool)
  while 1:
    data = core.svn_stream_read(file, 1024)
    if not data:
      break
    sys.stdout.write(data)

  fs.close(fsobj)
예제 #9
0
def _ReadSVNStream(stream):
  """Read an entire SVN stream into a string.

  Args:
    stream: an SVN stream

  Returns:
    str containing entire stream
  """
  out = ''
  while True:
    data = svn_core.svn_stream_read(stream, 16384)
    if not data:
      break
    out += data
  return out
예제 #10
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)
예제 #11
0
파일: getfile.py 프로젝트: aosm/subversion
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)
예제 #12
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
예제 #13
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
예제 #14
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
예제 #15
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
예제 #16
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