# HG changeset patch # User Jun Wu # Date 1465681017 -3600 # Node ID d890d8d4e168aa63dd7b7b7e118ffefcbf8258b4 # Parent 4217a050a088344ab5f623ccc193e09c1e19f17c svnrepo: change svnurl to not use self.svn Before this patch, svnremoterepo uses self.svn.svn_url to answer svnurl. Accessing svnremoterepo.svn will create an svn ra object, which can be expensive because it involves network i/o. This patch changes it to use self.svnauth, which is a local operation. It speeds up "hg svn info" a lot. The old behavior is hard to test since instantiating a svn ra object requires a real URL. The change does not seem worth to set up SSH and HTTP servers to test. Therefore the tests are added only for the new behavior. diff --git a/hgsubversion/svnrepo.py b/hgsubversion/svnrepo.py --- a/hgsubversion/svnrepo.py +++ b/hgsubversion/svnrepo.py @@ -157,7 +157,7 @@ class svnremoterepo(peerrepository): @property def svnurl(self): - return self.svn.svn_url + return self.svnauth[0] @propertycache def svn(self): diff --git a/tests/test_urls.py b/tests/test_urls.py --- a/tests/test_urls.py +++ b/tests/test_urls.py @@ -8,58 +8,61 @@ from hgsubversion import svnrepo class TestSubversionUrls(test_util.TestBase): def test_standard_url(self): - self.assertEqual((None, None, 'file:///var/svn/repo'), - parse_url('file:///var/svn/repo')) + self.check_parse_url((None, None, 'file:///var/svn/repo'), + ('file:///var/svn/repo', )) def test_user_url(self): - self.assertEqual( + self.check_parse_url( ('joe', None, 'https://svn.testurl.com/repo'), - parse_url('https://joe@svn.testurl.com/repo')) - self.assertEqual( + ('https://joe@svn.testurl.com/repo', )) + self.check_parse_url( ('bob', None, 'https://svn.testurl.com/repo'), - parse_url('https://joe@svn.testurl.com/repo', 'bob')) + ('https://joe@svn.testurl.com/repo', 'bob', )) def test_password_url(self): - self.assertEqual( + self.check_parse_url( (None, 't3stpw', 'svn+ssh://svn.testurl.com/repo'), - parse_url('svn+ssh://:t3stpw@svn.testurl.com/repo')) - self.assertEqual( + ('svn+ssh://:t3stpw@svn.testurl.com/repo', )) + self.check_parse_url( (None, '123abc', 'svn+ssh://svn.testurl.com/repo'), - parse_url('svn+ssh://:t3stpw@svn.testurl.com/repo', None, '123abc')) + ('svn+ssh://:t3stpw@svn.testurl.com/repo', None, '123abc', )) def test_svnssh_preserve_user(self): - self.assertEqual( + self.check_parse_url( ('user', 't3stpw', 'svn+ssh://user@svn.testurl.com/repo',), - parse_url('svn+ssh://user:t3stpw@svn.testurl.com/repo')) - self.assertEqual( + ('svn+ssh://user:t3stpw@svn.testurl.com/repo', )) + self.check_parse_url( ('bob', '123abc', 'svn+ssh://bob@svn.testurl.com/repo',), - parse_url('svn+ssh://user:t3stpw@svn.testurl.com/repo', 'bob', '123abc')) - self.assertEqual( + ('svn+ssh://user:t3stpw@svn.testurl.com/repo', 'bob', '123abc', )) + self.check_parse_url( ('user2', None, 'svn+ssh://user2@svn.testurl.com/repo',), - parse_url('svn+ssh://user2@svn.testurl.com/repo')) - self.assertEqual( + ('svn+ssh://user2@svn.testurl.com/repo', )) + self.check_parse_url( ('bob', None, 'svn+ssh://bob@svn.testurl.com/repo',), - parse_url('svn+ssh://user2@svn.testurl.com/repo', 'bob')) + ('svn+ssh://user2@svn.testurl.com/repo', 'bob', )) def test_user_password_url(self): - self.assertEqual( + self.check_parse_url( ('joe', 't3stpw', 'https://svn.testurl.com/repo'), - parse_url('https://joe:t3stpw@svn.testurl.com/repo')) - self.assertEqual( + ('https://joe:t3stpw@svn.testurl.com/repo', )) + self.check_parse_url( ('bob', '123abc', 'https://svn.testurl.com/repo'), - parse_url('https://joe:t3stpw@svn.testurl.com/repo', 'bob', '123abc')) + ('https://joe:t3stpw@svn.testurl.com/repo', 'bob', '123abc', )) def test_url_rewriting(self): ui = test_util.ui.ui() ui.setconfig('hgsubversion', 'username', 'bob') repo = svnrepo.svnremoterepo(ui, 'svn+ssh://joe@foo/bar') self.assertEqual('svn+ssh://bob@foo/bar', repo.svnauth[0]) + self.assertEqual('svn+ssh://bob@foo/bar', repo.svnurl) repo = svnrepo.svnremoterepo(ui, 'svn+http://joe@foo/bar') self.assertEqual(('http://foo/bar', 'bob', None), repo.svnauth) + self.assertEqual('http://foo/bar', repo.svnurl) repo = svnrepo.svnremoterepo(ui, 'svn+https://joe@foo/bar') self.assertEqual(('https://foo/bar', 'bob', None), repo.svnauth) + self.assertEqual('https://foo/bar', repo.svnurl) def test_quoting(self): ui = self.ui() @@ -72,3 +75,11 @@ class TestSubversionUrls(test_util.TestB repo1 = svnrepo.svnremoterepo(ui, repo_url + subdir) repo2 = svnrepo.svnremoterepo(ui, repo_url + quoted_subdir) self.assertEqual(repo1.svnurl, repo2.svnurl) + + def check_parse_url(self, expected, args): + self.assertEqual(expected, parse_url(*args)) + if len(args) == 1: + repo = svnrepo.svnremoterepo(self.ui(), path=args[0]) + self.assertEqual(expected[2], repo.svnauth[0]) + self.assertEqual(expected[2], repo.svnurl) +