patman: Support parsing of review snippets

Add support for parsing the contents of a patchwork 'patch' web page
containing comments received from reviewers. This allows patman to show
these comments in a simple 'snippets' format.

A snippet is some quoted code plus some unquoted comments below it. Each
review is from a unique person/email and can produce multiple snippets,
one for each part of the code that attracts a comment.

Show the file and line-number info at the top of each snippet if
available.

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/tools/patman/func_test.py b/tools/patman/func_test.py
index 2e15295..bbee4b7 100644
--- a/tools/patman/func_test.py
+++ b/tools/patman/func_test.py
@@ -1043,3 +1043,86 @@
         self.assertEqual('Reviewed-by: %s' % self.fred, next(lines))
         self.assertEqual('Reviewed-by: %s' % self.mary, next(lines))
         self.assertEqual('Tested-by: %s' % self.leb, next(lines))
+
+    def testParseSnippets(self):
+        """Test parsing of review snippets"""
+        text = '''Hi Fred,
+
+This is a comment from someone.
+
+Something else
+
+On some recent date, Fred wrote:
+> This is why I wrote the patch
+> so here it is
+
+Now a comment about the commit message
+A little more to say
+
+Even more
+
+> diff --git a/file.c b/file.c
+> Some more code
+> Code line 2
+> Code line 3
+> Code line 4
+> Code line 5
+> Code line 6
+> Code line 7
+> Code line 8
+> Code line 9
+
+And another comment
+
+> @@ -153,8 +143,13 @@ def CheckPatch(fname, show_types=False):
+>  further down on the file
+>  and more code
+> +Addition here
+> +Another addition here
+>  codey
+>  more codey
+
+and another thing in same file
+
+> @@ -253,8 +243,13 @@
+>  with no function context
+
+one more thing
+
+> diff --git a/tools/patman/main.py b/tools/patman/main.py
+> +line of code
+now a very long comment in a different file
+line2
+line3
+line4
+line5
+line6
+line7
+line8
+'''
+        pstrm = PatchStream.process_text(text, True)
+        self.assertEqual([], pstrm.commit.warn)
+
+        # We expect to the filename and up to 5 lines of code context before
+        # each comment. The 'On xxx wrote:' bit should be removed.
+        self.assertEqual(
+            [['Hi Fred,',
+              'This is a comment from someone.',
+              'Something else'],
+             ['> This is why I wrote the patch',
+              '> so here it is',
+              'Now a comment about the commit message',
+              'A little more to say', 'Even more'],
+             ['> File: file.c', '> Code line 5', '> Code line 6',
+              '> Code line 7', '> Code line 8', '> Code line 9',
+              'And another comment'],
+             ['> File: file.c',
+              '> Line: 153 / 143: def CheckPatch(fname, show_types=False):',
+              '>  and more code', '> +Addition here', '> +Another addition here',
+              '>  codey', '>  more codey', 'and another thing in same file'],
+             ['> File: file.c', '> Line: 253 / 243',
+              '>  with no function context', 'one more thing'],
+             ['> File: tools/patman/main.py', '> +line of code',
+              'now a very long comment in a different file',
+              'line2', 'line3', 'line4', 'line5', 'line6', 'line7', 'line8']],
+            pstrm.snippets)