X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-apply.c;h=aad55261fae35fa644bc65aae79fc15aabc38244;hb=faa1bbfdd2c7d2f6cf556ee3f0d54cad42b08c61;hp=cbe597771b42e34a2a8c0a2e88e1b7baadf7a6b4;hpb=f73a5e897609c895aa6c10f7a89428d1749d37ce;p=git.git diff --git a/builtin-apply.c b/builtin-apply.c index cbe597771..aad55261f 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -43,7 +43,7 @@ static int apply_verbosely; static int no_add; static int show_index_info; static int line_termination = '\n'; -static unsigned long p_context = -1; +static unsigned long p_context = ULONG_MAX; static const char apply_usage[] = "git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--cached] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [--reverse] [--reject] [--verbose] [-z] [-pNUM] [-CNUM] [--whitespace=] ..."; @@ -360,7 +360,7 @@ static int gitdiff_hdrend(const char *line, struct patch *patch) static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name, const char *oldnew) { if (!orig_name && !isnull) - return find_name(line, NULL, 1, 0); + return find_name(line, NULL, 1, TERM_TAB); if (orig_name) { int len; @@ -370,7 +370,7 @@ static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name, len = strlen(name); if (isnull) die("git-apply: bad git-diff - expected /dev/null, got %s on line %d", name, linenr); - another = find_name(line, NULL, 1, 0); + another = find_name(line, NULL, 1, TERM_TAB); if (!another || memcmp(another, name, len)) die("git-apply: bad git-diff - inconsistent %s filename on line %d", oldnew, linenr); free(another); @@ -934,6 +934,7 @@ static int parse_fragment(char *line, unsigned long size, struct patch *patch, s switch (*line) { default: return -1; + case '\n': /* newer GNU diff, an empty context line */ case ' ': oldlines--; newlines--; @@ -1042,10 +1043,14 @@ static int parse_single_patch(char *line, unsigned long size, struct patch *patc * then not having oldlines means the patch is creation, * and not having newlines means the patch is deletion. */ - if (patch->is_new < 0 && !oldlines) + if (patch->is_new < 0 && !oldlines) { patch->is_new = 1; - if (patch->is_delete < 0 && !newlines) + patch->old_name = NULL; + } + if (patch->is_delete < 0 && !newlines) { patch->is_delete = 1; + patch->new_name = NULL; + } } if (0 < patch->is_new && oldlines) @@ -1623,6 +1628,14 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag, i first = '-'; } switch (first) { + case '\n': + /* Newer GNU diff, empty context line */ + if (plen < 0) + /* ... followed by '\No newline'; nothing */ + break; + old[oldsize++] = '\n'; + new[newsize++] = '\n'; + break; case ' ': case '-': memcpy(old + oldsize, patch + 1, plen);