# HG changeset patch # User Augie Fackler # Date 1229049717 21600 # Node ID 9ffde8662967ba7b65c462863074bf567573b4bd # Parent 89a737852d3355ab7cbc5f65dd8b81f5069b552c util: Add a command to normalize svn urls and use it in a couple of places. Test that it works and prevents failed assertions. diff --git a/__init__.py b/__init__.py --- a/__init__.py +++ b/__init__.py @@ -23,6 +23,7 @@ def svn_fetch(ui, svn_url, hg_repo_path= hg_repo_path = hg.defaultdest(svn_url) + "-hg" ui.status("Assuming destination %s\n" % hg_repo_path) should_update = not os.path.exists(hg_repo_path) + svn_url = util.normalize_url(svn_url) res = fetch_command.fetch_revisions(ui, svn_url, hg_repo_path, **opts) if (res is None or res == 0) and should_update: repo = hg.repository(ui, hg_repo_path) diff --git a/fetch_command.py b/fetch_command.py --- a/fetch_command.py +++ b/fetch_command.py @@ -28,6 +28,7 @@ def fetch_revisions(ui, svn_url, hg_repo **opts): """Pull new revisions from Subversion. """ + svn_url = util.normalize_url(svn_url) old_encoding = merc_util._encoding merc_util._encoding = 'UTF-8' skipto_rev=int(skipto_rev) diff --git a/tests/test_utility_commands.py b/tests/test_utility_commands.py --- a/tests/test_utility_commands.py +++ b/tests/test_utility_commands.py @@ -4,7 +4,7 @@ from mercurial import ui from mercurial import hg import utility_commands - +import fetch_command import test_util expected_info_output = '''URL: file://%(repo)s/%(branch)s @@ -48,3 +48,17 @@ class UtilityTests(test_util.TestBase): utility_commands.print_wc_url(u, self.repo, self.wc_path) expected = 'file://%s\n' % urllib.quote(self.repo_path) self.assertEqual(u.stream.getvalue(), expected) + + def test_url_is_normalized(self): + """Verify url gets normalized on initial clone. + """ + test_util.load_svndump_fixture(self.repo_path, 'two_revs.svndump') + fetch_command.fetch_revisions(ui.ui(), + svn_url=test_util.fileurl(self.repo_path)+'/', + hg_repo_path=self.wc_path, + stupid=False) + hg.update(self.repo, 'tip') + u = ui.ui() + utility_commands.print_wc_url(u, self.repo, self.wc_path) + expected = 'file://%s\n' % urllib.quote(self.repo_path) + self.assertEqual(u.stream.getvalue(), expected) diff --git a/util.py b/util.py --- a/util.py +++ b/util.py @@ -23,6 +23,12 @@ def generate_help(): return "\n".join(ret) + '\n' +def normalize_url(svn_url): + while svn_url[-1] == '/': + svn_url = svn_url[:-1] + return svn_url + + def wipe_all_files(hg_wc_path): files = [f for f in os.listdir(hg_wc_path) if f != '.hg'] for f in files: @@ -69,10 +75,10 @@ def parse_revmap(revmap_filename): class PrefixMatch(object): def __init__(self, prefix): self.p = prefix - + def files(self): return [] - + def __call__(self, fn): return fn.startswith(self.p)