# HG changeset patch # User Augie Fackler # Date 1448491979 18000 # Node ID a593069575bb4ed67916a8f12425884c4579c2b6 # Parent c705bd4236f4a1da0ab497a5afc228148b50a310 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. diff --git a/hggit/git_handler.py b/hggit/git_handler.py --- a/hggit/git_handler.py +++ b/hggit/git_handler.py @@ -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 @@ @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. 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) else: os.mkdir(self.gitdir) - return Repo.init_bare(self.gitdir) + return Repo.init_bare(gitpath) def init_author_file(self): self.author_map = {}