【问题标题】:reading binary files with git fast-import使用 git fast-import 读取二进制文件
【发布时间】:2018-08-07 07:52:52
【问题描述】:

我正在编写将源代码从 MKS Source Integrity 7.3 导入 Git 的脚本。脚本通过管道传输到 git fast-import 并且所有内容都可以正常导入,但是当我阅读 .doc.docx.xls.msg 文件时,我收到了 Unsupported command exception 错误。我应该如何阅读这些文件?或者有没有办法告诉 git fast-import 只导入这些类型的文件,而不读取它们。 谢谢。

读取二进制文件的代码:

print("%s %s inline %s" % ('M', '644', filename), file=stdout)
line = open(filename, 'rb').read()
print('data %d\n%s' % (len(line), line), file=stdout)

快速导入崩溃报告:

fatal: Unsupported command: S\xffU\x0fV\x1fW/\x7fX?5\xbfZ\x0f[\x1f8\...
Most Recent Commands Before Crash
---------------------------------
M 644 inline Approval/RE_bno.msg
  data 43008
* S\xffU\x0fV\x1fW/\x7fX?5\xbfZ\x0f[\x1f8\...

【问题讨论】:

    标签: python-3.x git-fast-import


    【解决方案1】:

    毕竟我通过将原始二进制数据写入stdout 来解决它,如下所示:

    import sys
    
    line = open(filename, 'rb').read()
    print('data %d' % len(line), file=stdout)
    sys.stdout.buffer.write(line)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-04
      • 2019-04-13
      • 2020-11-11
      • 2012-09-11
      • 2019-09-25
      • 2017-06-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多