]> git.ozlabs.org Git - patchwork/commitdiff
[parser] Handle special case of "New newline at end of file"
authorNate Case <ncase@xes-inc.com>
Mon, 20 Oct 2008 16:31:11 +0000 (11:31 -0500)
committerJeremy Kerr <jk@ozlabs.org>
Thu, 23 Oct 2008 03:27:10 +0000 (14:27 +1100)
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 <ncase@xes-inc.com>
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
apps/patchwork/parser.py

index abec782f4f7c75cf74d7a83ef73b07f680addbdd..16cc30851e6cc8f38e34cb0e66491cdd84bf347c 100644 (file)
@@ -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