git-p4 is eating my image files

不羁的心 提交于 2019-12-10 17:29:39

问题


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 about 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.


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/1862944/git-p4-is-eating-my-image-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!