Exemple #1
0
 def create_file(self, file_name, content, author, comment):
     """
     Creates a file in the SVN repository with the given
     name and content (text). Returns the committed revision
     """
     assert self.svn_repos is not None, "SVN repository not set..."
     # Get an SVN file system pointer
     fs_ptr = repos.fs(self.svn_repos)
     rev = fs.youngest_rev(fs_ptr)
     # Create and SVN transaction
     txn = fs.begin_txn(fs_ptr, rev)
     txn_root = fs.txn_root(txn)
     # Create a file in the root transaction
     fs.make_file(txn_root, file_name)
     stream = fs.apply_text(txn_root, file_name, None)
     core.svn_stream_write(stream, "%s\n" % content)
     core.svn_stream_close(stream)
     # Now set the properties svn:log and svn:author to
     # the newly created node (file)
     fs.change_txn_prop(txn, 'svn:author', author)
     fs.change_txn_prop(txn, 'svn:log', comment)
     # Commit the transaction
     fs.commit_txn(txn)
     # Add teh file to the list of created files
     self.files.append(file_name)
     # Returns therevision number
     return rev + 1
Exemple #2
0
    def load(self, repo_path):
        repo_path = core.svn_path_canonicalize(repo_path)
        repos_ptr = repos.open(repo_path)
        fs_ptr = repos.fs(repos_ptr)
        rev = fs.youngest_rev(fs_ptr)
        base_root = fs.revision_root(fs_ptr, 0)
        root = fs.revision_root(fs_ptr, rev)
        hist = fs.node_history(root, self.root)
        while hist is not None:
            hist = fs.history_prev(hist, 0)
            dummy, rev = fs.history_location(hist)
            d = fs.revision_prop(fs_ptr, rev, core.SVN_PROP_REVISION_DATE)
            author = fs.revision_prop(fs_ptr, rev, \
                    core.SVN_PROP_REVISION_AUTHOR)
            if author == 'svnadmin':
                continue
            self.last_author = author
            self.last_date = core.svn_time_from_cstring(d) / 1000000
            self.last_rev = rev

            def authz_cb(root, path, pool):
                return 1

            editor = SvnDumperEditor(self)
            e_ptr, e_baton = delta.make_editor(editor)
            repos.dir_delta(base_root, '', '', root, self.root, e_ptr, e_baton,
                            authz_cb, 0, 1, 0, 0)
            break
Exemple #3
0
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]))
Exemple #4
0
def putfile(fname, rpath, uname="", commitmsg=""):
  rpath = core.svn_path_canonicalize(rpath)
  repos_ptr = repos.open(rpath)
  fsob = repos.fs(repos_ptr)

  # open a transaction against HEAD
  rev = fs.youngest_rev(fsob)

  txn = repos.fs_begin_txn_for_commit(repos_ptr, rev, uname, commitmsg)

  root = fs.txn_root(txn)
  rev_root = fs.revision_root(fsob, rev)

  kind = fs.check_path(root, fname)
  if kind == core.svn_node_none:
    print("file '%s' does not exist, creating..." % fname)
    fs.make_file(root, fname)
  elif kind == core.svn_node_dir:
    print("File '%s' is a dir." % fname)
    return
  else:
    print("Updating file '%s'" % fname)

  handler, baton = fs.apply_textdelta(root, fname, None, None)

  ### it would be nice to get an svn_stream_t. for now, just load in the
  ### whole file and shove it into the FS.
  delta.svn_txdelta_send_string(open(fname, 'rb').read(),
                                handler, baton)

  newrev = repos.fs_commit_txn(repos_ptr, txn)
  print("revision: %s" % newrev)
Exemple #5
0
 def create_file(self, file_name, content, author, comment):
     """
     Creates a file in the SVN repository with the given
     name and content (text). Returns the committed revision
     """
     assert self.svn_repos is not None, "SVN repository not set..."
     # Get an SVN file system pointer
     fs_ptr = repos.fs(self.svn_repos)
     rev = fs.youngest_rev(fs_ptr)
     # Create and SVN transaction
     txn = fs.begin_txn(fs_ptr, rev)
     txn_root = fs.txn_root(txn)
     # Create a file in the root transaction
     fs.make_file(txn_root, file_name)
     stream = fs.apply_text(txn_root, file_name, None)
     core.svn_stream_write(stream, "%s\n" % content)
     core.svn_stream_close(stream)
     # Now set the properties svn:log and svn:author to
     # the newly created node (file)
     fs.change_txn_prop(txn, 'svn:author', author)
     fs.change_txn_prop(txn, 'svn:log', comment)
     # Commit the transaction
     fs.commit_txn(txn)
     # Add teh file to the list of created files
     self.files.append(file_name)
     # Returns therevision number
     return rev + 1
 def setUp(self):
   """Load a Subversion repository"""
   self.temper = utils.Temper()
   (self.repos, _, _) = self.temper.alloc_known_repo(
     'trac/versioncontrol/tests/svnrepos.dump', suffix='-repository')
   self.fs = repos.fs(self.repos)
   self.rev = fs.youngest_rev(self.fs)
    def load(self, repo_path):
	repo_path = core.svn_path_canonicalize(repo_path)
	repos_ptr = repos.open(repo_path)
	fs_ptr = repos.fs(repos_ptr)
	rev = fs.youngest_rev(fs_ptr)
	base_root = fs.revision_root(fs_ptr, 0)
	root = fs.revision_root(fs_ptr, rev)
	hist = fs.node_history(root, self.root)
	while hist is not None:
	    hist = fs.history_prev(hist,0)
	    dummy,rev = fs.history_location(hist)
	    d = fs.revision_prop(fs_ptr, rev, core.SVN_PROP_REVISION_DATE)
	    author = fs.revision_prop(fs_ptr, rev, \
		    core.SVN_PROP_REVISION_AUTHOR)
	    if author == 'svnadmin':
		continue
	    self.last_author = author
	    self.last_date = core.svn_time_from_cstring(d) / 1000000
	    self.last_rev = rev
	    def authz_cb(root, path, pool):
		return 1
	    editor = SvnDumperEditor(self)
	    e_ptr, e_baton = delta.make_editor(editor)
	    repos.dir_delta(base_root, '', '', root, self.root, e_ptr, e_baton,
		authz_cb, 0, 1, 0, 0)
	    break
Exemple #8
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)()
Exemple #9
0
 def setUp(self):
     """Load a Subversion repository"""
     self.temper = utils.Temper()
     (self.repos, self.repos_path, _) = self.temper.alloc_known_repo(
         'trac/versioncontrol/tests/svnrepos.dump', suffix='-repository')
     self.fs = repos.fs(self.repos)
     self.rev = fs.youngest_rev(self.fs)
  def __init__(self, pool, path, txn):
    self.pool = pool;
    repos_ptr = repos.open(path, pool)
    self.fs_ptr = repos.fs(repos_ptr)

    self.look = SVNLook(self.pool, path, 'changed', None, txn)

    # Get the list of files and directories which have been added.
    changed = self.look.cmd_changed()
    if debug:
      for item in changed.added + changed.addeddir:
        print >> sys.stderr, 'Adding: ' + item.encode('utf-8')
    if self.numadded(changed) != 0:
      # Find the part of the file tree which they live in.
      changedroot = self.findroot(changed)
      if debug:
        print >> sys.stderr, 'Changedroot is ' + changedroot.encode('utf-8')
      # Get that part of the file tree.
      tree = self.look.cmd_tree(changedroot)
  
      if debug:
        print >> sys.stderr, 'File tree:'
        for path in tree.paths.keys():
          print >> sys.stderr, '  [%d] %s len %d' % (tree.paths[path], path.encode('utf-8'), len(path))
  
      # If a member of the paths hash has a count of more than one there is a
      # case conflict.
      for path in tree.paths.keys():
        if tree.paths[path] > 1:
          # Find out if this is one of the files being added, if not ignore it.
          addedfile = self.showfile(path, changedroot, changed)
          if addedfile <> '':
            print >> sys.stderr, "Case conflict: " + addedfile.encode('utf-8') \
                + "\nA file with same filename but different cases already exist!"
            globals()["exitstat"] = 1
Exemple #11
0
  def setUp(self):
    """Load a Subversion repository"""
    self.temper = utils.Temper()
    (self.repos, self.repos_path, self.repos_uri) = self.temper.alloc_known_repo(
      'trac/versioncontrol/tests/svnrepos.dump', suffix='-repository')
    self.fs = repos.fs(self.repos)
    self.rev = fs.youngest_rev(self.fs)
    self.tmpfile = None
    self.unistr = u'⊙_ʘ'
    tmpfd, self.tmpfile = mkstemp()

    tmpfp = os.fdopen(tmpfd, "wb")

    # Use a unicode file to ensure proper non-ascii handling.
    tmpfp.write(self.unistr.encode('utf8'))

    tmpfp.close()

    clientctx = client.svn_client_create_context()
    clientctx.log_msg_func3 = client.svn_swig_py_get_commit_log_func
    clientctx.log_msg_baton3 = self.log_message_func

    providers = [
       client.svn_client_get_simple_provider(),
       client.svn_client_get_username_provider(),
    ]

    clientctx.auth_baton = core.svn_auth_open(providers)

    commitinfo = client.import2(self.tmpfile,
                                urljoin(self.repos_uri +"/", "trunk/UniTest.txt"),
                                True, True,
                                clientctx)

    self.commitedrev = commitinfo.revision
Exemple #12
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)()
Exemple #13
0
def putfile(fname, rpath, uname="", commitmsg=""):
    rpath = core.svn_path_canonicalize(rpath)
    repos_ptr = repos.open(rpath)
    fsob = repos.fs(repos_ptr)

    # open a transaction against HEAD
    rev = fs.youngest_rev(fsob)

    txn = repos.fs_begin_txn_for_commit(repos_ptr, rev, uname, commitmsg)

    root = fs.txn_root(txn)
    rev_root = fs.revision_root(fsob, rev)

    kind = fs.check_path(root, fname)
    if kind == core.svn_node_none:
        print("file '%s' does not exist, creating..." % fname)
        fs.make_file(root, fname)
    elif kind == core.svn_node_dir:
        print("File '%s' is a dir." % fname)
        return
    else:
        print("Updating file '%s'" % fname)

    handler, baton = fs.apply_textdelta(root, fname, None, None)

    ### it would be nice to get an svn_stream_t. for now, just load in the
    ### whole file and shove it into the FS.
    delta.svn_txdelta_send_string(open(fname, 'rb').read(), handler, baton)

    newrev = repos.fs_commit_txn(repos_ptr, txn)
    print("revision: %s" % newrev)
Exemple #14
0
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]))
def get_node_id(pool, repos_path, path, revision):
    # Open the repository and filesystem.
    repos_ptr = repos.open(repos_path, pool)
    fs_ptr = repos.fs(repos_ptr)

    # Fetch the node revision ID of interest
    rev_root = fs.revision_root(fs_ptr, int(revision), pool)
    return fs.unparse_id(fs.node_id(rev_root, path, pool), pool)
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)
Exemple #18
0
def get_node_id(pool, repos_path, path, revision):
    # Open the repository and filesystem.
    repos_ptr = repos.open(repos_path, pool)
    fs_ptr = repos.fs(repos_ptr)

    # Fetch the node revision ID of interest
    rev_root = fs.revision_root(fs_ptr, int(revision), pool)
    return fs.unparse_id(fs.node_id(rev_root, path, pool), pool)
Exemple #19
0
 def connect(self, repository):
     """
     Connect with repository
     
     @todo: Create validation for repository url
     """    
     
     # Open repository connection
     self.repository = repos.open(repository)
     self.fs_ptr = repos.fs(self.repository)
 def setUp(self):
   """Load the mergeinfo-full Subversion repository.  This dumpfile is
      created by dumping the repository generated for command line log
      tests 16.  If it needs to be updated (mergeinfo format changes, for
      example), we can go there to get a new version."""
   self.temper = utils.Temper()
   (self.repos, _, _) = self.temper.alloc_known_repo('data/mergeinfo.dump',
                                                     suffix='-mergeinfo')
   self.fs = repos.fs(self.repos)
   self.rev = fs.youngest_rev(self.fs)
Exemple #21
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)
Exemple #22
0
 def setUp(self):
     """Load the mergeinfo-full Subversion repository.  This dumpfile is
    created by dumping the repository generated for command line log
    tests 16.  If it needs to be updated (mergeinfo format changes, for
    example), we can go there to get a new version."""
     self.temper = utils.Temper()
     (self.repos, _,
      _) = self.temper.alloc_known_repo('data/mergeinfo.dump',
                                        suffix='-mergeinfo')
     self.fs = repos.fs(self.repos)
     self.rev = fs.youngest_rev(self.fs)
Exemple #23
0
def dumpprops(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)

  root = fs.revision_root(fsob, rev)
  print_props(root, filename)
  if fs.is_dir(root, filename):
    walk_tree(root, filename)
Exemple #24
0
 def __init__(self, path):
   """initialize an SVNShell object"""
   Cmd.__init__(self)
   path = core.svn_path_canonicalize(path)
   self.fs_ptr = repos.fs(repos.open(path))
   self.is_rev = 1
   self.rev = fs.youngest_rev(self.fs_ptr)
   self.txn = None
   self.root = fs.revision_root(self.fs_ptr, self.rev)
   self.path = "/"
   self._setup_prompt()
   self.cmdloop()
Exemple #25
0
def dumpprops(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)

  root = fs.revision_root(fsob, rev)
  print_props(root, filename)
  if fs.is_dir(root, filename):
    walk_tree(root, filename)
Exemple #26
0
 def __init__(self, path):
   """initialize an SVNShell object"""
   Cmd.__init__(self)
   path = core.svn_path_canonicalize(path)
   self.fs_ptr = repos.fs(repos.open(path))
   self.is_rev = 1
   self.rev = fs.youngest_rev(self.fs_ptr)
   self.txn = None
   self.root = fs.revision_root(self.fs_ptr, self.rev)
   self.path = "/"
   self._setup_prompt()
   self.cmdloop()
Exemple #27
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)
  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
Exemple #29
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
Exemple #30
0
 def delete_file(self, file_name):
     """Deletes the given file from the repository"""
     assert self.svn_repos is not None, "SVN repository not set..."
     # Get an SVN file system pointer
     fs_ptr = repos.fs(self.svn_repos)
     rev = fs.youngest_rev(fs_ptr)
     # Create and SVN transaction
     txn = fs.begin_txn(fs_ptr, rev)
     txn_root = fs.txn_root(txn)
     # Create a file in the root transaction
     fs.delete(txn_root, file_name)
     # Commit the transaction
     fs.commit_txn(txn)
Exemple #31
0
 def delete_file(self, file_name):
     """Deletes the given file from the repository"""
     assert self.svn_repos is not None, "SVN repository not set..."
     # Get an SVN file system pointer
     fs_ptr = repos.fs(self.svn_repos)
     rev = fs.youngest_rev(fs_ptr)
     # Create and SVN transaction
     txn = fs.begin_txn(fs_ptr, rev)
     txn_root = fs.txn_root(txn)
     # Create a file in the root transaction
     fs.delete(txn_root, file_name)
     # Commit the transaction
     fs.commit_txn(txn)
Exemple #32
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)()
Exemple #33
0
def main():
  argc = len(sys.argv)
  if argc < 3 or argc > 4:
    print("Usage: %s PATH-TO-REPOS PATH-IN-REPOS [REVISION]" % sys.argv[0])
    sys.exit(1)

  fs_ptr = repos.fs(repos.open(sys.argv[1]))
  if argc == 3:
    revision = fs.youngest_rev(fs_ptr)
  else:
    revision = int(sys.argv[3])
  check_history(fs_ptr, sys.argv[2], revision)
  sys.exit(0)
Exemple #34
0
def main():
    argc = len(sys.argv)
    if argc < 3 or argc > 4:
        print("Usage: %s PATH-TO-REPOS PATH-IN-REPOS [REVISION]" % sys.argv[0])
        sys.exit(1)

    fs_ptr = repos.fs(repos.open(sys.argv[1]))
    if argc == 3:
        revision = fs.youngest_rev(fs_ptr)
    else:
        revision = int(sys.argv[3])
    check_history(fs_ptr, sys.argv[2], revision)
    sys.exit(0)
  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)()
Exemple #36
0
    def setUp(self):
        """Load a Subversion repository"""

        ra.initialize()
        self.temper = utils.Temper()
        # Isolate each test from the others with a fresh repository.

        # Open repository directly for cross-checking
        (self.repos, _, self.repos_uri) = self.temper.alloc_known_repo(
            'trac/versioncontrol/tests/svnrepos.dump', suffix='-ra')
        self.fs = repos.fs(self.repos)

        self.callbacks = ra.Callbacks()
        self.ra_ctx = ra.open2(self.repos_uri, self.callbacks, {})
Exemple #37
0
 def delete_files(self):
     """Deletes all the files created by the helper"""
     if self.svn_repos is not None:
         # Get an SVN file system pointer
         fs_ptr = repos.fs(self.svn_repos)
         rev = fs.youngest_rev(fs_ptr)
         # Create and SVN transaction
         txn = fs.begin_txn(fs_ptr, rev)
         txn_root = fs.txn_root(txn)
         # Create a file in the root transaction
         for svn_file in self.files:
             fs.delete(txn_root, svn_file)
         # Commit the transaction
         fs.commit_txn(txn)
Exemple #38
0
  def setUp(self):
    """Load a Subversion repository"""

    ra.initialize()
    self.temper = utils.Temper()
    # Isolate each test from the others with a fresh repository.

    # Open repository directly for cross-checking
    (self.repos, _, self.repos_uri) = self.temper.alloc_known_repo(
      'trac/versioncontrol/tests/svnrepos.dump', suffix='-ra')
    self.fs = repos.fs(self.repos)

    self.callbacks = ra.Callbacks()
    self.ra_ctx = ra.open2(self.repos_uri, self.callbacks, {})
Exemple #39
0
 def delete_files(self):
     """Deletes all the files created by the helper"""
     if self.svn_repos is not None:
         # Get an SVN file system pointer
         fs_ptr = repos.fs(self.svn_repos)
         rev = fs.youngest_rev(fs_ptr)
         # Create and SVN transaction
         txn = fs.begin_txn(fs_ptr, rev)
         txn_root = fs.txn_root(txn)
         # Create a file in the root transaction
         for svn_file in self.files:
             fs.delete(txn_root, svn_file)
         # Commit the transaction
         fs.commit_txn(txn)
Exemple #40
0
 def retrieve_file(self, file_name, rev=None):
     """
     Retrieves the given file name, at the specified revision or
     the latest available from the SVN repository
     """
     assert self.svn_repos is not None, "SVN repository not set..."
     # Get an SVN file system pointer
     fs_ptr = repos.fs(self.svn_repos)
     if rev is None:
         rev = fs.youngest_rev(fs_ptr)
     root = fs.revision_root(fs_ptr, rev)
     stream = fs.file_contents(root, file_name)
     svn_file = core.Stream(stream)
     core.svn_stream_close(stream)
     return svn_file
Exemple #41
0
 def retrieve_file(self, file_name, rev=None):
     """
     Retrieves the given file name, at the specified revision or
     the latest available from the SVN repository
     """
     assert self.svn_repos is not None, "SVN repository not set..."
     # Get an SVN file system pointer
     fs_ptr = repos.fs(self.svn_repos)
     if rev is None:
         rev = fs.youngest_rev(fs_ptr)
     root = fs.revision_root(fs_ptr, rev)
     stream = fs.file_contents(root, file_name)
     svn_file = core.Stream(stream)
     core.svn_stream_close(stream)
     return svn_file
Exemple #42
0
 def setUp(self):
     """Load the mergeinfo-full Subversion repository.  This dumpfile is
    created by dumping the repository generated for command line log
    tests 16.  If it needs to be updated (mergeinfo format changes, for
    example), we can go there to get a new version."""
     dumpfile = open(
         os.path.join(os.path.split(__file__)[0], 'data', 'mergeinfo.dump'))
     # Remove any existing repository to ensure a fresh start
     self.tearDown()
     self.repos = repos.svn_repos_create(REPOS_PATH, '', '', None, None)
     repos.svn_repos_load_fs2(self.repos, dumpfile, StringIO(),
                              repos.svn_repos_load_uuid_default, '', 0, 0,
                              None)
     self.fs = repos.fs(self.repos)
     self.rev = fs.youngest_rev(self.fs)
Exemple #43
0
 def setUp(self):
   """Load the mergeinfo-full Subversion repository.  This dumpfile is
      created by dumping the repository generated for command line log
      tests 16.  If it needs to be updated (mergeinfo format changes, for
      example), we can go there to get a new version."""
   dumpfile = open(os.path.join(os.path.split(__file__)[0],
                                'data', 'mergeinfo.dump'))
   # Remove any existing repository to ensure a fresh start
   self.tearDown()
   self.repos = repos.svn_repos_create(REPOS_PATH, '', '', None, None)
   repos.svn_repos_load_fs2(self.repos, dumpfile, StringIO(),
                            repos.svn_repos_load_uuid_default, '',
                            0, 0, None)
   self.fs = repos.fs(self.repos)
   self.rev = fs.youngest_rev(self.fs)
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)
Exemple #45
0
    def setUp(self):
        """Load a Subversion repository"""

        # Isolate each test from the others with a fresh repository.
        # Eventually, we should move this into a shared TestCase base
        # class that all test cases in this directory can use.
        SubversionRepositoryTestSetup().setUp()

        ra.initialize()

        # Open repository directly for cross-checking
        self.repos = repos.open(REPOS_PATH)
        self.fs = repos.fs(self.repos)

        self.callbacks = ra.Callbacks()
        self.ra_ctx = ra.open2(REPOS_URL, self.callbacks, None, None)
Exemple #46
0
  def setUp(self):
    """Load a Subversion repository"""

    # Isolate each test from the others with a fresh repository.
    # Eventually, we should move this into a shared TestCase base
    # class that all test cases in this directory can use.
    SubversionRepositoryTestSetup().setUp()

    ra.initialize()

    # Open repository directly for cross-checking
    self.repos = repos.open(REPOS_PATH)
    self.fs = repos.fs(self.repos)

    self.callbacks = ra.Callbacks()
    self.ra_ctx = ra.open2(REPOS_URL, self.callbacks, None, None)
Exemple #47
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 1:
    data = core.svn_stream_read(file, CHUNK_SIZE)
    if not data:
      break
    sys.stdout.write(data)
Exemple #48
0
  def setUp(self):
    """Load a Subversion repository"""

    self.temper = utils.Temper()

    # Isolate each test from the others with a fresh repository.
    (self.repos, _, self.repos_uri) = self.temper.alloc_known_repo(
      'trac/versioncontrol/tests/svnrepos.dump', suffix='-wc-repo')
    self.fs = repos.fs(self.repos)

    self.path = self.temper.alloc_empty_dir(suffix='-wc-wc')

    client_ctx = client.create_context()

    rev = core.svn_opt_revision_t()
    rev.kind = core.svn_opt_revision_head

    client.checkout2(self.repos_uri, self.path, rev, rev, True, True,
            client_ctx)

    self.wc = wc.adm_open3(None, self.path, True, -1, None)
Exemple #49
0
    def setUp(self):
        """Load a Subversion repository"""

        self.temper = utils.Temper()

        # Isolate each test from the others with a fresh repository.
        (self.repos, _, self.repos_uri) = self.temper.alloc_known_repo(
            'trac/versioncontrol/tests/svnrepos.dump', suffix='-wc-repo')
        self.fs = repos.fs(self.repos)

        self.path = self.temper.alloc_empty_dir(suffix='-wc-wc')

        client_ctx = client.create_context()

        rev = core.svn_opt_revision_t()
        rev.kind = core.svn_opt_revision_head

        client.checkout2(self.repos_uri, self.path, rev, rev, True, True,
                         client_ctx)

        self.wc = wc.adm_open3(None, self.path, True, -1, None)
Exemple #50
0
    def setUp(self):
        """Load a Subversion repository"""

        # Isolate each test from the others with a fresh repository.
        # Eventually, we should move this into a shared TestCase base
        # class that all test cases in this directory can use.
        SubversionRepositoryTestSetup().setUp()

        # Open repository directly for cross-checking
        self.repos = repos.open(REPOS_PATH)
        self.fs = repos.fs(self.repos)

        self.path = core.svn_path_canonicalize(tempfile.mktemp())

        client_ctx = client.create_context()

        rev = core.svn_opt_revision_t()
        rev.kind = core.svn_opt_revision_head

        client.checkout2(REPOS_URL, self.path, rev, rev, True, True, client_ctx)

        self.wc = wc.adm_open3(None, self.path, True, -1, None)
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)
Exemple #52
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)
  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()
Exemple #54
0
    def setUp(self):
        """Load a Subversion repository"""

        # Isolate each test from the others with a fresh repository.
        # Eventually, we should move this into a shared TestCase base
        # class that all test cases in this directory can use.
        SubversionRepositoryTestSetup().setUp()

        # Open repository directly for cross-checking
        self.repos = repos.open(REPOS_PATH)
        self.fs = repos.fs(self.repos)

        self.path = core.svn_path_canonicalize(tempfile.mktemp())

        client_ctx = client.create_context()

        rev = core.svn_opt_revision_t()
        rev.kind = core.svn_opt_revision_head

        client.checkout2(REPOS_URL, self.path, rev, rev, True, True,
                         client_ctx)

        self.wc = wc.adm_open3(None, self.path, True, -1, None)
Exemple #55
0
    def __init__(self, pool, path, txn):
        self.pool = pool
        repos_ptr = repos.open(path, pool)
        self.fs_ptr = repos.fs(repos_ptr)

        self.look = SVNLook(self.pool, path, 'changed', None, txn)

        # Get the list of files and directories which have been added.
        changed = self.look.cmd_changed()
        if debug:
            for item in changed.added + changed.addeddir:
                print >> sys.stderr, 'Adding: ' + item.encode('utf-8')
        if self.numadded(changed) != 0:
            # Find the part of the file tree which they live in.
            changedroot = self.findroot(changed)
            if debug:
                print >> sys.stderr, 'Changedroot is ' + changedroot.encode(
                    'utf-8')
            # Get that part of the file tree.
            tree = self.look.cmd_tree(changedroot)

            if debug:
                print >> sys.stderr, 'File tree:'
                for path in tree.paths.keys():
                    print >> sys.stderr, '  [%d] %s len %d' % (
                        tree.paths[path], path.encode('utf-8'), len(path))

            # If a member of the paths hash has a count of more than one there is a
            # case conflict.
            for path in tree.paths.keys():
                if tree.paths[path] > 1:
                    # Find out if this is one of the files being added, if not ignore it.
                    addedfile = self.showfile(path, changedroot, changed)
                    if addedfile <> '':
                        print >> sys.stderr, "Case conflict: " + addedfile.encode(
                            'utf-8')
                        globals()["exitstat"] = 1
Exemple #56
0
 def setUp(self):
     """Load a Subversion repository"""
     self.repos = repos.open(REPOS_PATH)
     self.fs = repos.fs(self.repos)
     self.rev = fs.youngest_rev(self.fs)
Exemple #57
0
import codecs

#argvs[1]:repository path
#argvs[2]:changeset folder
#argvs[3]:start revision
#argvs[4]:end revision
argvs = sys.argv  #コマンドライン引数リスト
argc = len(argvs)  #引数の個数

if (argc != 5):  #5でなければ出る
    usage(1)

path = argvs[1]
path = core.svn_path_canonicalize(path)
repos_ptr = repos.open(path)
fs_ptr = repos.fs(repos_ptr)

changeset_folder = argvs[2]

start_rev = int(argvs[3])
end_rev = int(argvs[4])

if start_rev > end_rev:
    sys.exit(exit)

rev = fs.youngest_rev(fs_ptr)
if start_rev > rev and end_rev > rev:
    sys.exit(exit)

if start_rev > rev:
    start_rev = rev
Exemple #58
0
 def setUp(self):
   """Load a Subversion repository"""
   self.repos = repos.open(REPOS_PATH)
   self.fs = repos.fs(self.repos)
   self.rev = fs.youngest_rev(self.fs)
Exemple #59
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