Mercurial > hg
changeset 49289:6c4c341d8fa5
convert: inline Python 3 variant of url2pathname_like_subversion()
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Tue, 31 May 2022 01:06:29 +0200 |
parents | ef5f5f1cbd90 |
children | 76f56d69a457 |
files | hgext/convert/subversion.py |
diffstat | 1 files changed, 10 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/convert/subversion.py Tue May 31 00:50:29 2022 +0200 +++ b/hgext/convert/subversion.py Tue May 31 01:06:29 2022 +0200 @@ -364,32 +364,6 @@ } -class NonUtf8PercentEncodedBytes(Exception): - pass - - -# Subversion paths are Unicode. Since the percent-decoding is done on -# UTF-8-encoded strings, percent-encoded bytes are interpreted as UTF-8. -def url2pathname_like_subversion(unicodepath): - if pycompat.ispy3: - # On Python 3, we have to pass unicode to urlreq.url2pathname(). - # Percent-decoded bytes get decoded using UTF-8 and the 'replace' error - # handler. - unicodepath = urlreq.url2pathname(unicodepath) - if u'\N{REPLACEMENT CHARACTER}' in unicodepath: - raise NonUtf8PercentEncodedBytes - else: - return unicodepath - else: - # If we passed unicode on Python 2, it would be converted using the - # latin-1 encoding. Therefore, we pass UTF-8-encoded bytes. - unicodepath = urlreq.url2pathname(unicodepath.encode('utf-8')) - try: - return unicodepath.decode('utf-8') - except UnicodeDecodeError: - raise NonUtf8PercentEncodedBytes - - def issvnurl(ui, url): try: proto, path = url.split(b'://', 1) @@ -412,9 +386,15 @@ % pycompat.sysbytes(fsencoding) ) return False - try: - unicodepath = url2pathname_like_subversion(unicodepath) - except NonUtf8PercentEncodedBytes: + + # Subversion paths are Unicode. Since it does percent-decoding on + # UTF-8-encoded strings, percent-encoded bytes are interpreted as + # UTF-8. + # On Python 3, we have to pass unicode to urlreq.url2pathname(). + # Percent-decoded bytes get decoded using UTF-8 and the 'replace' + # error handler. + unicodepath = urlreq.url2pathname(unicodepath) + if u'\N{REPLACEMENT CHARACTER}' in unicodepath: ui.warn( _( b'Subversion does not support non-UTF-8 ' @@ -422,6 +402,7 @@ ) ) return False + # Below, we approximate how Subversion checks the path. On Unix, we # should therefore convert the path to bytes using `fsencoding` # (like Subversion does). On Windows, the right thing would