Example #1
0
 def changes(self):
     """
     Hash table of the changes in the transaction.
     """
     if self._changes is None:
         self._changes = svn_fs_paths_changed(self.root)
     return self._changes
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)
Example #3
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)
Example #4
0
def export_revision(rev, repo, fs, pool):
    sys.stderr.write("Exporting revision %s... " % rev)

    revpool = svn_pool_create(pool)
    svn_pool_clear(revpool)

    # Open a root object representing the youngest (HEAD) revision.
    root = svn_fs_revision_root(fs, rev, revpool)

    # And the list of what changed in this revision.
    changes = svn_fs_paths_changed(root, revpool)

    i = 1
    marks = {}
    file_changes = []

    for path, change_type in changes.iteritems():
        c_t = ct_short[change_type.change_kind]
        if svn_fs_is_dir(root, path, revpool):
            continue

        if not path.startswith(trunk_path):
            # We don't handle branches. Or tags. Yet.
            pass
        else:
            if c_t == 'D':
                file_changes.append("D %s" % path.replace(trunk_path, ''))
            else:
                marks[i] = path.replace(trunk_path, '')
                file_changes.append("M 644 :%s %s" % (i, marks[i]))
                sys.stdout.write("blob\nmark :%s\n" % i)
                dump_file_blob(root, path, revpool)
                i += 1

    # Get the commit author and message
    props = svn_fs_revision_proplist(fs, rev, revpool)

    # Do the recursive crawl.
    if props.has_key('svn:author'):
        author = "%s <%s@localhost>" % (props['svn:author'],
                                        props['svn:author'])
    else:
        author = 'nobody <nobody@localhost>'

    if len(file_changes) == 0:
        svn_pool_destroy(revpool)
        sys.stderr.write("skipping.\n")
        return

    svndate = props['svn:date'][0:-8]
    commit_time = mktime(strptime(svndate, '%Y-%m-%dT%H:%M:%S'))
    sys.stdout.write("commit refs/heads/master\n")
    sys.stdout.write("committer %s %s -0000\n" % (author, int(commit_time)))
    sys.stdout.write("data %s\n" % len(props['svn:log']))
    sys.stdout.write(props['svn:log'])
    sys.stdout.write("\n")
    sys.stdout.write('\n'.join(file_changes))
    sys.stdout.write("\n\n")

    svn_pool_destroy(revpool)

    sys.stderr.write("done!\n")
Example #5
0
def export_revision(rev, repo, fs, pool):
    sys.stderr.write("Exporting revision %s... " % rev)

    revpool = svn_pool_create(pool)
    svn_pool_clear(revpool)

    # Open a root object representing the youngest (HEAD) revision.
    root = svn_fs_revision_root(fs, rev, revpool)

    # And the list of what changed in this revision.
    changes = svn_fs_paths_changed(root, revpool)

    i = 1
    marks = {}
    file_changes = []

    for path, change_type in changes.iteritems():
        c_t = ct_short[change_type.change_kind]
        if svn_fs_is_dir(root, path, revpool):
            continue

        if not path.startswith(trunk_path):
            # We don't handle branches. Or tags. Yet.
            pass
        else:
            if c_t == "D":
                file_changes.append("D %s" % path.replace(trunk_path, ""))
            else:
                marks[i] = path.replace(trunk_path, "")
                file_changes.append("M 644 :%s %s" % (i, marks[i]))
                sys.stdout.write("blob\nmark :%s\n" % i)
                dump_file_blob(root, path, revpool)
                i += 1

    # Get the commit author and message
    props = svn_fs_revision_proplist(fs, rev, revpool)

    # Do the recursive crawl.
    if props.has_key("svn:author"):
        author = "%s <%s@localhost>" % (props["svn:author"], props["svn:author"])
    else:
        author = "nobody <nobody@localhost>"

    if len(file_changes) == 0:
        svn_pool_destroy(revpool)
        sys.stderr.write("skipping.\n")
        return

    svndate = props["svn:date"][0:-8]
    commit_time = mktime(strptime(svndate, "%Y-%m-%dT%H:%M:%S"))
    sys.stdout.write("commit refs/heads/master\n")
    sys.stdout.write("committer %s %s -0000\n" % (author, int(commit_time)))
    sys.stdout.write("data %s\n" % len(props["svn:log"]))
    sys.stdout.write(props["svn:log"])
    sys.stdout.write("\n")
    sys.stdout.write("\n".join(file_changes))
    sys.stdout.write("\n\n")

    svn_pool_destroy(revpool)

    sys.stderr.write("done!\n")