今天,我可以将一些非常古老的存储库迁移到git。虽然这很有趣,但有一件事引起了我的注意。提交消息中的所有特殊字符,甚至作者名称都没有使用正确的编码。
所以我试着去调查问题的来源。
Unicode clients require a unicode enabled server.没有影响。p4 users where,确实在ANSI中(根据file -bi对重定向输出进行咨询notepad++或ISO8859-1)。locale命令是LANG=en_US.UTF-8 .毕竟,我的猜测是,所有的p4客户端输出都在ISO8859-1中,而git-p4则假定为UTF-8。
我尝试用以下方法重写提交消息
git filter-branch --msg-filter 'iconv -f iso-8859-1 -t utf-8' -- --all但这并不能解决问题,特别是因为它并不打算重写作者的名字。
有人猜测如何强迫输出在git-p4收到之前被翻译到UTF-8?
更新:
我试图用一个简单的shell脚本覆盖默认的p4命令输出,这个脚本是我加到PATH上的。
/usr/bin/p4 $@ | iconv -f iso-8859-1 -t utf-8但是,这会使显然被使用的封送python对象感到厌恶:
File "/usr/local/bin/git-p4", line 2467, in getBranchMapping
for info in p4CmdList(command):
File "/usr/local/bin/git-p4", line 480, in p4CmdList
entry = marshal.load(p4.stdout)
ValueError: bad marshal dataUpdate2:
如图所示,更改Python的默认编码?试图将python编码设置为ascii:
export export PYTHONIOENCODING="ascii"
python -c 'import sys; print(sys.stdin.encoding, sys.stdout.encoding)'输出:
('ascii', 'ascii')但是,仍然没有正确迁移所有消息和作者。
更新3:
即使试图修补git-p4.py def commit(self, details, files, branch, parent = "")函数也没有帮助:更改
self.gitStream.write(details["desc"])为其中之一
self.gitStream.write(details["desc"].encode('utf8', 'replace'))
self.gitStream.write(unicode(details["desc"],'utf8')刚刚提出:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 29: ordinal not in range(128)因为我不是python开发人员,所以我不知道接下来要尝试什么。
发布于 2015-05-14 10:43:53
我怀疑details["desc"]的类型是字节字符串。( python2)。
因此,您需要先将其decode到Unicode,然后再进行encode。
print type(details["desc"])找出哪种类型。
details["desc"].decode("iso-8859-1").encode("UTF-8")可能有助于将iso-8859-1转换为UTF-8。
https://stackoverflow.com/questions/30223655
复制相似问题