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
1919 from mercurial.node import hex, bin, nullid
2020 from mercurial import bookmarks
2121 from mercurial import commands
22+from mercurial import encoding
2223 from mercurial import context, util as hgutil
2324 from mercurial import url
2425
@@ -135,12 +136,18 @@ class GitHandler(object): · 110 unmodified lines
135136
136137 @hgutil.propertycache
137138 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)
138145 # make the git data directory
139146 if os.path.exists(self.gitdir):
140− return Repo(self.gitdir)
147+ return Repo(gitpath)
141148 else:
142149 os.mkdir(self.gitdir)
143− return Repo.init_bare(self.gitdir)
150+ return Repo.init_bare(gitpath)
144151
145152 def init_author_file(self):
146153 self.author_map = {}