示例#1
0
    def test_checks_uuid(self):
        repos_url = self.make_svn_repository('d')

        dc = self.get_commit_editor(repos_url)
        dc.add_dir("bp")
        dc.close()

        mapping = mapping_registry.get_default()()
        ra = RemoteAccess(repos_url.encode("utf-8"),
                          auth=Auth([get_username_provider()]))
        revnum = ra.get_latest_revnum()
        revprops = {
            SVN_REVPROP_BZR_REPOS_UUID: "otheruuid",
            "svn:log": "bla",
            SVN_REVPROP_BZR_ROOT: "bp",
            SVN_REVPROP_BZR_MAPPING_VERSION: mapping.name,
            SVN_REVPROP_BZR_BASE_REVISION: "therealbaserevid"
        }
        dc = TestCommitEditor(ra.get_commit_editor(revprops), ra.url, revnum)
        dc.open_dir("bp").add_file("bp/la").modify()
        dc.close()

        repos = Repository.open(repos_url)

        revmeta1 = repos._revmeta_provider.get_revision(u"bp", 1)
        revmeta2 = repos._revmeta_provider.get_revision(u"bp", 2)

        self.assertEquals(
            mapping.revision_id_foreign_to_bzr((repos.uuid, "bp", 1)),
            revmeta2.get_lhs_parent_revid(mapping, revmeta1))
示例#2
0
    def get_commit_editor(self, url, message="Test commit"):
        """Obtain a commit editor.

        :param url: URL to connect to
        :param message: Commit message
        :return: Commit editor object
        """
        ra_ctx = RemoteAccess(url.encode("utf-8"), auth=Auth([ra.get_username_provider()]))
        revnum = ra_ctx.get_latest_revnum()
        return TestCommitEditor(ra_ctx.get_commit_editor({"svn:log": message}), ra_ctx.url, revnum)
示例#3
0
    def get_commit_editor(self, url, message="Test commit"):
        """Obtain a commit editor.

        :param url: URL to connect to
        :param message: Commit message
        :return: Commit editor object
        """
        ra_ctx = RemoteAccess(url.encode("utf-8"),
            auth=Auth([ra.get_username_provider()]))
        revnum = ra_ctx.get_latest_revnum()
        return TestCommitEditor(ra_ctx.get_commit_editor({"svn:log": message}),
            ra_ctx.url, revnum)
示例#4
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()
示例#5
0
from cStringIO import StringIO
from subvertpy import delta, repos
from subvertpy.ra import RemoteAccess, Auth, get_username_provider

# Create a repository
repos.create("tmprepo")

# Connect to the "remote" repository using the file transport. 
# Note that a username provider needs to be provided, so that Subversion
# knows who to record as the author of new commits made over this connection.
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()
示例#6
0
class RecordingRemoteAccess(object):
    """Trivial RemoteAccess wrapper that records all activity."""

    busy = property(lambda self: self.actual.busy)
    url = property(lambda self: self.actual.url)

    def __init__(self, *args, **kwargs):
        self.actual = RemoteAccess(*args, **kwargs)

    def check_path(self, path, revnum):
        self.__class__.calls.append(("check-path", (revnum, path)))
        return self.actual.check_path(path, revnum)

    def stat(self, path, revnum):
        self.__class__.calls.append(("stat", (revnum, path)))
        return self.actual.stat(path, revnum)

    def has_capability(self, cap):
        self.__class__.calls.append(("has-capability", (cap, )))
        return self.actual.has_capability(cap)

    def get_uuid(self):
        self.__class__.calls.append(("get-uuid", ()))
        return self.actual.get_uuid()

    def get_repos_root(self):
        self.__class__.calls.append(("get-repos", ()))
        return self.actual.get_repos_root()

    def get_latest_revnum(self):
        self.__class__.calls.append(("get-latest-revnum", ()))
        return self.actual.get_latest_revnum()

    def get_log(self, callback, paths, from_revnum, to_revnum, limit, *args,
                **kwargs):
        self.__class__.calls.append(
            ("log", (from_revnum, to_revnum, paths, limit)))
        return self.actual.get_log(callback, paths, from_revnum, to_revnum,
                                   limit, *args, **kwargs)

    def iter_log(self, paths, from_revnum, to_revnum, limit, *args, **kwargs):
        self.__class__.calls.append(
            ("log", (from_revnum, to_revnum, paths, limit)))
        return self.actual.iter_log(paths, from_revnum, to_revnum, limit,
                                    *args, **kwargs)

    def change_rev_prop(self, revnum, name, value):
        self.__class__.calls.append(("change-revprop", (revnum, name, value)))
        return self.actual.change_rev_prop(revnum, name, value)

    def get_dir(self, path, revnum=-1, fields=0):
        self.__class__.calls.append(("get-dir", (path, revnum, fields)))
        return self.actual.get_dir(path, revnum, fields)

    def get_file(self, path, stream, revnum):
        self.__class__.calls.append(("get-file", (path, revnum)))
        return self.actual.get_file(path, stream, revnum)

    def get_file_revs(self, path, start_revnum, end_revnum, handler):
        self.__class__.calls.append(
            ("get-file-revs", (path, start_revnum, end_revnum)))
        return self.actual.get_file_revs(path, start_revnum, end_revnum,
                                         handler)

    def revprop_list(self, revnum):
        self.__class__.calls.append(("revprop-list", (revnum, )))
        return self.actual.revprop_list(revnum)

    def get_locations(self, path, peg_revnum, revnums):
        self.__class__.calls.append(
            ("get-locations", (path, peg_revnum, revnums)))
        return self.actual.get_locations(path, peg_revnum, revnums)

    def do_update(self, revnum, path, start_empty, editor):
        self.__class__.calls.append(("do-update", (revnum, path, start_empty)))
        return self.actual.do_update(revnum, path, start_empty, editor)

    def do_diff(self,
                revision_to_update,
                diff_target,
                versus_url,
                diff_editor,
                recurse=True,
                ignore_ancestry=False,
                text_deltas=False,
                depth=None):
        self.__class__.calls.append(("diff", (revision_to_update, diff_target,
                                              versus_url, text_deltas, depth)))
        return self.actual.do_diff(revision_to_update, diff_target, versus_url,
                                   diff_editor, recurse, ignore_ancestry,
                                   text_deltas)

    def do_switch(self, revnum, path, start_empty, to_url, editor):
        self.__class__.calls.append(
            ("switch", (revnum, path, start_empty, to_url)))
        return self.actual.do_switch(revnum, path, start_empty, to_url, editor)

    def reparent(self, url):
        self.__class__.calls.append(("reparent", (url, )))
        return self.actual.reparent(url)

    def get_commit_editor(self, *args, **kwargs):
        self.__class__.calls.append(("commit", ()))
        return self.actual.get_commit_editor(*args, **kwargs)

    def rev_proplist(self, revnum):
        self.__class__.calls.append(("rev-proplist", (revnum, )))
        return self.actual.rev_proplist(revnum)

    def replay_range(self,
                     start_revision,
                     end_revision,
                     low_water_mark,
                     cbs,
                     send_deltas=True):
        self.__class__.calls.append(
            ("replay-range", (start_revision, end_revision, low_water_mark,
                              send_deltas)))
        return self.actual.replay_range(start_revision, end_revision,
                                        low_water_mark, cbs, send_deltas)

    def replay(self, revision, low_water_mark, editor, send_deltas=True):
        self.__class__.calls.append(
            ("replay", (revision, low_water_mark, send_deltas)))
        return self.actual.replay(revision, low_water_mark, editor,
                                  send_deltas)
示例#7
0
import os
from cStringIO import StringIO
from subvertpy import delta, repos
from subvertpy.ra import RemoteAccess, Auth, get_username_provider

# Create a repository
repos.create("tmprepo")

# Connect to the "remote" repository using the file transport.
# Note that a username provider needs to be provided, so that Subversion
# knows who to record as the author of new commits made over this connection.
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()