开发者

git-p4 is eating my image files

So, I can import from p4 using git-p4 without any problem. Everything seems to work, but my PNG files (and perhaps others) are getting corrupted.

I've read a开发者_运维百科bout gitattributes and the line ending issues, but nothing I do seems to change the end result. Broken images.

My attributes file is: *.png binary

Any ideas? As I understand it, git is supposed to be smart enough to figure out that a png is a binary file without this help.

Is this something particular to do with how p4-git pulls the files out of Perforce?

Update: This is on Windows. I forgot that would be important.


The PNG file format has a header which is specifically designed to look out for programs that do end conversion, and cause a failure if not.

The 8-bytes of a PNG file are: 89 50 4E 47 0D 0A 1A 0A, chosen specifically because they contain the Unix newline and the Windows newline - so programs doing auto-conversion will automatically invalidate the PNG. PNG Signature rationale

So it seems that this is indeed the problem; and rather than assuming that Git is the problem, try looking at the import from Perforce. Either Perforce is doing the translation, or it was initially checked in in a corrupted state, and no amount of cloning/updating will fix the original problem.


There are multiple layers of (very) leaky abstraction here.

Firstly, there is what the perforce server may be storing the files as. Secondly, the perforce client may be mangling newlines. Thirdly, the python script may be mangling newlines (Unlikely). Fourthly, git could be mangling newlines.

Now, on windows, and only on windows, git will automatically mangle newlines by default. (99% of the git community seem to hate this default, but it's apparently the only sensible default option on windows).

As a result is that if you have newline "issues", I suggest manually investigating each layer and specifying exactly how you want newlines to be treated. I suggest making them explicit, not automatic.

I suggest you investigate git's configuration first, as the windows defaults are quite different, and git's defaults differ between some versions, and some builds. (ie, msysgit is different to cygwin - cygwin's git has another layer of newline mangling - cygwin itself).

Enjoy.


Make sure your PNG file is set to "binary" type in Perforce. I just had this problem with a random binary file being set to a "text" type in Perforce. I'm not sure why Perforce had derived that file to be text, but it was causing issues with git-p4's detection of what to do with that file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜