git-apply: do not fail on binary diff when not applying nor checking.
We run git-apply with --stat and --summary at the end of the pull by default, which causes it to barf when the pull brought in changes to binary files. Just mark them as binary patch and proceed when not applying nor checking. [jc: I almost missed --check until I saw Linus did something similar.] Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Nov 9, 2005 at 14:59 UTC
ff36de0847768873cc793afd6378d3b229591436
1 file changed
+19
-6
apply.c
+19
-6
@@ -53,7 +53,7 @@ struct fragment {
53
struct patch {
54
char *new_name, *old_name, *def_name;
55
unsigned int old_mode, new_mode;
56
- int is_rename, is_copy, is_new, is_delete;
56
+ int is_rename, is_copy, is_new, is_delete, is_binary;
57
int lines_added, lines_deleted;
58
int score;
59
struct fragment *fragments;
@@ -890,8 +890,18 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch)
890
891
patchsize = parse_single_patch(buffer + offset + hdrsize, size - offset - hdrsize, patch);
892
893
- if (!patchsize && !metadata_changes(patch))
894
- die("patch with only garbage at line %d", linenr);
893
+ if (!patchsize && !metadata_changes(patch)) {
894
+ static const char binhdr[] = "Binary files ";
895
+
896
+ if (sizeof(binhdr) - 1 < size - offset - hdrsize &&
897
+ !memcmp(binhdr, buffer + hdrsize, sizeof(binhdr)-1))
898
+ patch->is_binary = 1;
899
+
900
+ if (patch->is_binary && !apply && !check)
901
+ ;
902
+ else
903
+ die("patch with only garbage at line %d", linenr);
904
+ }
905
906
return offset + hdrsize + patchsize;
907
}
@@ -949,9 +959,12 @@ static void show_stats(struct patch *patch)
959
add = (add * max + max_change / 2) / max_change;
960
del = total - add;
961
}
952
- printf(" %s%-*s |%5d %.*s%.*s\n", prefix,
953
- len, name, patch->lines_added + patch->lines_deleted,
954
- add, pluses, del, minuses);
962
+ if (patch->is_binary)
963
+ printf(" %s%-*s | Bin\n", prefix, len, name);
964
+ else
965
+ printf(" %s%-*s |%5d %.*s%.*s\n", prefix,
966
+ len, name, patch->lines_added + patch->lines_deleted,
967
+ add, pluses, del, minuses);
968
if (qname)
969
free(qname);
970
}