reading binary files with git fast-import

307 Views Asked by At

I am writing script for importing sources from MKS Source Integrity 7.3 to Git. Script is piped to git fast-import and everything imports just fine, but I am getting Unsupported command exception error when I read .doc , .docx, .xls, .msg files. How should I read these files? Or is there a way to tell git fast-import to just import these types of files as they are, without reading them. Thanks.

Code for reading binary files:

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)

fast-import crash report:

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\...
1

There are 1 best solutions below

0
misanek On

After all I resolved it with writing raw binary data to stdout like this:

import sys

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