threads / patch / 14291

patchFix apply --recount handling of no-EOL line

Subject: [PATCH] Fix apply --recount handling of no-EOL line

## tl;dr

2 messages between Jul 4, 2008 and Jul 4, 2008. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Thomas Rast· Jul 4, 2008, 19:10 UTC · lore

If a patch modifies the last line of a file that previously had no terminating '\n', it looks like

-old text \ No newline at end of file +new text

Hence, a '\' line does not signal the end of the hunk. This modifies 'git apply --recount' to take this into account.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---

This is just the straightforward fix. A more elaborate solution might check if the previous line was a ' ' and '+', and if so, consider the hunk terminated anyway.

- Thomas
 builtin-apply.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to builtin-apply.c +1 −1
diff --git a/builtin-apply.c b/builtin-apply.c
index 194f03b..fb85a5b 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -931,7 +931,7 @@ static void recount_diff(char *line, int size, struct fragment *fragment)
 			newlines++;
 			continue;
 		case '\\':
-			break;
+			continue;
 		case '@':
 			ret = size < 3 || prefixcmp(line, "@@ ");
 			break;
-- 
1.5.6.1.330.g2ff03
Johannes Schindelin· Jul 4, 2008, 19:34 UTC · re: Thomas Rast · lore

Re: [PATCH] Fix apply --recount handling of no-EOL line

Hi,
On Fri, 4 Jul 2008, Thomas Rast wrote:
Show 6 quoted lines
> If a patch modifies the last line of a file that previously had no
> terminating '\n', it looks like
> 
> -old text
> \ No newline at end of file
> +new text
Oh!
> Hence, a '\' line does not signal the end of the hunk.  This modifies
> 'git apply --recount' to take this into account.
> 
> Signed-off-by: Thomas Rast <trast@student.ethz.ch>
ACK!

Ciao, Dscho

← back to recent threads