From b507b465f7831612b9d9fc643e3e5218b64e5bfa Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 19 Oct 2006 19:26:08 -0700 Subject: git-apply: prepare for upcoming GNU diff -u format change. The latest GNU diff from CVS emits an empty line to express an empty context line, instead of more traditional "single white space followed by a newline". Do not get broken by it. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- builtin-apply.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'builtin-apply.c') diff --git a/builtin-apply.c b/builtin-apply.c index cbe597771b..11a5277a69 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -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--; @@ -1623,6 +1624,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); -- cgit v1.2.3