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))
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)
def main(local_url, svn_url, revision_start, revision_end, debug, cleanup): """Script to present how to use Replay class.""" conn = RemoteAccess(svn_url.encode("utf-8"), auth=Auth([get_username_provider()])) os.makedirs(local_url, exist_ok=True) rootpath = tempfile.mkdtemp( prefix=local_url, suffix="-" + os.path.basename(svn_url) ) rootpath = os.fsencode(rootpath) # Do not go beyond the repository's latest revision revision_end_max = conn.get_latest_revnum() if revision_end == -1: revision_end = revision_end_max revision_end = min(revision_end, revision_end_max) try: replay = Replay(conn, rootpath) for rev in range(revision_start, revision_end + 1): contents, skipped_contents, directories = replay.compute_objects(rev) print( "r%s %s (%s new contents, %s new directories)" % ( rev, hashutil.hash_to_hex(replay.directory.hash), len(contents) + len(skipped_contents), len(directories), ) ) if debug: print("%s" % rootpath.decode("utf-8")) finally: if cleanup: if os.path.exists(rootpath): shutil.rmtree(rootpath)
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)
#!/usr/bin/python # Demonstrates how to iterate over the log of a Subversion repository. from subvertpy.ra import RemoteAccess conn = RemoteAccess("svn://svn.samba.org/subvertpy/trunk") for (changed_paths, rev, revprops, has_children) in conn.iter_log( paths=None, start=0, end=conn.get_latest_revnum(), discover_changed_paths=True ): print "=" * 79 print "%d:" % rev print "Revision properties:" for entry in revprops.items(): print " %s: %s" % entry print "" print "Changed paths" for path, (action, from_path, from_rev, node_kind) in changed_paths.iteritems(): print " %s (%s)" % (path, action)
#!/usr/bin/python # Demonstrates how to iterate over the log of a Subversion repository. from subvertpy.ra import RemoteAccess conn = RemoteAccess("svn://svn.samba.org/subvertpy/trunk") for (changed_paths, rev, revprops, has_children) in conn.iter_log( paths=None, start=0, end=conn.get_latest_revnum(), discover_changed_paths=True): print("=" * 79) print("%d:" % rev) print("Revision properties:") for entry in revprops.items(): print(" %s: %s" % entry) print("") print("Changed paths") for path, (action, from_path, from_rev, node_kind) in ( changed_paths.items()): print(" %s (%s)" % (path, action))
#!/usr/bin/python # Demonstrates how to iterate over the log of a Subversion repository. from subvertpy.ra import RemoteAccess conn = RemoteAccess("svn://svn.samba.org/subvertpy/trunk") for (changed_paths, rev, revprops, has_children) in conn.iter_log(paths=None, start=0, end=conn.get_latest_revnum(), discover_changed_paths=True): print("=" * 79) print("%d:" % rev) print("Revision properties:") for entry in revprops.items(): print(" %s: %s" % entry) print("") print("Changed paths") for path, (action, from_path, from_rev, node_kind) in (changed_paths.items()): print(" %s (%s)" % (path, action))