Bruno, in Optimisation de PNG, ou encore une bonne raison de préférer git, argues that git is better because you can use gitattributes to specify a program which will convert binary files to text before diffing:
$ echo '*.png diff=exif' >> .gitattributes $ git config diff.exif.textconv exiftool
This trick had already been reported by Scott, and is included in Pro Git in chapter 7.2.
We’ve seen in the last post how to have a Color-highlighted svn diff output with git default colors, now we’ll see how to svn diff png files.
This is what you’ll get if you try a svn diff on a png file:
$ svn diff preview.png Index: preview.png =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream
And if you carefully read the Subversion FAQ, in the section named How does Subversion handle binary files? you’ll see that for files it has determined as binary (read the FAQ to know how it does), Subversion will:
Not show the differences as part of svn diff
And if you try:
$ svn diff preview.png Index: preview.png =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream
You can see that it will not even try to diff binary files. But you can use the –force option to do it anyway:
$ svn diff --force preview.png Index: preview.png =================================================================== Binary files preview.png (revision 14882) and preview.png (working copy) differ svn: 'colordiff' returned 2
But diff (with the colordiff wrapper from the previous post) only tells us whether the two binary files differ or not.
Now here’s the trick adapted from the posts concerning git.
First install ExifTool. Under Debian:
$ sudo aptitude install libimage-exiftool-perl
Then create a wrapper:
$ sudoedit /usr/local/bin/svndiff #!/bin/sh DIFF=`which colordiff` if `file ${6} | grep -q PNG`; then LEFT=`mktemp` RIGHT=`mktemp` exiftool ${6} > $LEFT exiftool ${7} > $RIGHT $DIFF -u -L "${3}" -L "${5}" "$LEFT" "$RIGHT" | grep -E -v "ExifTool Version Number|[+-]File Name|[+-]Directory|[+-]File Permissions" rm ${LEFT} rm ${RIGHT} else $DIFF -u -L "${3}" -L "${5}" "${6}" "${7}" fi
Make it executable:
$ sudo chmod +x /usr/local/bin/svndiff
And finally edit the Subversion configuration file in order to use this new wrapper:
$ vim ~/.subversion/config [helpers] diff-cmd = svndiff
And now that’s what you’ll get:
$ svn diff --force preview.png Index: preview.png =================================================================== --- preview.png (revision 14882) +++ preview.png (working copy) @@ -1,22 +1,22 @@ -File Size : 7.1 kB -File Modification Date/Time : 2010:02:02 16:15:46+01:00 +File Size : 5.5 kB +File Modification Date/Time : 2010:11:16 17:57:50+01:00 File Type : PNG MIME Type : image/png Image Width : 150 Image Height : 120 Bit Depth : 8 -Color Type : RGB with Alpha +Color Type : RGB Compression : Deflate/Inflate Filter : Adaptive Interlace : Noninterlaced SRGB Rendering : Perceptual -Background Color : 255 255 255 Pixels Per Unit X : 2835 Pixels Per Unit Y : 2835 Pixel Units : Meters Modify Date : 2009:04:17 08:37:21 +Background Color : 255 255 255 Image Size : 150x120
And a screenshot to see the color-highlighted output:

what’s the point of
DIFF=`which colordiff`
and then
$DIFF -u - ....
?
Why not just do
colordiff -u - ....
?
now if only patch would work too.
@somebody: That’s because $DIFF is used twice in the shell script, so if you want to change colordiff to something else, you just have to change it at the beginning. And if you add support for another binary file type, it would be used even more times.
@j: Have a look at bsdiff and bspatch
Hi you,
you svndiff simply did not work. But your ideas were very helpfull for mine.
You can simply change your if line with:
if `file ${6} | grep -qi "jpeg\|png\|"`; then
and anything between if and else with:
$DIFF --suppress-common-lines <(cat "${6}" | exiftool -s -) <(cat "${7}" | exiftool -s -)
PS.: I really dont know if it changes anything but in my case I started it with #!/bin/bash.