Mercurial > hg
comparison tests/test-convert-svn-encoding.t @ 45022:e3b19004087a stable
convert: correctly convert paths to UTF-8 for Subversion
The previous code using encoding.tolocal() only worked by chance in these
situations:
* The string is ASCII: The fast path was triggered and the string was returned
unmodified.
* The local encoding is UTF-8: The source and target encoding is the same.
* The string is not valid UTF-8 and the native encoding is ISO-8859-1: If the
string doesn’t decode using UTF-8, ISO-8859-1 is tried as a fallback. During
`hg convert`, the local encoding is always UTF-8. The irony is that in this
case, encoding.tolocal() behaves like what someone would expect the reverse
function, encoding.fromlocal(), to do.
When the locale encoding is ISO-8859-15, trying to convert a SVN repo `/tmp/a€`
failed before like this:
file:///tmp/a%C2%A4 does not look like a Subversion repository to libsvn version 1.14.0
The correct URL is `file:///tmp/a%E2%82%AC`.
Unlike previously (with the ISO-8859-1 fallback), decoding the path using the
locale encoding can fail. In this case, we have to bail out, as Subversion
won’t be able to do anything useful with the path.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Mon, 29 Jun 2020 15:03:36 +0200 |
parents | 697212a830fb |
children | e54c3cafda15 |
comparison
equal
deleted
inserted
replaced
45021:cb097496138a | 45022:e3b19004087a |
---|---|
159 $ hg convert --source-type=svn http://localhost:$HGPORT/$XFF test | 159 $ hg convert --source-type=svn http://localhost:$HGPORT/$XFF test |
160 initializing destination test repository | 160 initializing destination test repository |
161 Subversion sources don't support non-ASCII characters in HTTP(S) URLs. Please percent-encode them. | 161 Subversion sources don't support non-ASCII characters in HTTP(S) URLs. Please percent-encode them. |
162 http://localhost:$HGPORT/\xff does not look like a Subversion repository (esc) | 162 http://localhost:$HGPORT/\xff does not look like a Subversion repository (esc) |
163 abort: http://localhost:$HGPORT/\xff: missing or unsupported repository (esc) | 163 abort: http://localhost:$HGPORT/\xff: missing or unsupported repository (esc) |
164 [255] | |
165 | |
166 In Subversion, paths are Unicode (encoded as UTF-8). Therefore paths that can't | |
167 be converted between UTF-8 and the locale encoding (which is always ASCII in | |
168 tests) don't work. | |
169 | |
170 $ cp -R svn-repo $XFF | |
171 $ hg convert $XFF test | |
172 initializing destination test repository | |
173 Subversion requires that paths can be converted to Unicode using the current locale encoding (ascii) | |
174 \xff does not look like a CVS checkout (glob) (esc) | |
175 $TESTTMP/\xff does not look like a Git repository (esc) | |
176 \xff does not look like a Subversion repository (glob) (esc) | |
177 \xff is not a local Mercurial repository (glob) (esc) | |
178 \xff does not look like a darcs repository (glob) (esc) | |
179 \xff does not look like a monotone repository (glob) (esc) | |
180 \xff does not look like a GNU Arch repository (glob) (esc) | |
181 \xff does not look like a Bazaar repository (glob) (esc) | |
182 cannot find required "p4" tool | |
183 abort: \xff: missing or unsupported repository (glob) (esc) | |
164 [255] | 184 [255] |
165 | 185 |
166 #if py3 | 186 #if py3 |
167 For now, on Python 3, we abort when encountering non-UTF-8 percent-encoded | 187 For now, on Python 3, we abort when encountering non-UTF-8 percent-encoded |
168 bytes in a filename. | 188 bytes in a filename. |