Allow .gitmodules to start with UTF-8 BOM.
While cloning a repository I encountered the error below.
hg-git takes the content of a .gitmodules
file as io.BytesIO
and passes that to dulwich’s config.ConfigFile.from_file
, which expects a io.BinaryIO
stream.
This means that even if the content starts with a UTF-8 signature, it will not be treated as UTF-8 but as bytes.
git however can read .gitmodules
with encoding and I think that hg-git should be able to do this as well.
** unknown exception encountered, please report by visiting
** https://mercurial-scm.org/wiki/BugTracker
** Python 3.8.8 (default, Feb 19 2021, 16:53:21) [GCC]
** Mercurial Distributed SCM (Version 5.7)
** Erweiterungen geladen: absorb, amend, churn, evolve 10.2.0.post1, extdiff, graphlog, hggit 0.10.0 (dulwich 0.20.15), histedit, purge, rebase, record, strip, topic 0.21.0
Traceback (most recent call last):
File "/usr/bin/hg", line 59, in <module>
dispatch.run()
File "/usr/lib64/python3.8/site-packages/mercurial/dispatch.py", line 143, in run
status = dispatch(req)
File "/usr/lib64/python3.8/site-packages/mercurial/dispatch.py", line 245, in dispatch
status = _rundispatch(req)
File "/usr/lib64/python3.8/site-packages/mercurial/dispatch.py", line 289, in _rundispatch
ret = _runcatch(req) or 0
File "/usr/lib64/python3.8/site-packages/mercurial/dispatch.py", line 465, in _runcatch
return _callcatch(ui, _runcatchfunc)
File "/usr/lib64/python3.8/site-packages/mercurial/dispatch.py", line 475, in _callcatch
return scmutil.callcatch(ui, func)
File "/usr/lib64/python3.8/site-packages/mercurial/scmutil.py", line 155, in callcatch
return func()
File "/usr/lib64/python3.8/site-packages/mercurial/dispatch.py", line 455, in _runcatchfunc
return _dispatch(req)
File "/usr/lib64/python3.8/site-packages/mercurial/dispatch.py", line 1258, in _dispatch
return runcommand(
File "/usr/lib64/python3.8/site-packages/mercurial/dispatch.py", line 913, in runcommand
ret = _runcommand(ui, options, cmd, d)
File "/usr/lib64/python3.8/site-packages/mercurial/dispatch.py", line 1270, in _runcommand
return cmdfunc()
File "/usr/lib64/python3.8/site-packages/mercurial/dispatch.py", line 1256, in <lambda>
d = lambda: util.checksignature(func)(ui, *args, **strcmdopt)
File "/usr/lib64/python3.8/site-packages/mercurial/util.py", line 1867, in check
return func(*args, **kwargs)
File "/usr/lib64/python3.8/site-packages/mercurial/commands.py", line 1925, in clone
r = hg.clone(
File "/usr/lib64/python3.8/site-packages/mercurial/hg.py", line 942, in clone
exchange.pull(
File "/home/xph/hg/hg-git/hggit/util.py", line 63, in inner
return f(*args, **kwargs)
File "/home/xph/hg/hg-git/hggit/__init__.py", line 556, in exchangepull
pullop.cgresult = repo.githandler.fetch(remote.path, heads)
File "/home/xph/hg/hg-git/hggit/git_handler.py", line 308, in fetch
imported = self.import_git_objects(remote_name, filteredrefs)
File "/home/xph/hg/hg-git/hggit/git_handler.py", line 832, in import_git_objects
self.import_git_commit(commit)
File "/home/xph/hg/hg-git/hggit/git_handler.py", line 906, in import_git_commit
gitmodules = self.parse_gitmodules(git_commit_tree)
File "/home/xph/hg/hg-git/hggit/git_handler.py", line 1696, in parse_gitmodules
tt = dul_config.ConfigFile.from_file(fo)
File "/usr/lib64/python3.8/site-packages/dulwich/config.py", line 431, in from_file
raise ValueError("setting %r without section" % line)
ValueError: setting b'\xef\xbb\xbf[submodule "redacted-name"]\n' without section