Mercurial > hg
changeset 7074:b1a4f67b98d0
convert: properly encode subversion URLs (issue 1224)
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Fri, 10 Oct 2008 11:36:02 +0200 |
parents | af1117f37fa7 |
children | 6db6f6db026a 967adcf5910d |
files | hgext/convert/subversion.py tests/test-convert-svn-source tests/test-convert-svn-source.out |
diffstat | 3 files changed, 31 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/convert/subversion.py Fri Oct 10 11:32:38 2008 +0200 +++ b/hgext/convert/subversion.py Fri Oct 10 11:36:02 2008 +0200 @@ -21,6 +21,7 @@ import sys import cPickle as pickle import tempfile +import urllib from mercurial import strutil, util from mercurial.i18n import _ @@ -54,7 +55,7 @@ path = os.path.normpath(os.path.abspath(path)) if os.name == 'nt': path = '/' + util.normpath(path) - return 'file://%s' % path + return 'file://%s' % urllib.quote(path) return path def optrev(number): @@ -172,10 +173,10 @@ self.transport = transport.SvnRaTransport(url=self.url) self.ra = self.transport.ra self.ctx = self.transport.client - self.base = svn.ra.get_repos_root(self.ra) + self.baseurl = svn.ra.get_repos_root(self.ra) # Module is either empty or a repository path starting with # a slash and not ending with a slash. - self.module = self.url[len(self.base):] + self.module = urllib.unquote(self.url[len(self.baseurl):]) self.prevmodule = None self.rootmodule = self.module self.commits = {} @@ -230,7 +231,7 @@ def exists(self, path, optrev): try: - svn.client.ls(self.url.rstrip('/') + '/' + path, + svn.client.ls(self.url.rstrip('/') + '/' + urllib.quote(path), optrev, False, self.ctx) return True except SubversionException, err: @@ -279,8 +280,8 @@ # Check if branches bring a few more heads to the list if branches: rpath = self.url.strip('/') - branchnames = svn.client.ls(rpath + '/' + branches, rev, False, - self.ctx) + branchnames = svn.client.ls(rpath + '/' + urllib.quote(branches), + rev, False, self.ctx) for branch in branchnames.keys(): module = '%s/%s/%s' % (oldmodule, branches, branch) if not isdir(module, self.last_changed): @@ -324,8 +325,8 @@ else: # Perform a full checkout on roots uuid, module, revnum = self.revsplit(rev) - entries = svn.client.ls(self.base + module, optrev(revnum), - True, self.ctx) + entries = svn.client.ls(self.baseurl + urllib.quote(module), + optrev(revnum), True, self.ctx) files = [n for n,e in entries.iteritems() if e.kind == svn.core.svn_node_file] copies = {} @@ -524,12 +525,12 @@ """Reparent the svn transport and return the previous parent.""" if self.prevmodule == module: return module - svn_url = (self.base + module).encode(self.encoding) + svnurl = self.baseurl + urllib.quote(module) prevmodule = self.prevmodule if prevmodule is None: prevmodule = '' - self.ui.debug("reparent to %s\n" % svn_url) - svn.ra.reparent(self.ra, svn_url) + self.ui.debug("reparent to %s\n" % svnurl) + svn.ra.reparent(self.ra, svnurl) self.prevmodule = module return prevmodule @@ -872,8 +873,9 @@ def _find_children(self, path, revnum): path = path.strip('/') pool = Pool() - rpath = '/'.join([self.base, path]).strip('/') - return ['%s/%s' % (path, x) for x in svn.client.ls(rpath, optrev(revnum), True, self.ctx, pool).keys()] + rpath = '/'.join([self.baseurl, urllib.quote(path)]).strip('/') + return ['%s/%s' % (path, x) for x in + svn.client.ls(rpath, optrev(revnum), True, self.ctx, pool).keys()] def getrelpath(self, path, module=None): if module is None: @@ -909,7 +911,7 @@ if not p.startswith('/'): p = self.module + '/' + p relpaths.append(p.strip('/')) - args = [self.base, relpaths, start, end, limit, discover_changed_paths, + args = [self.baseurl, relpaths, start, end, limit, discover_changed_paths, strict_node_history] arg = encodeargs(args) hgexe = util.hgexecutable()
--- a/tests/test-convert-svn-source Fri Oct 10 11:32:38 2008 +0200 +++ b/tests/test-convert-svn-source Fri Oct 10 11:36:02 2008 +0200 @@ -30,23 +30,23 @@ mkdir tags cd .. -svnurl=file://$svnpath/svn-repo/projB +svnurl=file://$svnpath/svn-repo/proj%20B svn import -m "init projB" projB $svnurl | fix_path echo % update svn repository svn co $svnurl/trunk B | fix_path cd B -echo hello > letter.txt -svn add letter.txt +echo hello > 'letter .txt' +svn add 'letter .txt' svn ci -m hello -"$TESTDIR/svn-safe-append.py" world letter.txt +"$TESTDIR/svn-safe-append.py" world 'letter .txt' svn ci -m world svn copy -m "tag v0.1" $svnurl/trunk $svnurl/tags/v0.1 -"$TESTDIR/svn-safe-append.py" 'nice day today!' letter.txt +"$TESTDIR/svn-safe-append.py" 'nice day today!' 'letter .txt' svn ci -m "nice day" cd .. @@ -55,7 +55,7 @@ echo % update svn repository again cd B -"$TESTDIR/svn-safe-append.py" "see second letter" letter.txt +"$TESTDIR/svn-safe-append.py" "see second letter" 'letter .txt' echo "nice to meet you" > letter2.txt svn add letter2.txt svn ci -m "second letter"
--- a/tests/test-convert-svn-source.out Fri Oct 10 11:32:38 2008 +0200 +++ b/tests/test-convert-svn-source.out Fri Oct 10 11:36:02 2008 +0200 @@ -7,16 +7,16 @@ Committed revision 1. % update svn repository Checked out revision 1. -A letter.txt -Adding letter.txt +A letter .txt +Adding letter .txt Transmitting file data . Committed revision 2. -Sending letter.txt +Sending letter .txt Transmitting file data . Committed revision 3. Committed revision 4. -Sending letter.txt +Sending letter .txt Transmitting file data . Committed revision 5. % convert to hg once @@ -31,7 +31,7 @@ updating tags % update svn repository again A letter2.txt -Sending letter.txt +Sending letter .txt Adding letter2.txt Transmitting file data .. Committed revision 6. @@ -51,15 +51,15 @@ | o 6 work in progress files: letter2.txt | -o 5 second letter files: letter.txt letter2.txt +o 5 second letter files: letter .txt letter2.txt | o 4 update tags files: .hgtags | -o 3 nice day files: letter.txt +o 3 nice day files: letter .txt | -o 2 world files: letter.txt +o 2 world files: letter .txt | -o 1 hello files: letter.txt +o 1 hello files: letter .txt | o 0 init projB files: