git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Problems with binary patches (pull) and spaces in filenames (gitk)

From
Junio C Hamano <junkio@cox.net>
Date
Nov 9, 2005, 22:36 UTC
Message-ID
<7v8xvxbg9y.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<7vfyq5bhi2.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> writes:
> Hmm.  Perhaps a suboption to git-apply --stat to tell it not to
> barf is helpful?  In the meantime, could you pull with -n flag?
Would this help?

-- >8 -- cut here -- >8 -- [PATCH] git-apply: do not barf on binary diff when not applying.

Instead, just mark the patch as binary, and keep going when doing --stat and --summary.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
diff --git a/apply.c b/apply.c
index 3e53b34..6d756f7 100644
--- a/apply.c
+++ b/apply.c
@@ -53,7 +53,7 @@ struct fragment {
 struct patch {
 	char *new_name, *old_name, *def_name;
 	unsigned int old_mode, new_mode;
-	int is_rename, is_copy, is_new, is_delete;
+	int is_rename, is_copy, is_new, is_delete, is_binary;
 	int lines_added, lines_deleted;
 	int score;
 	struct fragment *fragments;
@@ -890,8 +890,18 @@ static int parse_chunk(char *buffer, uns
 
 	patchsize = parse_single_patch(buffer + offset + hdrsize, size - offset - hdrsize, patch);
 
-	if (!patchsize && !metadata_changes(patch))
-		die("patch with only garbage at line %d", linenr);
+	if (!patchsize && !metadata_changes(patch)) {
+		static const char binhdr[] = "Binary files ";
+
+		if (sizeof(binhdr) - 1 < size - offset - hdrsize &&
+		    !memcmp(binhdr, buffer + hdrsize, sizeof(binhdr)-1))
+			patch->is_binary = 1;
+
+		if (patch->is_binary && !apply)
+			;
+		else
+			die("patch with only garbage at line %d", linenr);
+	}
 
 	return offset + hdrsize + patchsize;
 }
@@ -949,9 +959,12 @@ static void show_stats(struct patch *pat
 		add = (add * max + max_change / 2) / max_change;
 		del = total - add;
 	}
-	printf(" %s%-*s |%5d %.*s%.*s\n", prefix,
-		len, name, patch->lines_added + patch->lines_deleted,
-		add, pluses, del, minuses);
+	if (patch->is_binary)
+		printf(" %s%-*s |  Bin\n", prefix, len, name);
+	else
+		printf(" %s%-*s |%5d %.*s%.*s\n", prefix,
+		       len, name, patch->lines_added + patch->lines_deleted,
+		       add, pluses, del, minuses);
 	if (qname)
 		free(qname);
 }
Previous: Junio C HamanoNext: Peter Eriksen
Message 3 of 6 in “Problems with binary patches (pull) and spaces in filenames (gitk)”
  1. Peter EriksenNov 9, 2005
  2. Junio C HamanoNov 9, 2005
  3. Junio C HamanoNov 9, 2005
  4. Peter EriksenNov 9, 2005
  5. Jan HarkesNov 9, 2005
  6. Linus TorvaldsNov 9, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.