示例#1
0
        def visitdir(editor, directory, paths, pathidx):
            while pathidx < len(paths):
                path = paths[pathidx]
                if directory and not path.startswith(directory + '/'):
                    return pathidx

                pathidx += 1

                if path in file_data:
                    # visiting a file
                    base_text, new_text, action = file_data[path]
                    if action == 'modify':
                        fileeditor = editor.open_file(path, base_revision)
                    elif action == 'add':
                        frompath, fromrev = copies.get(path, (None, -1))
                        if frompath:
                            frompath = self.path2url(frompath)
                        fileeditor = editor.add_file(path, frompath, fromrev)
                    elif action == 'delete':
                        editor.delete_entry(path, base_revision)
                        continue
                    else:
                        assert False, "invalid action '%s'" % action

                    if path in props:
                        if props[path].get('svn:special', None):
                            new_text = 'link %s' % new_text
                        for p, v in props[path].iteritems():
                            fileeditor.change_prop(p, v)


                    handler = fileeditor.apply_textdelta()
                    delta.send_stream(cStringIO.StringIO(new_text), handler)
                    fileeditor.close()

                else:
                    # visiting a directory
                    if path in deleteddirs:
                        direditor = editor.delete_entry(path, base_revision)

                        if path not in addeddirs:
                            continue

                    if path in addeddirs:
                        frompath, fromrev = copies.get(path, (None, -1))
                        if frompath:
                            frompath = self.path2url(frompath)
                        direditor = editor.add_directory(path, frompath, fromrev)
                    else:
                        direditor = editor.open_directory(path)

                    if path in props:
                        for p, v in props[path].iteritems():
                            direditor.change_prop(p, v)

                    pathidx = visitdir(direditor, path, paths, pathidx)
                    direditor.close()

            return pathidx
示例#2
0
        def visitdir(editor, directory, paths, pathidx):
            while pathidx < len(paths):
                path = paths[pathidx]
                if directory and not path.startswith(directory + '/'):
                    return pathidx

                pathidx += 1

                if path in file_data:
                    # visiting a file
                    base_text, new_text, action = file_data[path]
                    if action == 'modify':
                        fileeditor = editor.open_file(path, base_revision)
                    elif action == 'add':
                        frompath, fromrev = copies.get(path, (None, -1))
                        if frompath:
                            frompath = self.path2url(frompath)
                        fileeditor = editor.add_file(path, frompath, fromrev)
                    elif action == 'delete':
                        editor.delete_entry(path, base_revision)
                        continue
                    else:
                        assert False, 'invalid action \'%s\'' % action

                    if path in props:
                        if props[path].get('svn:special', None):
                            new_text = 'link %s' % new_text
                        for p, v in props[path].iteritems():
                            fileeditor.change_prop(p, v)


                    handler = fileeditor.apply_textdelta()
                    delta.send_stream(cStringIO.StringIO(new_text), handler)
                    fileeditor.close()

                else:
                    # visiting a directory
                    if path in addeddirs:
                        direditor = editor.add_directory(path)
                    elif path in deleteddirs:
                        direditor = editor.delete_entry(path, base_revision)
                        continue
                    else:
                        direditor = editor.open_directory(path)

                    if path in props:
                        for p, v in props[path].iteritems():
                            direditor.change_prop(p, v)

                    pathidx = visitdir(direditor, path, paths, pathidx)
                    direditor.close()

            return pathidx
示例#3
0
def add_commit(repo_url: str, message: str, changes: List[CommitChange]) -> None:
    conn = RemoteAccess(repo_url, auth=Auth([get_username_provider()]))
    editor = conn.get_commit_editor({"svn:log": message})
    root = editor.open_root()
    for change in changes:
        if change["change_type"] == CommitChangeType.Delete:
            root.delete_entry(change["path"].rstrip("/"))
        else:
            dir_change = change["path"].endswith("/")
            split_path = change["path"].rstrip("/").split("/")
            for i in range(len(split_path)):
                path = "/".join(split_path[0 : i + 1])
                if i < len(split_path) - 1:
                    try:
                        root.add_directory(path).close()
                    except SubversionException:
                        pass
                else:
                    if dir_change:
                        try:
                            dir = root.add_directory(path)
                        except SubversionException:
                            dir = root.open_directory(path)
                        if "properties" in change:
                            for prop, value in change["properties"].items():
                                dir.change_prop(prop, value)
                        dir.close()
                    else:
                        try:
                            file = root.add_file(path)
                        except SubversionException:
                            file = root.open_file(path)
                        if "properties" in change:
                            for prop, value in change["properties"].items():
                                file.change_prop(prop, value)
                        if "data" in change:
                            txdelta = file.apply_textdelta()
                            delta.send_stream(BytesIO(change["data"]), txdelta)
                        file.close()
    root.close()
    editor.close()
示例#4
0
 def modify(self, contents=None):
     if contents is None:
         contents = urllib2.randombytes(100)
     txdelta = self.file.apply_textdelta()
     delta.send_stream(StringIO(contents), txdelta)
示例#5
0
conn = RemoteAccess(repo_url,
                    auth=Auth([get_username_provider()]))

# Simple commit that adds a directory
editor = conn.get_commit_editor({"svn:log": "Commit message"})
root = editor.open_root()
# Add a directory
dir = root.add_directory("somedir")
dir.close()
# Add and edit a file
file = root.add_file("somefile")
# Set the svn:executable attribute
file.change_prop("svn:executable", "*")
# Obtain a textdelta handler and send the new file contents
txdelta = file.apply_textdelta()
delta.send_stream(StringIO("new file contents"), txdelta)
file.close()
root.close()
editor.close()

# Rename the directory
editor = conn.get_commit_editor({"svn:log": "Commit message"})
root = editor.open_root()
# Create a new directory copied from somedir:1
dir = root.add_directory("new dir name", "%s/somedir" % repo_url, 1)
dir.close()
# Remove the original directory
root.delete_entry("somedir")
root.close()
editor.close()
示例#6
0
 def modify(self, contents=None):
     if contents is None:
         contents = urllib2.randombytes(100)
     txdelta = self.file.apply_textdelta()
     delta.send_stream(StringIO(contents), txdelta)
示例#7
0
 def test_send_stream(self):
     stream = BytesIO(b"foo")
     send_stream(stream, self.storing_window_handler)
     self.assertEqual([(0, 0, 3, 0, [(2, 0, 3)], b'foo'), None], 
                       self.windows)
示例#8
0
repo_url = "file://%s" % os.path.abspath("tmprepo")
conn = RemoteAccess(repo_url, auth=Auth([get_username_provider()]))

# Simple commit that adds a directory
editor = conn.get_commit_editor({"svn:log": "Commit message"})
root = editor.open_root()
# Add a directory
dir = root.add_directory("somedir")
dir.close()
# Add and edit a file
file = root.add_file("somefile")
# Set the svn:executable attribute
file.change_prop("svn:executable", "*")
# Obtain a textdelta handler and send the new file contents
txdelta = file.apply_textdelta()
delta.send_stream(StringIO("new file contents"), txdelta)
file.close()
root.close()
editor.close()

# Rename the directory
editor = conn.get_commit_editor({"svn:log": "Commit message"})
root = editor.open_root()
# Create a new directory copied from somedir:1
dir = root.add_directory("new dir name", "%s/somedir" % repo_url, 1)
dir.close()
# Remove the original directory
root.delete_entry("somedir")
root.close()
editor.close()
示例#9
0
 def modify(self, contents=None):
     if contents is None:
         contents = os.urandom(100)
     txdelta = self.file.apply_textdelta()
     delta.send_stream(BytesIO(contents), txdelta)
示例#10
0
 def test_send_stream(self):
     stream = StringIO("foo")
     send_stream(stream, self.storing_window_handler)
     self.assertEqual([(0, 0, 3, 0, [(2, 0, 3)], 'foo'), None],
                      self.windows)
示例#11
0
repo_url = "file://%s" % os.path.abspath("tmprepo")
conn = RemoteAccess(repo_url, auth=Auth([get_username_provider()]))

# Simple commit that adds a directory
editor = conn.get_commit_editor({"svn:log": "Commit message"})
root = editor.open_root()
# Add a directory
dir = root.add_directory("somedir")
dir.close()
# Add and edit a file
file = root.add_file("somefile")
# Set the svn:executable attribute
file.change_prop("svn:executable", "*")
# Obtain a textdelta handler and send the new file contents
txdelta = file.apply_textdelta()
delta.send_stream(BytesIO(b"new file contents"), txdelta)
file.close()
root.close()
editor.close()

# Rename the directory
editor = conn.get_commit_editor({"svn:log": "Commit message"})
root = editor.open_root()
# Create a new directory copied from somedir:1
dir = root.add_directory("new dir name", "%s/somedir" % repo_url, 1)
dir.close()
# Remove the original directory
root.delete_entry("somedir")
root.close()
editor.close()
示例#12
0
 def modify(self, contents=None):
     if contents is None:
         contents = os.urandom(100)
     txdelta = self.file.apply_textdelta()
     delta.send_stream(BytesIO(contents), txdelta)
示例#13
0
conn = RemoteAccess(repo_url,
                    auth=Auth([get_username_provider()]))

# Simple commit that adds a directory
editor = conn.get_commit_editor({"svn:log": "Commit message"})
root = editor.open_root()
# Add a directory
dir = root.add_directory("somedir")
dir.close()
# Add and edit a file
file = root.add_file("somefile")
# Set the svn:executable attribute
file.change_prop("svn:executable", "*")
# Obtain a textdelta handler and send the new file contents
txdelta = file.apply_textdelta()
delta.send_stream(BytesIO(b"new file contents"), txdelta)
file.close()
root.close()
editor.close()

# Rename the directory
editor = conn.get_commit_editor({"svn:log": "Commit message"})
root = editor.open_root()
# Create a new directory copied from somedir:1
dir = root.add_directory("new dir name", "%s/somedir" % repo_url, 1)
dir.close()
# Remove the original directory
root.delete_entry("somedir")
root.close()
editor.close()