def _get_prop_diff(self, path):
    """Get property changes as a GNU-style diff."""
    try:
      root_props = fs.node_proplist(self.root, path)
    except:
      root_props = []

    try:
      base_props = fs.node_proplist(self.base_root, path)
    except:
      base_props = []

    file_props = list(itertools.chain(base_props, root_props))
    diff_content = ''

    file_props.sort()

    for prop_name in file_props:
      try:
        old_prop_val = fs.node_prop(self.base_root, path, prop_name)
      except core.SubversionException:
        old_prop_val = None
        pass # Must be a new path

      try:
        new_prop_val = fs.node_prop(self.root, path, prop_name)
      except core.SubversionException:
        new_prop_val = None
        pass # Must be a deleted path

      if not old_prop_val == new_prop_val:
        diff = StringIO.StringIO()

        diff.write("Property changes on: %s\n" % path)
        diff.write("_______________________________________________________" + \
                   "_______________________\n")

        if old_prop_val:
          if new_prop_val:
            diff.write("Modified: %s\n" % prop_name)
            diff.write("   - %s\n" % str(old_prop_val))
            diff.write("   + %s\n" % str(new_prop_val))
          else:
            diff.write("Deleted: %s\n" % prop_name)
            diff.write("   - %s\n" % str(old_prop_val))
        else:
          diff.write("Added: %s\n" % prop_name)
          diff.write("   + %s\n" % str(new_prop_val))

        diff.write("\n")

        diff_content = diff_content + diff.getvalue()

        diff.close()

    return diff_content
Example #2
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:]
Example #3
0
 def get_properties(self):
     props = fs.node_proplist(self.root, self._scoped_path_utf8, self.pool())
     for name, value in props.items():
         # Note that property values can be arbitrary binary values
         # so we can't assume they are UTF-8 strings...
         props[_from_svn(name)] = to_unicode(value)
     return props
Example #4
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:]
Example #5
0
def print_props(root, path):
  raw_props = fs.node_proplist(root, path)
  # need to massage some buffers into strings for printing
  props = { }
  for key, value in raw_props.items():
    props[key] = str(value)

  print '---', path
  pprint.pprint(props)
Example #6
0
def print_props(root, path):
  raw_props = fs.node_proplist(root, path)
  # need to massage some buffers into strings for printing
  props = { }
  for key, value in raw_props.items():
    props[key] = str(value)

  print '---', path
  pprint.pprint(props)
Example #7
0
File: svn_fs.py Project: t2y/trac
    def get_properties(self):
        """Return `dict` of node properties at current revision.

        (wraps ``fs.node_proplist``)
        """
        props = fs.node_proplist(self.root, self._scoped_path_utf8, self.pool())
        for name, value in props.items():
            # Note that property values can be arbitrary binary values
            # so we can't assume they are UTF-8 strings...
            props[_from_svn(name)] = to_unicode(value)
        return props
Example #8
0
    def get_properties(self):
        """Return `dict` of node properties at current revision.

        (wraps ``fs.node_proplist``)
        """
        props = fs.node_proplist(self.root, self._scoped_path_utf8, self.pool())
        for name, value in props.items():
            # Note that property values can be arbitrary binary values
            # so we can't assume they are UTF-8 strings...
            props[_from_svn(name)] = to_unicode(value)
        return props
Example #9
0
 def itemprops(self, path_parts, rev):
     path = self._getpath(path_parts)
     self.itemtype(path_parts, rev)  # does auth-check
     rev = self._getrev(rev)
     fsroot = self._getroot(rev)
     proptable = fs.node_proplist(fsroot, path)
     propdict = {}
     for pname in proptable.keys():
         pvalue = proptable[pname]
         pname, pvalue = _normalize_property(pname, pvalue, self.encoding)
         if pname:
             propdict[pname] = pvalue
     return propdict
Example #10
0
 def do_pcat(self, arg):
   """list the properties of a path"""
   catpath = self.path
   if len(arg):
     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
   plist = fs.node_proplist(self.root, catpath)
   if not plist:
     return
   for pkey, pval in plist.items():
     print('K ' + str(len(pkey)))
     print(pkey)
     print('P ' + str(len(pval)))
     print(pval)
   print('PROPS-END')
Example #11
0
 def do_pcat(self, arg):
   """list the properties of a path"""
   catpath = self.path
   if len(arg):
     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
   plist = fs.node_proplist(self.root, catpath)
   if not plist:
     return
   for pkey, pval in plist.items():
     print('K ' + str(len(pkey)))
     print(pkey)
     print('P ' + str(len(pval)))
     print(pval)
   print('PROPS-END')
Example #12
0
 def get_properties(self):
     props = fs.node_proplist(self.root, self.scoped_path)
     for name,value in props.items():
         props[name] = str(value) # Make sure the value is a proper string
     return props
Example #13
0
 def get_properties(self):
     props = fs.node_proplist(self.root, self._scoped_svn_path, self.pool())
     for name, value in props.items():
         props[_from_svn(name)] = to_unicode(value, 'utf-8')
     return props
Example #14
0
def MakeRecordsFromPath(srcrepo, srcrev, srcpath, dstpath, record_source):
  """Generate Records adding the contents of a given repo/rev/path.

  Args:
    srcrepo: path to the source repository
    srcrev: revision number
    srcpath: path within the source repository
    dstpath: destination path in the repository being filtered
    record_source: the source attribute of the Records generated

  Returns:
    a list of Records

  Raises:
    RuntimeError: if svnrdump seems to have failed

  This is the fundamental feature of a working svndumpfilter replacement. In the
  upstream svndumpfilter, copyfrom operations that reference paths that are
  excluded by filtering cannot be resolved. To fix that, each svndumpfilter
  replacement must find a way to turn that copy operation into a series of add
  operations.

  svndumpfilter2 originally did this by calling the svnlook utility
  to list the directory structure, grab file contents, list property names, and
  grab property values. This resulted in calling svnlook once per tree, twice
  per file, and once per property.

  For a time, we tried instead making a single call to svnrdump which, unlike
  svnadmin dump (which is used by svndumpfilter3 with disastrous results for
  performance) can output a dump file containing only the desired subdirectory.
  The dump file is parsed into Records, the paths have the destination path
  prepended, and the Records are inserted into the dump.

  Unfortunately, svnrdump always produces format 3 dumps which use deltas. Even
  though it was only used for a single non-incremental revision, every file's
  contents were in the form of a delta. Since some tools (such as p4convert-svn)
  do not support deltas, svnrdump was done away with, replaced by the SVN SWIG
  bindings.

  It turns out that this same functionality is critical to 'internalizing' SVN
  externals. By generating Records that add all of the files and directories in
  the repo/rev/path referenced by an svn:external property, the history can be
  made to look as though the actual files had been there all along, not just a
  reference to them. Further filtering of these generated Records must be done
  in the case of externals to delete externals when they are removed and modify
  the filesystem when the revision is changed, rather than deleting and reading
  it every time (see externals.FromRev, externals.Diff, Diff).
  """
  srcrepo = svn_core.svn_path_canonicalize(srcrepo)
  repo_ptr = svn_repos.open(srcrepo)
  fs = svn_repos.fs(repo_ptr)
  root = svn_fs.revision_root(fs, srcrev)
  output = []
  # Perform a depth-first search
  stack = [srcpath]
  while stack:
    path = stack.pop()
    if srcpath:
      relative_path = path[len(srcpath):]
      node_path = dstpath + relative_path
    else:
      node_path = (dstpath + '/' + path) if path else dstpath
    if svn_fs.is_dir(root, path):
      record = Record(action='add', kind='dir', path=node_path,
                      source=record_source)
      # Add children to the stack
      prefix = (path + '/') if path else ''
      for name in svn_fs.dir_entries(root, path).keys():
        stack.append(prefix + name)
    else:
      record = Record(action='add', kind='file', path=node_path,
                      source=record_source)
      # Fetch file content
      stream = svn_fs.file_contents(root, path)
      record.text = _ReadSVNStream(stream)
      checksum = svn_fs.file_md5_checksum(root, path)
      record.headers['Text-content-md5'] = checksum.encode('hex_codec')
    # Fetch properties
    props = svn_fs.node_proplist(root, path)
    record.props = {key: str(value) for key, value in props.iteritems()}
    output.append(record)
  return output
Example #15
0
 def get_properties(self):
     props = fs.node_proplist(self.root, self.scoped_path)
     for name, value in core._as_list(props.items()):
         props[name] = value
     return props
Example #16
0
 def itemprops(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)
   return fs.node_proplist(fsroot, path)
Example #17
0
 def get_properties(self):
     props = fs.node_proplist(self.root, self.scoped_path)
     for name, value in props.items():
         props[name] = str(value)  # Make sure the value is a proper string
     return props
Example #18
0
 def itemprops(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)
     return fs.node_proplist(fsroot, path)