[PATCH] Ensure consecutive patch header lines

Dirk Wallenstein halsmit at t-online.de
Thu Feb 10 06:35:05 EST 2011


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

Signed-off-by: Dirk Wallenstein <halsmit at 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(-)

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('+++ '):
-- 
1.7.3.2


More information about the Patchwork mailing list