X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=apply.c;h=2da225a8ecae356c1b3376d5a0671940f265509c;hb=8ff8eea016f27d22d0264b140843470c7f14e004;hp=453482a035d76a14b04fa4182694a3d46db083e7;hpb=e1a0c8b1483b38d32d3870408e03a6c1b340aa15;p=git.git diff --git a/apply.c b/apply.c index 453482a0..2da225a8 100644 --- a/apply.c +++ b/apply.c @@ -32,7 +32,7 @@ static int no_add = 0; static int show_index_info = 0; static int line_termination = '\n'; static const char apply_usage[] = -"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [-z] [-pNUM] ..."; +"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [-z] [-pNUM] [--whitespace=] ..."; static enum whitespace_eol { nowarn_whitespace, @@ -651,7 +651,7 @@ static int parse_git_header(char *line, int len, unsigned int size, struct patch len = linelen(line, size); if (!len || line[len-1] != '\n') break; - for (i = 0; i < sizeof(optable) / sizeof(optable[0]); i++) { + for (i = 0; i < ARRAY_SIZE(optable); i++) { const struct opentry *p = optable + i; int oplen = strlen(p->str); if (len < oplen || memcmp(p->str, line, oplen)) @@ -834,7 +834,7 @@ static int parse_fragment(char *line, unsigned long size, struct patch *patch, s patch->new_name = NULL; } - if (patch->is_new != !oldlines) + if (patch->is_new && oldlines) return error("new file depends on old contents"); if (patch->is_delete != !newlines) { if (newlines) @@ -1232,6 +1232,14 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag) size -= len; } +#ifdef NO_ACCURATE_DIFF + if (oldsize > 0 && old[oldsize - 1] == '\n' && + newsize > 0 && new[newsize - 1] == '\n') { + oldsize--; + newsize--; + } +#endif + offset = find_offset(buf, desc->size, old, oldsize, frag->newpos); if (offset >= 0) { int diff = newsize - oldsize; @@ -1394,12 +1402,13 @@ static int check_patch(struct patch *patch) costate.not_new = 0; costate.refresh_cache = 1; if (checkout_entry(active_cache[pos], - &costate) || + &costate, + NULL) || lstat(old_name, &st)) return -1; } - changed = ce_match_stat(active_cache[pos], &st); + changed = ce_match_stat(active_cache[pos], &st, 1); if (changed) return error("%s: does not match index", old_name);