From 28aa302374838ce623a1924a260d6f5f046ed051 Mon Sep 17 00:00:00 2001 From: Augie Fackler Date: Wed, 25 Nov 2015 17:52:59 -0500 Subject: [PATCH] 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. --- hggit/git_handler.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hggit/git_handler.py b/hggit/git_handler.py index 9441ab41d1..a64f1a78e2 100644 --- a/hggit/git_handler.py +++ b/hggit/git_handler.py @@ -19,6 +19,7 @@ from mercurial.i18n import _ 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 @@ class GitHandler(object): @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 = {}