Example #1
0
    def __init__(self, path, rev=None, txn=None, cmd=None):
        """
    path  - path to repository
    rev   - revision number
    txn   - name of transaction (usually the one about to be committed)
    cmd   - if set, specifies cmd_* method to execute

    txn takes precedence over rev; if both are None, inspect the head revision
    """
        path = core.svn_path_canonicalize(path)
        repos_ptr = repos.open(path)
        self.fs_ptr = repos.fs(repos_ptr)

        # if set, txn takes precendence
        if txn:
            self.txn_ptr = fs.open_txn(self.fs_ptr, txn)
        else:
            self.txn_ptr = None
            if rev is None:
                rev = fs.youngest_rev(self.fs_ptr)
            else:
                rev = int(rev)
        self.rev = rev

        if cmd != None:
            getattr(self, 'cmd_' + cmd)()
Example #2
0
  def __init__(self, fs_ptr, root, pool=None, notify_cb=None):
    """Construct a walker over the svn_fs_root_t ROOT, which must
    be in the svn_fs_t FS_PTR.  Invoke NOTIFY_CB with a single argument
    of type ChangedPath for each change under ROOT.

    At this time, two ChangedPath objects will be passed for a path that had
    been replaced in the revision/transaction.  This may change in the future.

    ### Can't we deduce FS_PTR from ROOT?

    ### POOL is unused
    """

    self.fs_ptr = fs_ptr
    self.changes = { } # path -> ChangedPathEntry()
    self.roots = { } # revision -> svn_svnfs_root_t
    self.notify_cb = notify_cb
    self.props = { }
    self.fs_root = root

    # Figger out the base revision and root properties.
    if _svnfs.is_revision_root(self.fs_root):
      rev = _svnfs.revision_root_revision(self.fs_root)
      self.base_rev = rev - 1
      self.props = _svnfs.revision_proplist(self.fs_ptr, rev)
    else:
      txn_name = _svnfs.txn_root_name(self.fs_root)
      txn_t = _svnfs.open_txn(self.fs_ptr, txn_name)
      self.base_rev = _svnfs.txn_base_revision(txn_t)
      self.props = _svnfs.txn_proplist(txn_t)
Example #3
0
def main(pool, repos_dir, txn):
    # Construct a ChangeCollector to fetch our changes.
    fs_ptr = repos.svn_repos_fs(repos.svn_repos_open(repos_dir, pool))
    root = fs.txn_root(fs.open_txn(fs_ptr, txn, pool), pool)
    cc = repos.ChangeCollector(fs_ptr, root, pool)

    # Call the transaction property validator.  Might as well get the
    # cheap checks outta the way first.
    retval = test_props(cc.get_root_props())
    if retval:
        return retval

    # Generate the path-based changes list.
    e_ptr, e_baton = delta.make_editor(cc, pool)
    repos.svn_repos_replay(root, e_ptr, e_baton, pool)

    # Call the path change validator.
    changes = cc.get_changes()
    paths = changes.keys()
    paths.sort(lambda a, b: core.svn_path_compare_paths(a, b))
    for path in paths:
        change = changes[path]
        retval = test_path_change(path, change)
        if retval:
            return retval

    return 0
def main(pool, repos_dir, txn):
  # Construct a ChangeCollector to fetch our changes.
  fs_ptr = repos.svn_repos_fs(repos.svn_repos_open(repos_dir, pool))
  root = fs.txn_root(fs.open_txn(fs_ptr, txn, pool), pool)
  cc = repos.ChangeCollector(fs_ptr, root, pool)

  # Call the transaction property validator.  Might as well get the
  # cheap checks outta the way first.
  retval = test_props(cc.get_root_props())
  if retval:
    return retval

  # Generate the path-based changes list.
  e_ptr, e_baton = delta.make_editor(cc, pool)
  repos.svn_repos_replay(root, e_ptr, e_baton, pool)

  # Call the path change validator.
  changes = cc.get_changes()
  paths = changes.keys()
  paths.sort(lambda a, b: core.svn_path_compare_paths(a, b))
  for path in paths:
    change = changes[path]
    retval = test_path_change(path, change)
    if retval:
      return retval
    
  return 0
Example #5
0
  def __init__(self, path, rev=None, txn=None, cmd=None):
    """
    path  - path to repository
    rev   - revision number
    txn   - name of transaction (usually the one about to be committed)
    cmd   - if set, specifies cmd_* method to execute

    txn takes precedence over rev; if both are None, inspect the head revision
    """
    path = core.svn_path_canonicalize(path)
    repos_ptr = repos.open(path)
    self.fs_ptr = repos.fs(repos_ptr)

    # if set, txn takes precendence
    if txn:
      self.txn_ptr = fs.open_txn(self.fs_ptr, txn)
    else:
      self.txn_ptr = None
      if rev is None:
        rev = fs.youngest_rev(self.fs_ptr)
      else:
        rev = int(rev)
    self.rev = rev

    if cmd != None:
      getattr(self, 'cmd_' + cmd)()
def duplicate_ephemeral_txnprops(repos_path, txn_name):
  fs_ptr = repos.fs(repos.open(repos_path))
  txn_t = fs.open_txn(fs_ptr, txn_name)
  for name, value in fs.txn_proplist(txn_t).items():
    if name.startswith(core.SVN_PROP_TXN_PREFIX):
      name = core.SVN_PROP_REVISION_PREFIX + \
                  name[len(core.SVN_PROP_TXN_PREFIX):]
      fs.change_txn_prop(txn_t, name, value)
def duplicate_ephemeral_txnprops(repos_path, txn_name):
    fs_ptr = repos.fs(repos.open(repos_path))
    txn_t = fs.open_txn(fs_ptr, txn_name)
    for name, value in fs.txn_proplist(txn_t).items():
        if name.startswith(core.SVN_PROP_TXN_PREFIX):
            name = core.SVN_PROP_REVISION_PREFIX + \
                        name[len(core.SVN_PROP_TXN_PREFIX):]
            fs.change_txn_prop(txn_t, name, value)
Example #8
0
def check_po(pool, repos_path, txn):
    def authz_cb(root, path, pool):
        return 1

    fs_ptr = repos.fs(repos.open(repos_path, pool))
    txn_ptr = fs.open_txn(fs_ptr, txn, pool)
    txn_root = fs.txn_root(txn_ptr, pool)
    base_root = fs.revision_root(fs_ptr, fs.txn_base_revision(txn_ptr), pool)
    editor = ChangeReceiver(txn_root, base_root, pool)
    e_ptr, e_baton = delta.make_editor(editor, pool)
    repos.dir_delta(base_root, "", "", txn_root, "", e_ptr, e_baton, authz_cb, 0, 1, 0, 0, pool)
Example #9
0
def check_po(pool, repos_path, txn):
    def authz_cb(root, path, pool):
        return 1

    fs_ptr = repos.fs(repos.open(repos_path, pool))
    txn_ptr = fs.open_txn(fs_ptr, txn, pool)
    txn_root = fs.txn_root(txn_ptr, pool)
    base_root = fs.revision_root(fs_ptr, fs.txn_base_revision(txn_ptr), pool)
    editor = ChangeReceiver(txn_root, base_root, pool)
    e_ptr, e_baton = delta.make_editor(editor, pool)
    repos.dir_delta(base_root, '', '', txn_root, '', e_ptr, e_baton, authz_cb,
                    0, 1, 0, 0, pool)
Example #10
0
 def do_settxn(self, arg):
   """set the current transaction to view"""
   try:
     txnobj = fs.open_txn(self.fs_ptr, arg)
     newroot = fs.txn_root(txnobj)
   except:
     print("Error setting the transaction to '" + arg + "'.")
     return
   fs.close_root(self.root)
   self.root = newroot
   self.txn = arg
   self.is_rev = 0
   self._do_path_landing()
Example #11
0
  def __init__(self, path, cmd, rev, txn):
    repos_ptr = repos.open(path)
    self.fs_ptr = repos.fs(repos_ptr)

    if txn:
      self.txn_ptr = fs.open_txn(self.fs_ptr, txn)
    else:
      self.txn_ptr = None
      if rev is None:
        rev = fs.youngest_rev(self.fs_ptr)
    self.rev = rev

    getattr(self, 'cmd_' + cmd)()
  def __init__(self, pool, path, cmd, rev, txn):
    self.pool = pool

    repos_ptr = repos.open(path, pool)
    self.fs_ptr = repos.fs(repos_ptr)

    if txn:
      self.txn_ptr = fs.open_txn(self.fs_ptr, txn, pool)
    else:
      self.txn_ptr = None
      if rev is None:
        rev = fs.youngest_rev(self.fs_ptr, pool)
    self.rev = rev
Example #13
0
 def do_settxn(self, arg):
   """set the current transaction to view"""
   try:
     txnobj = fs.open_txn(self.fs_ptr, arg)
     newroot = fs.txn_root(txnobj)
   except:
     print("Error setting the transaction to '" + arg + "'.")
     return
   fs.close_root(self.root)
   self.root = newroot
   self.txn = arg
   self.is_rev = 0
   self._do_path_landing()
Example #14
0
    def __init__(self, pool, path, cmd, rev, txn):
        self.pool = pool

        repos_ptr = repos.open(path, pool)
        self.fs_ptr = repos.fs(repos_ptr)

        if txn:
            self.txn_ptr = fs.open_txn(self.fs_ptr, txn, pool)
        else:
            self.txn_ptr = None
            if rev is None:
                rev = fs.youngest_rev(self.fs_ptr, pool)
        self.rev = rev
  def __init__(self, path, cmd, rev, txn):
    path = core.svn_path_canonicalize(path)
    repos_ptr = repos.open(path)
    self.fs_ptr = repos.fs(repos_ptr)

    if txn:
      self.txn_ptr = fs.open_txn(self.fs_ptr, txn)
    else:
      self.txn_ptr = None
      if rev is None:
        rev = fs.youngest_rev(self.fs_ptr)
    self.rev = rev

    getattr(self, 'cmd_' + cmd)()
Example #16
0
  def __init__(self, fs_ptr, root, pool=None, notify_cb=None):
    self.fs_ptr = fs_ptr
    self.changes = { } # path -> ChangedPathEntry()
    self.roots = { } # revision -> svn_svnfs_root_t
    self.notify_cb = notify_cb
    self.props = { }
    self.fs_root = root

    # Figger out the base revision and root properties.
    if _svnfs.is_revision_root(self.fs_root):
      rev = _svnfs.revision_root_revision(self.fs_root)
      self.base_rev = rev - 1
      self.props = _svnfs.revision_proplist(self.fs_ptr, rev)
    else:
      txn_name = _svnfs.txn_root_name(self.fs_root)
      txn_t = _svnfs.open_txn(self.fs_ptr, txn_name)
      self.base_rev = _svnfs.txn_base_revision(txn_t)
      self.props = _svnfs.txn_proplist(txn_t)
Example #17
0
  def __init__(self, fs_ptr, root, pool=None, notify_cb=None):
    self.fs_ptr = fs_ptr
    self.changes = { } # path -> ChangedPathEntry()
    self.roots = { } # revision -> svn_fs_root_t
    self.notify_cb = notify_cb
    self.props = { }
    self.fs_root = root

    # Figger out the base revision and root properties.
    if _fs.is_revision_root(self.fs_root):
      rev = _fs.revision_root_revision(self.fs_root)
      self.base_rev = rev - 1
      self.props = _fs.revision_proplist(self.fs_ptr, rev)
    else:
      txn_name = _fs.txn_root_name(self.fs_root)
      txn_t = _fs.open_txn(self.fs_ptr, txn_name)
      self.base_rev = _fs.txn_base_revision(txn_t)
      self.props = _fs.txn_proplist(txn_t)
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)
  def __init__(self, path, rev, txn):
    self.repo_root_path = core.svn_path_canonicalize(path)
    
    root_ptr = repos.open(self.repo_root_path)
    self.fs_ptr = repos.fs(root_ptr)

    # Set the revision/transaction
    if txn:
      self.txn_ptr = fs.open_txn(self.fs_ptr, txn)
    else:
      self.txn_ptr = None
      if rev is None:
          rev = fs.youngest_rev(self.fs_ptr)
    self.rev = rev

    # Set the root
    if self.txn_ptr:
      self.root = fs.txn_root(self.txn_ptr)
    else:
      self.root = fs.revision_root(self.fs_ptr, self.rev)

    # Set the base revision/transaction
    if self.txn_ptr:
      self.base_rev = fs.txn_base_revision(self.txn_ptr)
    else:
      self.base_rev = self.rev - 1

    # Set the base root of the comparison
    self.base_root = fs.revision_root(self.fs_ptr, self.base_rev)

    # Get all the changes and sort by path
    editor = repos.ChangeCollector(self.fs_ptr, self.root)
    e_ptr, e_baton = delta.make_editor(editor)
    repos.replay(self.root, e_ptr, e_baton)

    self.changelist = editor.get_changes().items()

    self.changelist.sort()
Example #20
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 #21
0
  return dir + '/' + name

def ensure_names(path, names, txn_root):
  if (not names.has_key(path)):
     names[path] = []
     for name, dirent in fs.dir_entries(txn_root, path).iteritems():
       names[path].append([canonicalize(name), name])

names = {}   # map of: key - path, value - list of two element lists of names
clashes = {} # map of: key - path, value - map of: key - path, value - dummy

native = locale.getlocale()[1]
if not native: native = 'ascii'
repos_handle = repos.open(sys.argv[1].decode(native).encode('utf-8'))
fs_handle = repos.fs(repos_handle)
txn_handle = fs.open_txn(fs_handle, sys.argv[2].decode(native).encode('utf-8'))
txn_root = fs.txn_root(txn_handle)

new_paths = get_new_paths(txn_root)
for path in new_paths:
  dir, name = split_path(path)
  canonical = canonicalize(name)
  ensure_names(dir, names, txn_root)
  for name_pair in names[dir]:
    if (name_pair[0] == canonical and name_pair[1] != name):
      canonical_path = join_path(dir, canonical)
      if (not clashes.has_key(canonical_path)):
        clashes[canonical_path] = {}
      clashes[canonical_path][join_path(dir, name)] = True
      clashes[canonical_path][join_path(dir, name_pair[1])] = True
Example #22
0
def ensure_names(path, names, txn_root):
    if (not names.has_key(path)):
        names[path] = []
        for name, dirent in fs.dir_entries(txn_root, path).iteritems():
            names[path].append([canonicalize(name), name])


names = {}  # map of: key - path, value - list of two element lists of names
clashes = {}  # map of: key - path, value - map of: key - path, value - dummy

native = locale.getlocale()[1]
if not native: native = 'ascii'
repos_handle = repos.open(sys.argv[1].decode(native).encode('utf-8'))
fs_handle = repos.fs(repos_handle)
txn_handle = fs.open_txn(fs_handle, sys.argv[2].decode(native).encode('utf-8'))
txn_root = fs.txn_root(txn_handle)

new_paths = get_new_paths(txn_root)
for path in new_paths:
    dir, name = split_path(path)
    canonical = canonicalize(name)
    ensure_names(dir, names, txn_root)
    for name_pair in names[dir]:
        if (name_pair[0] == canonical and name_pair[1] != name):
            canonical_path = join_path(dir, canonical)
            if (not clashes.has_key(canonical_path)):
                clashes[canonical_path] = {}
            clashes[canonical_path][join_path(dir, name)] = True
            clashes[canonical_path][join_path(dir, name_pair[1])] = True
Example #23
0
def ensure_names(path, names, txn_root):
    if (path not in names):
        names[path] = []
        for name, dirent in fs.dir_entries(txn_root, path).items():
            name = name.decode('utf-8')
            names[path].append([canonicalize(name), name])


names = {}  # map of: key - path, value - list of two element lists of names
clashes = {}  # map of: key - path, value - map of: key - path, value - dummy

native = locale.getlocale()[1]
if not native: native = 'ascii'
repos_handle = repos.open(sys.argv[1].encode('utf-8'))
fs_handle = repos.fs(repos_handle)
txn_handle = fs.open_txn(fs_handle, sys.argv[2].encode('utf-8'))
txn_root = fs.txn_root(txn_handle)

new_paths = get_new_paths(txn_root)
for path in new_paths:
    dir, name = split_path(path)
    canonical = canonicalize(name)
    ensure_names(dir, names, txn_root)
    for name_pair in names[dir]:
        if (name_pair[0] == canonical and name_pair[1] != name):
            canonical_path = join_path(dir, canonical)
            if (canonical_path not in clashes):
                clashes[canonical_path] = {}
            clashes[canonical_path][join_path(dir, name)] = True
            clashes[canonical_path][join_path(dir, name_pair[1])] = True