@matheusbsbs / matheus-bagliano / commits / 3200d1aee0
Fork 0

Deal with binary diff output from GNU diff 2.8.7

Some vintage of diff says just "Files X and Y differ\n", instead of "Binary files X and Y differ\n", so catch both patterns. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Nov 17, 2005 at 20:46 UTC 3200d1aee0c22a34d075aafefe3e92f4f7d08840
1 file changed +18 -6
apply.c
+18 -6
@@ -893,12 +893,24 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch)
893 patchsize = parse_single_patch(buffer + offset + hdrsize, size - offset - hdrsize, patch);
894
895 if (!patchsize) {
896 - static const char binhdr[] = "Binary files ";
897 -
898 - if (sizeof(binhdr) - 1 < size - offset - hdrsize &&
899 - !memcmp(binhdr, buffer + hdrsize + offset,
900 - sizeof(binhdr)-1))
901 - patch->is_binary = 1;
896 + static const char *binhdr[] = {
897 + "Binary files ",
898 + "Files ",
899 + NULL,
900 + };
901 + int i;
902 + int hd = hdrsize + offset;
903 + unsigned long llen = linelen(buffer + hd, size - hd);
904 +
905 + if (!memcmp(" differ\n", buffer + hd + llen - 8, 8))
906 + for (i = 0; binhdr[i]; i++) {
907 + int len = strlen(binhdr[i]);
908 + if (len < size - hd &&
909 + !memcmp(binhdr[i], buffer + hd, len)) {
910 + patch->is_binary = 1;
911 + break;
912 + }
913 + }
914
915 /* Empty patch cannot be applied if:
916 * - it is a binary patch and we do not do binary_replace, or