changeset 975:afea0e32db20

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. This is a roll-forward of a593069575bb, which should be valid now that the previous change defends against accidentally writing unicode tags inside the templater.
author Augie Fackler <raf@durin42.com>
date Thu, 31 Dec 2015 18:49:17 -0500
parents 5d45e0edfa3f
children 97528d49ae5b
files hggit/git_handler.py
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -21,6 +21,7 @@
     bookmarks,
     commands,
     context,
+    encoding,
     util as hgutil,
     lock as lockmod,
     url,
@@ -139,12 +140,19 @@
 
     @hgutil.propertycache
     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. As a workaround, try decoding our
+        # (bytes) path to the repo in hg's active encoding and hope
+        # for the best.
+        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)
         else:
             os.mkdir(self.gitdir)
-            return Repo.init_bare(self.gitdir)
+            return Repo.init_bare(gitpath)
 
     def init_author_file(self):
         self.author_map = {}