def test_mkdir_missing_parent(self): repos_url = self.make_svn_repository('a') t = SvnRaTransport(repos_url) self.assertRaises(NoSuchFile, t.mkdir, "bla/subdir") c = ra.RemoteAccess(repos_url) self.assertEquals(c.check_path("bla/subdir", c.get_latest_revnum()), subvertpy.NODE_NONE)
def ra(self): """Lazily creates the ``RemoteAccess`` object so ``accept_ssl_certificate`` works properly. """ if not hasattr(self, '_ra'): self._ra = ra.RemoteAccess(self.repopath, auth=self.auth) return self._ra
def test_diff(self): r = ra.RemoteAccess(self.repos_url, auth=ra.Auth([ra.get_username_provider()])) dc = self.get_commit_editor(self.repos_url) f = dc.add_file("foo") f.modify("foo1") dc.close() dc = self.get_commit_editor(self.repos_url) f = dc.open_file("foo") f.modify("foo2") dc.close() if client.api_version() < (1, 5): self.assertRaises(NotImplementedError, self.client.diff, 1, 2, self.repos_url, self.repos_url) return # Skip test (outf, errf) = self.client.diff(1, 2, self.repos_url, self.repos_url) self.addCleanup(outf.close) self.addCleanup(errf.close) self.assertEqual( """Index: foo =================================================================== --- foo\t(revision 1) +++ foo\t(revision 2) @@ -1 +1 @@ -foo1 \\ No newline at end of file +foo2 \\ No newline at end of file """, outf.read()) self.assertEqual("", errf.read())
def client_log(self, url, start_revnum, stop_revnum): """Fetch the log :param url: URL to log :param start_revnum: Start revision of the range to log over :param start_revnum: Stop revision of the range to log over :return: Dictionary """ r = ra.RemoteAccess(url) assert isinstance(url, str) ret = {} def rcvr(orig_paths, rev, revprops, has_children=None): ret[rev] = (orig_paths, revprops.get(properties.PROP_REVISION_AUTHOR), revprops.get(properties.PROP_REVISION_DATE), revprops.get(properties.PROP_REVISION_LOG)) r.get_log(rcvr, [""], start_revnum, stop_revnum, 0, True, True, revprops=[ properties.PROP_REVISION_AUTHOR, properties.PROP_REVISION_DATE, properties.PROP_REVISION_LOG ]) return ret
def test_commit(self): self.build_tree({"dc/foo": None}) self.client.add("dc/foo") self.client.log_msg_func = lambda c: "Amessage" self.client.commit(["dc"]) r = ra.RemoteAccess(self.repos_url) revprops = r.rev_proplist(1) self.assertEqual(b"Amessage", revprops["svn:log"])
def test_commit_start(self): self.build_tree({"dc/foo": None}) self.client = client.Client(auth=ra.Auth([ra.get_username_provider()]), log_msg_func=lambda c: "Bmessage") self.client.add("dc/foo") self.client.commit(["dc"]) r = ra.RemoteAccess(self.repos_url) revprops = r.rev_proplist(1) self.assertEqual("Bmessage", revprops["svn:log"])
def client_set_revprop(self, url, revnum, name, value): """Set a revision property on a repository. :param url: URL of the repository :param revnum: Revision number of the revision :param name: Name of the property :param value: Value of the property, None to remove """ r = ra.RemoteAccess(url, auth=Auth([ra.get_username_provider()])) r.change_rev_prop(revnum, name, value)
def client_get_revprop(self, url, revnum, name): """Get the revision property. :param url: URL of the repository :param revnum: Revision number :param name: Property name :return: Revision property value """ r = ra.RemoteAccess(url) return r.rev_proplist(revnum)[name]
def connect(self): """ Given a path, then connect to that path """ # Check if the path contains a 'file://' indicator #if self.path.find() == -1: # self.abs_path = "file://" + self.path #else: # self.abs_path = self.path self.ra_api = ra.RemoteAccess(self.path)
def test_push_unnecessary_merge(self): from breezy.debug import debug_flags debug_flags.add("commit") debug_flags.add("fetch") repos_url = self.make_svn_repository("a") bzrwt = ControlDir.create_standalone_workingtree("c") self.build_tree({'c/registry/generic.c': b"Tour"}) bzrwt.add("registry") bzrwt.add("registry/generic.c") revid1 = bzrwt.commit("Add initial directory + file", rev_id=b"initialrevid") # Push first branch into Subversion newdir = ControlDir.open(repos_url + "/trunk") config = BranchConfig(repos_url + "/trunk", newdir.find_repository().uuid) config.set_user_option("allow_metadata_in_file_properties", "True") newbranch = newdir.import_branch(bzrwt.branch) c = ra.RemoteAccess(repos_url) self.assertTrue( c.check_path("trunk/registry/generic.c", c.get_latest_revnum()) == subvertpy.NODE_FILE) dc = self.get_commit_editor(repos_url) trunk = dc.open_dir("trunk") registry = trunk.open_dir("trunk/registry") registry.open_file("trunk/registry/generic.c").modify(b"BLA") dc.close() mapping = newdir.find_repository().get_mapping() merge_revid = newdir.find_repository().generate_revision_id( 2, u"trunk", mapping) # Merge self.build_tree({'c/registry/generic.c': b"DE"}) bzrwt.add_pending_merge(merge_revid) self.assertEquals(bzrwt.get_parent_ids()[1], merge_revid) revid2 = bzrwt.commit("Merge something", rev_id=b"mergerevid") bzr_parents = bzrwt.branch.repository.get_revision(revid2).parent_ids trunk = Branch.open(repos_url + "/trunk") self.assertRaises(AppendRevisionsOnlyViolation, trunk.pull, bzrwt.branch) trunk.set_append_revisions_only(False) trunk.pull(bzrwt.branch) self.assertEquals(tuple(bzr_parents), trunk.repository.get_revision(revid2).parent_ids) self.assertEquals((2, revid2), trunk.last_revision_info()) self.assertEquals( b'1 initialrevid\n2 mergerevid\n', self.client_get_prop(repos_url + "/trunk", SVN_PROP_BZR_REVISION_ID + "v3-trunk0", c.get_latest_revnum()))
def test_mkdir(self): repos_url = self.make_svn_repository('a') t = SvnRaTransport(repos_url) t.mkdir("bla") c = ra.RemoteAccess(repos_url) self.assertEquals(c.check_path("bla", c.get_latest_revnum()), subvertpy.NODE_DIR) t.mkdir("bla/subdir") self.assertEquals(c.check_path("bla/subdir", c.get_latest_revnum()), subvertpy.NODE_DIR) t = SvnRaTransport(repos_url + "/nonexistant") t.mkdir(".")
def init_ra_and_client(self): """ Initializes the RA and client layers. With the SWIG bindings, getting unified diffs runs the remote server sometimes runs out of open files. It is not known whether the Subvertpy is affected by this. """ def getclientstring(): return 'hgsubversion' # TODO: handle certificate authentication, Mercurial style def getpass(realm, username, may_save): return self.username or username, self.password or '', False def getuser(realm, may_save): return self.username or '', False providers = ra.get_platform_specific_client_providers() providers += [ ra.get_simple_provider(), ra.get_username_provider(), ra.get_ssl_client_cert_file_provider(), ra.get_ssl_client_cert_pw_file_provider(), ra.get_ssl_server_trust_file_provider(), ra.get_username_prompt_provider(getuser, 0), ra.get_simple_prompt_provider(getpass, 0), ] auth = ra.Auth(providers) if self.username: auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_USERNAME, self.username) if self.password: auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_PASSWORD, self.password) self.remote = ra.RemoteAccess(url=self.svn_url, client_string_func=getclientstring, auth=auth) self.client = client.Client() self.client.auth = auth
def test_commit_sets_mergeinfo(self): repos_url = self.make_repository('d') dc = self.get_commit_editor(repos_url) foo = dc.add_dir("trunk") foo.add_file("trunk/bla").modify(b"bla") dc.add_dir("branches") dc.close() dc = self.get_commit_editor(repos_url) tags = dc.add_dir("tags") foobranch = tags.add_dir("tags/foo") foobranch.add_file("tags/foo/afile").modify() dc.close() dc = self.get_commit_editor(repos_url) tags = dc.open_dir("tags") foobranch = tags.open_dir("tags/foo") foobranch.add_file("tags/foo/bfile").modify() dc.close() branch = Branch.open(repos_url + "/trunk") foobranch = Branch.open(repos_url + "/tags/foo") branch.lock_write() self.addCleanup(branch.unlock) builder = branch.get_commit_builder( [branch.last_revision(), foobranch.last_revision()], revision_id="my-revision-id") builder.finish_inventory() builder.commit("foo") self.assertEqual( "/tags/foo:2-3\n", self.client_get_prop("%s/trunk" % repos_url, "svn:mergeinfo", 4)) try: c = ra.RemoteAccess(repos_url) mi = c.mergeinfo(["trunk"], 4) self.assertEquals({"trunk": {"/tags/foo": [(1, 3, 1)]}}, mi) except NotImplementedError: raise TestSkipped("mergeinfo not available with svn 1.4")
def setUp(self): super(TestRemoteAccess, self).setUp() self.repos_url = self.make_repository("d") self.ra = ra.RemoteAccess(self.repos_url, auth=ra.Auth([ra.get_username_provider()]))
def init_ra_and_client(self): """ Initializes the RA and client layers. With the SWIG bindings, getting unified diffs runs the remote server sometimes runs out of open files. It is not known whether the Subvertpy is affected by this. """ def getclientstring(): return 'hgsubversion' def simple(realm, username, may_save): return _prompt.simple(realm, username, may_save) def username(realm, may_save): return _prompt.username(realm, may_save) def ssl_client_cert(realm, may_save): return _prompt.ssl_client_cert(realm, may_save) def ssl_client_cert_pw(realm, may_save): return _prompt.ssl_client_cert_pw(realm, may_save) def ssl_server_trust(realm, failures, cert_info, may_save): creds = _prompt.ssl_server_trust(realm, failures, cert_info, may_save) if creds is None: # We need to reject the certificate, but subvertpy doesn't # handle None as a return value here, and requires # we instead return a tuple of (int, bool). Because of that, # we return (0, False) instead. creds = (0, False) return creds providers = ra.get_platform_specific_client_providers() providers += [ ra.get_simple_provider(), ra.get_username_provider(), ra.get_ssl_client_cert_file_provider(), ra.get_ssl_client_cert_pw_file_provider(), ra.get_ssl_server_trust_file_provider(), ] if _prompt: providers += [ ra.get_simple_prompt_provider(simple, 2), ra.get_username_prompt_provider(username, 2), ra.get_ssl_client_cert_prompt_provider(ssl_client_cert, 2), ra.get_ssl_client_cert_pw_prompt_provider(ssl_client_cert_pw, 2), ra.get_ssl_server_trust_prompt_provider(ssl_server_trust), ] auth = ra.Auth(providers) if self.username: auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_USERNAME, self.username) if self.password: auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_PASSWORD, self.password) try: self.remote = ra.RemoteAccess(url=self.svn_url, client_string_func=getclientstring, auth=auth) except SubversionException, e: # e.child contains a detailed error messages msglist = [] svn_exc = e while svn_exc: if svn_exc.args[0]: msglist.append(svn_exc.args[0]) svn_exc = svn_exc.child msg = '\n'.join(msglist) raise common.SubversionConnectionException(msg)
def calculate_hot_spots(jiraKey,repoUrl,end_time = time.time(),cache_update_time = time.time()): providers = ra.get_platform_specific_client_providers() providers += [ ra.get_simple_provider(), ra.get_username_provider(), ra.get_ssl_client_cert_file_provider(), ra.get_ssl_client_cert_pw_file_provider(), ra.get_ssl_server_trust_file_provider(), ra.get_username_prompt_provider(getuser, 0), ra.get_simple_prompt_provider(getpass, 0), ] auth=ra.Auth(providers) auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_USERNAME, settings.username) auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_PASSWORD, settings.password) conn = ra.RemoteAccess(repoUrl,auth=auth) global bugCache global svnCache if jiraKey in bugCache: bugs = bugCache[jiraKey] else: bugs = [] if jiraKey in svnCache: svn_entries = svnCache[jiraKey] else: svn_entries = [] start_time = end_time scores = {} authors = {} modified_files = [] if (len(bugs) == 0 and len(svn_entries) == 0) or time.time() > cache_update_time: #retrieve the SVN log entries for (changed_paths, rev, revprops, has_children) in conn.iter_log(paths=None,start=0, end=conn.get_latest_revnum(), discover_changed_paths=True): svn_entries.append((changed_paths, rev, revprops, has_children)) #query jira for all the closed bugs bugs = get_bugs(jiraKey) #add to the cache dictionary bugCache[jiraKey] = bugs svnCache[jiraKey] = svn_entries for (changed_paths, rev, revprops, has_children) in svn_entries: commit_time = time.mktime(dateutil.parser.parse(revprops["svn:date"]).timetuple()) if commit_time <= end_time: #this svn commit contains code that fixed a bug if fixed_bug(revprops["svn:log"].decode('utf8') ,bugs): #only consider *.java and *.js files for now modified_files.extend([(commit_time,filename,revprops["svn:author"]) for filename in changed_paths.keys() if is_source_file(filename)]) if commit_time < start_time: start_time = commit_time for modified_file in modified_files: filename = modified_file[1] author = modified_file[2] #as per Google's description, normalize t between 0 and 1 t = (modified_file[0]-start_time)/(end_time-start_time) #google's magic sauce score = 1/(1+(math.e**(-12*t+12))) #map the score to the file if filename not in scores: scores[filename] = score else: scores[filename] = scores[filename] + score #map the author(s) to the file if filename not in authors: authors[filename] = [author] else: authors[filename].append(author) #convert the list of authors to a map containing the counts for filename,authorsList in authors.items(): authors[filename]=Counter(authorsList) sorted_scores = sorted(scores.iteritems(), key=operator.itemgetter(1)) sorted_scores.reverse() #add the author count to the scores tuple scoresWithAuthors =[] for score in sorted_scores: scoresWithAuthors.append((score[0],score[1],authors[score[0]])) #return the top 10 hotspots return scoresWithAuthors[:10]