Skip to content

Commit

Permalink
git-apply: do not fail on binary diff when not applying nor checking.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Nov 9, 2005
1 parent c44922a commit ff36de0
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -890,8 +890,18 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch)

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 && !check)
;
else
die("patch with only garbage at line %d", linenr);
}

return offset + hdrsize + patchsize;
}
Expand Down Expand Up @@ -949,9 +959,12 @@ static void show_stats(struct patch *patch)
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);
}
Expand Down

0 comments on commit ff36de0

Please sign in to comment.