changeset 468:037bba1c6736

svnrepo: expose the same svnurl than SubversionRepo Since the ssh+svn URLs depend on supplied credentials, and because we want to get the actual SVN URL without talking to the remote repository, we duplicate the work done by SubversionRepo.
author Patrick Mezard <pmezard@gmail.com>
date Sat, 18 Jul 2009 20:44:33 -0500
parents 3941d73c262e
children 5567af673f83
files hgsubversion/svnrepo.py tests/test_urls.py
diffstat 2 files changed, 19 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/svnrepo.py
+++ b/hgsubversion/svnrepo.py
@@ -76,18 +76,24 @@ class svnremoterepo(mercurial.repo.repos
         self.capabilities = set(['lookup', 'subversion'])
 
     @propertycache
-    def svnurl(self):
-        return util.normalize_url(self.path)
-
-    @propertycache
-    def svn(self):
+    def svnauth(self):
         # DO NOT default the user to hg's getuser(). If you provide
         # *any* default username to Subversion, it won't use any remembered
         # username for the desired realm, breaking OS X Keychain support,
         # GNOME keyring support, and all similar tools.
         user = self.ui.config('hgsubversion', 'username')
         passwd = self.ui.config('hgsubversion', 'password')
-        return svnwrap.SubversionRepo(self.svnurl, user, passwd)
+        url = util.normalize_url(self.path)
+        user, passwd, url = svnwrap.parse_url(url, user, passwd)
+        return url, user, passwd
+
+    @property
+    def svnurl(self):
+        return self.svnauth[0]
+
+    @propertycache
+    def svn(self):
+        return svnwrap.SubversionRepo(*self.svnauth)
 
     @property
     def svnuuid(self):
--- a/tests/test_urls.py
+++ b/tests/test_urls.py
@@ -1,6 +1,7 @@
 import test_util
 import unittest
 from hgsubversion.svnwrap.svn_swig_wrapper import parse_url
+from hgsubversion import svnrepo
 
 class TestSubversionUrls(test_util.TestBase):
     def test_standard_url(self):
@@ -45,6 +46,12 @@ class TestSubversionUrls(test_util.TestB
             ('bob', '123abc', 'https://svn.testurl.com/repo'),
             parse_url('https://joe:t3stpw@svn.testurl.com/repo', 'bob', '123abc'))
 
+class TestSvnRepo(test_util.TestBase):
+    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.svnurl)
 
 def suite():
     all = [unittest.TestLoader().loadTestsFromTestCase(TestSubversionUrls)]