History

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.

Augie Fackler committed 10 years ago

Commit bada0331 parent 5b4065d1 file · +9 −2Browse files

Unified · Split

hggit/git_handler.py+9−2
@@ -19,6 +19,7 @@ from mercurial.i18n import _ · 18 unmodified lines
19from mercurial.node import hex, bin, nullid19from mercurial.node import hex, bin, nullid
20from mercurial import bookmarks20from mercurial import bookmarks
21from mercurial import commands21from mercurial import commands
22from mercurial import encoding
22from mercurial import context, util as hgutil23from mercurial import context, util as hgutil
23from mercurial import url24from mercurial import url
24 25
@@ -135,12 +136,18 @@ class GitHandler(object): · 110 unmodified lines
135 136
136 @hgutil.propertycache137 @hgutil.propertycache
137 def git(self):138 def git(self):
139 # Dulwich is going to try and join unicode ref names against
140 # the repository path to try and read unpacked refs. This
141 # doesn't match hg's bytes-only view of filesystems, we just
142 # have to cope with that. To cope, just decode the gitdir path
143 # in the local encoding and say a prayer that it decodes.
144 gitpath = self.gitdir.decode(encoding.encoding, encoding.encodingmode)
138 # make the git data directory145 # make the git data directory
139 if os.path.exists(self.gitdir):146 if os.path.exists(self.gitdir):
140 return Repo(self.gitdir)147 return Repo(gitpath)
141 else:148 else:
142 os.mkdir(self.gitdir)149 os.mkdir(self.gitdir)
143 return Repo.init_bare(self.gitdir)150 return Repo.init_bare(gitpath)
144 151
145 def init_author_file(self):152 def init_author_file(self):
146 self.author_map = {}153 self.author_map = {}