Mercurial > hg > hg-git
diff hggit/git_handler.py @ 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 | 07473e474bc4 |
children | 7a767993352b |
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 = {}