Patchwork Ensure consecutive patch header lines

login
register
mail settings
Submitter Dirk Wallenstein
Date Feb. 9, 2011, 7:35 p.m.
Message ID <20110209193505.GA11850@zap>
Download mbox | patch
Permalink /patch/82524/
State Changes Requested
Headers show

Comments

Dirk Wallenstein - Feb. 9, 2011, 7:35 p.m.
Reset the state if we can't proceed after the optional extended header
line.

Signed-off-by: Dirk Wallenstein <halsmit@t-online.de>
---
This should do the trick -- at least for git-format-patch patches.
Maybe we need a class here to be able to start over with the current
line.

 apps/patchwork/parser.py |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
Jeremy Kerr - Feb. 28, 2011, 1:29 a.m.
Hi Dirk,

> Reset the state if we can't proceed after the optional extended header
> line.

I was originally intending for patchwork to be fairly permissive with what it 
accepts as part of the patch, as patch(1) is happy to ignore stuff that isn't 
part of the actual patch. Looks like it's being *too* permissive though.

I think a nicer fix would be to drop the current parse buffer (ie, make it 
part of the comment) if we see '^diff' again, rather than allowing for only 
one line between '^diff' and '^--- '. This way we should only see entire hunks 
ending up in the patch bufffer.

Cheers,


Jeremy

Patch

diff --git a/apps/patchwork/parser.py b/apps/patchwork/parser.py
index 24631b7..985e196 100644
--- a/apps/patchwork/parser.py
+++ b/apps/patchwork/parser.py
@@ -62,6 +62,7 @@  def parse_patch(text):
     # line counts while parsing a patch hunk
     lc = (0, 0)
     hunk = 0
+    seen_extended_header_line = False
 
     for line in text.decode('utf-8').split('\n'):
         line += '\n'
@@ -83,6 +84,16 @@  def parse_patch(text):
             buf += line
             if line.startswith('--- '):
                 state = 2
+                seen_extended_header_line = False
+
+            elif not seen_extended_header_line:
+                seen_extended_header_line = True
+
+            else:
+                seen_extended_header_line = False
+                state = 0
+                commentbuf += buf + line
+                buf = ''
 
         elif state == 2:
             if line.startswith('+++ '):