# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1588498199 -7200
#      Sun May 03 11:29:59 2020 +0200
# Node ID 2c32471b56089094af808b259258e8ce63e3b19b
# Parent  121401d74d0d2f73885d6cd9abd1ef28d696932c
py3: pass URI to dulwich as str

Dulwich decodes other parts of the path using the utf-8 codec since
bcb4459da4. Before, it used the file system encoding. As a follow-up, we could
do that conversion ourselves to get consistent behavior on all dulwich
versions in case the file system encoding is not utf-8.

diff --git a/hggit/git_handler.py b/hggit/git_handler.py
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -1727,7 +1727,13 @@
             ua = b'git/20x6 (hg-git ; uses dulwich and hg ; like git-core)'
             config = dul_config.ConfigDict()
             config.set(b'http', b'useragent', ua)
-            return client.HttpGitClient(uri, config=config), uri
+            if pycompat.ispy3:
+                # urllib3.util.url._encode_invalid_chars() converts the path
+                # back to bytes using the utf-8 codec
+                str_uri = uri.decode('utf-8')
+            else:
+                str_uri = uri
+            return client.HttpGitClient(str_uri, config=config), uri
 
         # if its not git or git+ssh, try a local url..
         return client.SubprocessGitClient(), uri