4

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.

splicer
  • 5,344
  • 4
  • 42
  • 47
  • Are you using Git on Windows? – Greg Hewgill Dec 07 '09 at 21:48
  • Yes, sorry. This is Windows. – Christopher Manley Dec 07 '09 at 21:58
  • 1
    Diff the files (expected and actual). This will help determine if this is a cr/lf type of problem, or if something else is going on. – jdigital Dec 07 '09 at 22:40
  • I can't actually tell if it was cr/lf that did this. The 'expected' looks good. Has a %PNG header and some metadata tags a bit into the file and finishes with an END. The actual is utterly unreadable. Just a jumble of special characters. Also, the actual file is bigger than the expected file. Any obvious way to know if it's a cr/lf thing? – Christopher Manley Dec 08 '09 at 01:38
  • Note that the %PNG header isn't the full thing - if it's %png\n\r\n\r then it's a line-encoding-rewriting problem. – AlBlue Dec 08 '09 at 19:39
  • It is %png\n\r\n\r . . . It certainly looks like line-encoding. I just can't sort out where it's being mangled. I pulled the code out of P4 by hand and then did a git init on it. All went fine. Feels more and more like the Python script may be destroying it. – Christopher Manley Dec 08 '09 at 20:17
  • Git just corrupted my images as well. All my png and jpg files are now a splash of random colors. This happend after I tired to normalize line endings after reading this blog : https://help.github.com/articles/dealing-with-line-endings – Zasz Oct 08 '12 at 17:24

3 Answers3

6

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.

AlBlue
  • 23,254
  • 14
  • 71
  • 91
  • I agree - and I did take this line of thinking last night. I dug through the git-p4 source and docs to see how it pulled files out of Perforce. Turns out it just does a p4 print //path//to//file#revision So, I tries this on the PNG files and they look fine. (Also, the files as checked in are fine. These aren't new by any means.) My current guess is the way the stream is read and written inside of the Python script is doing some kind of damage. (git-p4 is a python script). But, I see no reports of this anywhere else. Makes me think it's something else in my setup. – Christopher Manley Dec 08 '09 at 14:38
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.

Arafangion
  • 11,517
  • 1
  • 40
  • 72
0

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.

Jimmy2Times
  • 673
  • 5
  • 11