Пример #1
0
Файл: svn_fs.py Проект: t2y/trac
 def get_copy_ancestry(self):
     """Retrieve the list of `(path,rev)` copy ancestors of this node.
     Most recent ancestor first. Each ancestor `(path, rev)` corresponds
     to the path and revision of the source at the time the copy or move
     operation was performed.
     """
     ancestors = []
     previous = (self._scoped_path_utf8, self.rev, self.root)
     while previous:
         (previous_path, previous_rev, previous_root) = previous
         previous = None
         root_path = fs.closest_copy(previous_root, previous_path)
         if root_path:
             (root, path) = root_path
             path = path.lstrip('/')
             rev = fs.revision_root_revision(root)
             relpath = None
             if path != previous_path:
                 # `previous_path` is a subfolder of `path` and didn't
                 # change since `path` was copied
                 relpath = previous_path[len(path):].strip('/')
             copied_from = fs.copied_from(root, path)
             if copied_from:
                 (rev, path) = copied_from
                 path = path.lstrip('/')
                 root = fs.revision_root(self.fs_ptr, rev, self.pool())
                 if relpath:
                     path += '/' + relpath
                 ui_path = _path_within_scope(self.scope, _from_svn(path))
                 if ui_path:
                     ancestors.append((ui_path, rev))
                 previous = (path, rev, root)
     return ancestors
Пример #2
0
 def get_copy_ancestry(self):
     """Retrieve the list of `(path,rev)` copy ancestors of this node.
     Most recent ancestor first. Each ancestor `(path, rev)` corresponds
     to the path and revision of the source at the time the copy or move
     operation was performed.
     """
     ancestors = []
     previous = (self._scoped_path_utf8, self.rev, self.root)
     while previous:
         (previous_path, previous_rev, previous_root) = previous
         previous = None
         root_path = fs.closest_copy(previous_root, previous_path)
         if root_path:
             (root, path) = root_path
             path = path.lstrip('/')
             rev = fs.revision_root_revision(root)
             relpath = None
             if path != previous_path:
                 # `previous_path` is a subfolder of `path` and didn't
                 # change since `path` was copied
                 relpath = previous_path[len(path):].strip('/')
             copied_from = fs.copied_from(root, path)
             if copied_from:
                 (rev, path) = copied_from
                 path = path.lstrip('/')
                 root = fs.revision_root(self.fs_ptr, rev, self.pool())
                 if relpath:
                     path += '/' + relpath
                 ui_path = _path_within_scope(self.scope, _from_svn(path))
                 if ui_path:
                     ancestors.append((ui_path, rev))
                 previous = (path, rev, root)
     return ancestors
Пример #3
0
    def add_history(self, path, revision, pool):
        # If filtering, only add the path and revision to the histories
        # list if they were actually changed in this revision (where
        # change means the path itself was changed, or one of its parents
        # was copied).  This is useful for omitting bubble-up directory
        # changes.
        if not self.oldest_rev:
            self.oldest_rev = revision
        else:
            assert revision < self.oldest_rev

        if not self.show_all_logs:
            rev_root = fs.revision_root(self.fs_ptr, revision)
            paths = list(fs.paths_changed2(rev_root).keys())
            if path not in paths:
                # Look for a copied parent
                test_path = path
                found = 0
                while 1:
                    off = test_path.rfind("/")
                    if off < 0:
                        break
                    test_path = test_path[0:off]
                    if test_path in paths:
                        copyfrom_rev, copyfrom_path = fs.copied_from(
                            rev_root, test_path)
                        if copyfrom_rev >= 0 and copyfrom_path:
                            found = 1
                            break
                if not found:
                    return
        self.histories.append([revision, _cleanup_path(path)])
        if self.limit and len(self.histories) == self.limit:
            raise core.SubversionException("", core.SVN_ERR_CEASE_INVOCATION)
Пример #4
0
 def add_history(self, path, revision, pool):
     # If filtering, only add the path and revision to the histories
     # list if they were actually changed in this revision (where
     # change means the path itself was changed, or one of its parents
     # was copied).  This is useful for omitting bubble-up directory
     # changes.
     if not self.show_all_logs:
         rev_root = fs.revision_root(self.fs_ptr, revision, pool)
         changed_paths = fs.paths_changed(rev_root, pool)
         paths = changed_paths.keys()
         if path not in paths:
             # Look for a copied parent
             test_path = path
             found = 0
             subpool = core.svn_pool_create(pool)
             while 1:
                 core.svn_pool_clear(subpool)
                 off = string.rfind(test_path, '/')
                 if off < 0:
                     break
                 test_path = test_path[0:off]
                 if test_path in paths:
                     copyfrom_rev, copyfrom_path = \
                                   fs.copied_from(rev_root, test_path, subpool)
                     if copyfrom_rev >= 0 and copyfrom_path:
                         found = 1
                         break
             core.svn_pool_destroy(subpool)
             if not found:
                 return
     self.histories[revision] = _cleanup_path(path)
Пример #5
0
 def add_history(self, path, revision, pool):
   # If filtering, only add the path and revision to the histories
   # list if they were actually changed in this revision (where
   # change means the path itself was changed, or one of its parents
   # was copied).  This is useful for omitting bubble-up directory
   # changes.
   if not self.oldest_rev:
     self.oldest_rev = revision
   else:
     assert(revision < self.oldest_rev)
     
   if not self.show_all_logs:
     rev_root = fs.revision_root(self.fs_ptr, revision)
     changed_paths = fs.paths_changed(rev_root)
     paths = changed_paths.keys()
     if path not in paths:
       # Look for a copied parent
       test_path = path
       found = 0
       while 1:
         off = test_path.rfind('/')
         if off < 0:
           break
         test_path = test_path[0:off]
         if test_path in paths:
           copyfrom_rev, copyfrom_path = fs.copied_from(rev_root, test_path)
           if copyfrom_rev >= 0 and copyfrom_path:
             found = 1
             break
       if not found:
         return
   self.histories.append([revision, _cleanup_path(path)])
   if self.limit and len(self.histories) == self.limit:
     raise core.SubversionException("", _SVN_ERR_CEASE_INVOCATION)
Пример #6
0
 def add_history(self, path, revision, pool):
   # If filtering, only add the path and revision to the histories
   # list if they were actually changed in this revision (where
   # change means the path itself was changed, or one of its parents
   # was copied).  This is useful for omitting bubble-up directory
   # changes.
   if not self.show_all_logs:
     rev_root = fs.revision_root(self.fs_ptr, revision, pool)
     changed_paths = fs.paths_changed(rev_root, pool)
     paths = changed_paths.keys()
     if path not in paths:
       # Look for a copied parent
       test_path = path
       found = 0
       subpool = core.svn_pool_create(pool)
       while 1:
         core.svn_pool_clear(subpool)
         off = string.rfind(test_path, '/')
         if off < 0:
           break
         test_path = test_path[0:off]
         if test_path in paths:
           copyfrom_rev, copyfrom_path = \
                         fs.copied_from(rev_root, test_path, subpool)
           if copyfrom_rev >= 0 and copyfrom_path:
             found = 1
             break
       core.svn_pool_destroy(subpool)
       if not found:
         return
   self.histories[revision] = _cleanup_path(path)
Пример #7
0
 def _get_change_copyinfo(fsroot, path, change):
     if hasattr(change, 'copyfrom_known') and change.copyfrom_known:
         copyfrom_path = change.copyfrom_path
         copyfrom_rev = change.copyfrom_rev
     else:
         copyfrom_rev, copyfrom_path = fs.copied_from(fsroot, path)
     return copyfrom_path, copyfrom_rev
Пример #8
0
 def _get_change_copyinfo(fsroot, path, change):
   if hasattr(change, 'copyfrom_known') and change.copyfrom_known:
     copyfrom_path = change.copyfrom_path
     copyfrom_rev = change.copyfrom_rev
   else:
     copyfrom_rev, copyfrom_path = fs.copied_from(fsroot, path)
   return copyfrom_path, copyfrom_rev
Пример #9
0
 def _log_helper(self, path, rev, lockinfo):
     rev_root = fs.revision_root(self.fs_ptr, rev)
     copyfrom_rev, copyfrom_path = fs.copied_from(rev_root, path)
     date, author, msg, revprops, changes = self._revinfo(rev)
     if fs.is_file(rev_root, path):
         size = fs.file_length(rev_root, path)
     else:
         size = None
     return Revision(rev, date, author, msg, size, lockinfo, path,
                     copyfrom_path and _cleanup_path(copyfrom_path),
                     copyfrom_rev)
Пример #10
0
 def _log_helper(self, path, rev, lockinfo):
   rev_root = fs.revision_root(self.fs_ptr, rev)
   copyfrom_rev, copyfrom_path = fs.copied_from(rev_root, path)
   date, author, msg, revprops, changes = self._revinfo(rev)
   if fs.is_file(rev_root, path):
     size = fs.file_length(rev_root, path)
   else:
     size = None
   return Revision(rev, date, author, msg, size, lockinfo, path,
                   copyfrom_path and _cleanup_path(copyfrom_path),
                   copyfrom_rev)
Пример #11
0
 def _get_change_copyinfo(fsroot, path, change):
     # If we know the copyfrom info, return it...
     if change.copyfrom_known:
         copyfrom_path = change.copyfrom_path
         copyfrom_rev = change.copyfrom_rev
     # ...otherwise, if this change could be a copy (that is, it
     # contains an add action), query the copyfrom info ...
     elif (change.change_kind == fs.path_change_replace
           or change.change_kind == fs.path_change_add):
         copyfrom_rev, copyfrom_path = fs.copied_from(fsroot, path)
     # ...else, there's no copyfrom info.
     else:
         copyfrom_rev = core.SVN_INVALID_REVNUM
         copyfrom_path = None
     return copyfrom_path, copyfrom_rev
Пример #12
0
 def _get_change_copyinfo(fsroot, path, change):
   # If we know the copyfrom info, return it...
   if hasattr(change, 'copyfrom_known') and change.copyfrom_known:
     copyfrom_path = change.copyfrom_path
     copyfrom_rev = change.copyfrom_rev
   # ...otherwise, if this change could be a copy (that is, it
   # contains an add action), query the copyfrom info ...
   elif (change.change_kind == fs.path_change_add or
         change.change_kind == fs.path_change_replace):
     copyfrom_rev, copyfrom_path = fs.copied_from(fsroot, path)
   # ...else, there's no copyfrom info.
   else:
     copyfrom_rev = core.SVN_INVALID_REVNUM
     copyfrom_path = None
   return copyfrom_path, copyfrom_rev
Пример #13
0
def _log_helper(svnrepos, rev, path, pool):
    rev_root = fs.revision_root(svnrepos.fs_ptr, rev, pool)

    # Was this path@rev the target of a copy?
    copyfrom_rev, copyfrom_path = fs.copied_from(rev_root, path, pool)

    # Assemble our LogEntry
    datestr, author, msg = _fs_rev_props(svnrepos.fs_ptr, rev, pool)
    date = _datestr_to_date(datestr, pool)
    if fs.is_file(rev_root, path, pool):
        size = fs.file_length(rev_root, path, pool)
    else:
        size = None
    entry = Revision(rev, date, author, msg, size, path, copyfrom_path
                     and _cleanup_path(copyfrom_path), copyfrom_rev)
    return entry
Пример #14
0
def _log_helper(svnrepos, rev, path, pool):
  rev_root = fs.revision_root(svnrepos.fs_ptr, rev, pool)

  # Was this path@rev the target of a copy?
  copyfrom_rev, copyfrom_path = fs.copied_from(rev_root, path, pool)

  # Assemble our LogEntry
  datestr, author, msg = _fs_rev_props(svnrepos.fs_ptr, rev, pool)
  date = _datestr_to_date(datestr, pool)
  if fs.is_file(rev_root, path, pool):
    size = fs.file_length(rev_root, path, pool)
  else:
    size = None
  entry = Revision(rev, date, author, msg, size, path,
                   copyfrom_path and _cleanup_path(copyfrom_path),
                   copyfrom_rev)
  return entry
Пример #15
0
def validate_added_extensions(repos_path, txn_name, extensions, action):
    # Open the repository and transaction.
    fs_ptr = repos.fs(repos.open(repos_path))
    txn_t = fs.open_txn(fs_ptr, txn_name)
    txn_root = fs.txn_root(txn_t)

    # Fetch the changes made in this transaction.
    changes = fs.svn_fs_paths_changed(txn_root)
    paths = changes.keys()

    # Check the changes.
    for path in paths:
        change = changes[path]

        # Always allow deletions.
        if change.change_kind == fs.path_change_delete:
            continue

        # Always allow non-files.
        kind = fs.check_path(txn_root, path)
        if kind != core.svn_node_file:
            continue

        # If this was a newly added (without history) file ...
        if ((change.change_kind == fs.path_change_replace) \
            or (change.change_kind == fs.path_change_add)):
            copyfrom_rev, copyfrom_path = fs.copied_from(txn_root, path)
            if copyfrom_rev == core.SVN_INVALID_REVNUM:

                # ... then check it for a valid extension.
                base, ext = os.path.splitext(path)
                if ext:
                    ext = ext[1:].lower()
                if ((ext in extensions) and (action == 'deny')) \
                   or ((ext not in extensions) and (action == 'allow')):
                    sys.stderr.write(
                        "Path '%s' has an extension disallowed by server "
                        "configuration.\n" % (path))
                    sys.exit(1)
Пример #16
0
def validate_added_extensions(repos_path, txn_name, extensions, action):
  # Open the repository and transaction.
  fs_ptr = repos.fs(repos.open(repos_path))
  txn_t = fs.open_txn(fs_ptr, txn_name)
  txn_root = fs.txn_root(txn_t)

  # Fetch the changes made in this transaction.
  changes = fs.svn_fs_paths_changed(txn_root)
  paths = changes.keys()

  # Check the changes.
  for path in paths:
    change = changes[path]

    # Always allow deletions.
    if change.change_kind == fs.path_change_delete:
      continue

    # Always allow non-files.
    kind = fs.check_path(txn_root, path)
    if kind != core.svn_node_file:
      continue

    # If this was a newly added (without history) file ...
    if ((change.change_kind == fs.path_change_replace) \
        or (change.change_kind == fs.path_change_add)):
      copyfrom_rev, copyfrom_path = fs.copied_from(txn_root, path)
      if copyfrom_rev == core.SVN_INVALID_REVNUM:

        # ... then check it for a valid extension.
        base, ext = os.path.splitext(path)
        if ext:
          ext = ext[1:].lower()
        if ((ext in extensions) and (action == 'deny')) \
           or ((ext not in extensions) and (action == 'allow')):
          sys.stderr.write("Path '%s' has an extension disallowed by server "
                           "configuration.\n" % (path))
          sys.exit(1)