[PATCH] Deal with binary diff output from (unknown version of) diff

Subsystems: the rest

DORMANTno replies

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH] Deal with binary diff output from (unknown version of) diff

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:12

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 <redacted>

---

    Junio C Hamano [off-list ref] writes:

    >> Files /dev/null and b/file3 differ
    >> diff --git a/file4 b/file4
    >> index edc575d..adb07b7 100644
    >> Files a/file4 and b/file4 differ
    >
    > Thanks.  I've seen enough.  I expected diff (GNU diffutils 2.8.1
    > is what I have handy) output which says "Binary files a/foo and
    > b/foo differ".
    >
    > Hmph.  Now I'd need to find a way to catch at least these two
    > cases...

    Could you two try this patch please?
diff --git a/apply.c b/apply.c
index 129edb1..50be8f3 100644
--- a/apply.c
+++ b/apply.c
@@ -893,12 +893,24 @@ static int parse_chunk(char *buffer, uns
 	patchsize = parse_single_patch(buffer + offset + hdrsize, size - offset - hdrsize, patch);
 
 	if (!patchsize) {
-		static const char binhdr[] = "Binary files ";
-
-		if (sizeof(binhdr) - 1 < size - offset - hdrsize &&
-		    !memcmp(binhdr, buffer + hdrsize + offset,
-			    sizeof(binhdr)-1))
-			patch->is_binary = 1;
+		static const char *binhdr[] = {
+			"Binary files ",
+			"Files ",
+			NULL,
+		};
+		int i;
+		int hd = hdrsize + offset;
+		unsigned long llen = linelen(buffer + hd, size - hd);
+
+		if (!memcmp(" differ\n", buffer + hd + llen - 8, 8))
+			for (i = 0; binhdr[i]; i++) {
+				int len = strlen(binhdr[i]);
+				if (len < size - hd &&
+				    !memcmp(binhdr[i], buffer + hd, len)) {
+					patch->is_binary = 1;
+					break;
+				}
+			}
 
 		/* Empty patch cannot be applied if:
 		 * - it is a binary patch and we do not do binary_replace, or

Re: [PATCH] Deal with binary diff output from (unknown version of) diff

From: A Large Angry SCM <hidden>
Date: 2016-06-15 22:42:12

Passed here!


Junio C Hamano wrote:
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 <redacted>

---

    Junio C Hamano [off-list ref] writes:

    >> Files /dev/null and b/file3 differ
    >> diff --git a/file4 b/file4
    >> index edc575d..adb07b7 100644
    >> Files a/file4 and b/file4 differ
    >
    > Thanks.  I've seen enough.  I expected diff (GNU diffutils 2.8.1
    > is what I have handy) output which says "Binary files a/foo and
    > b/foo differ".
    >
    > Hmph.  Now I'd need to find a way to catch at least these two
    > cases...

    Could you two try this patch please?
[snip snip]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help