From 6cf42625073d11bd63adc681a4d141a932925d0e Mon Sep 17 00:00:00 2001 From: Nate Case Date: Mon, 20 Oct 2008 11:31:11 -0500 Subject: [PATCH] [parser] Handle special case of "New newline at end of file" If a file doesn't have a newline at the end, diff will insert a "\ No newline at end of file" line in the middle of the last hunk. parser.py was counting this line as part of the hunk line count. This had the side effect of putting the last line of the hunk in the patch comment, and truncating out the last line of the diff. Handle this special case by not including this line in the internal line counter. This appears to be the only case where diff will insert a string like this within a hunk. Signed-off-by: Nate Case Signed-off-by: Jeremy Kerr --- apps/patchwork/parser.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/patchwork/parser.py b/apps/patchwork/parser.py index abec782..16cc308 100644 --- a/apps/patchwork/parser.py +++ b/apps/patchwork/parser.py @@ -133,6 +133,9 @@ def parse_patch(text): lc[0] -= 1 elif line.startswith('+'): lc[1] -= 1 + elif line.startswith('\ No newline at end of file'): + # Special case: Not included as part of the hunk's line count + pass else: lc[0] -= 1 lc[1] -= 1 -- 2.39.2