changeset 952:a593069575bb

git_handler: work around dulwich using unicode for ref names Dulwich treats ref names internally as unicode strings (probably because of Python 3?), which means that at some points it tries to do os.path.join between the repo path and the unicode of the ref name, which fails miserably if we construct the repo with a str and not a unicode. Kludge around this problem. Fixes issue 172.
author Augie Fackler <>
date Wed, 25 Nov 2015 17:52:59 -0500
parents c705bd4236f4
children 584961625a58
files hggit/
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/
+++ b/hggit/
@@ -19,6 +19,7 @@
 from mercurial.node import hex, bin, nullid
 from mercurial import bookmarks
 from mercurial import commands
+from mercurial import encoding
 from mercurial import context, util as hgutil
 from mercurial import url
@@ -135,12 +136,18 @@
     def git(self):
+        # Dulwich is going to try and join unicode ref names against
+        # the repository path to try and read unpacked refs. This
+        # doesn't match hg's bytes-only view of filesystems, we just
+        # have to cope with that. To cope, just decode the gitdir path
+        # in the local encoding and say a prayer that it decodes.
+        gitpath = self.gitdir.decode(encoding.encoding, encoding.encodingmode)
         # make the git data directory
         if os.path.exists(self.gitdir):
-            return Repo(self.gitdir)
+            return Repo(gitpath)
-            return Repo.init_bare(self.gitdir)
+            return Repo.init_bare(gitpath)
     def init_author_file(self):
         self.author_map = {}