All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [RFC PATCH 13/16] patchstream: Support parsing of review snippets
Date: Sun,  5 Jul 2020 21:42:00 -0600	[thread overview]
Message-ID: <20200706034203.2171077-14-sjg@chromium.org> (raw)
In-Reply-To: <20200706034203.2171077-1-sjg@chromium.org>

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.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/patman/patchstream.py | 53 +++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/tools/patman/patchstream.py b/tools/patman/patchstream.py
index 0c68c86156..5e2b8e3986 100644
--- a/tools/patman/patchstream.py
+++ b/tools/patman/patchstream.py
@@ -2,10 +2,12 @@
 # Copyright (c) 2011 The Chromium OS Authors.
 #
 
+import collections
 import datetime
 import math
 import os
 import re
+import queue
 import shutil
 import tempfile
 
@@ -80,6 +82,10 @@ class PatchStream:
         self.state = STATE_MSG_HEADER    # What state are we in?
         self.signoff = []                # Contents of signoff line
         self.commit = None               # Current commit
+        self.snippets = []               # List of unquoted test blocks
+        self.recent_quoted = collections.deque([], 5)
+        self.recent_unquoted = queue.Queue()
+        self.was_quoted = None
 
     def AddToSeries(self, line, name, value):
         """Add a new Series-xxx tag.
@@ -165,6 +171,40 @@ class PatchStream:
             self.commit.AddChange(self.change_version, change)
         self.change_lines = []
 
+    def FinaliseSnippet(self):
+        """Finish off a snippet and add it to the list
+
+        This is called when we get to the end of a snippet, i.e. the we enter
+        the next block of quoted text:
+
+            This is a comment from someone.
+
+            Something else
+
+            > Now we have some code          <----- end of snippet
+            > more code
+
+            Now a comment about the above code
+
+        This adds the snippet to our list
+        """
+        quoted_lines = []
+        while len(self.recent_quoted):
+            quoted_lines.append(self.recent_quoted.popleft())
+        unquoted_lines = []
+        valid = False
+        while not self.recent_unquoted.empty():
+            text = self.recent_unquoted.get()
+            unquoted_lines.append(text)
+            if text:
+                valid = True
+        if valid:
+            lines = quoted_lines + unquoted_lines
+            if lines[0].startswith('On ') and lines[0].endswith('wrote:'):
+                lines = lines[1:]
+            if lines:
+                self.snippets.append(lines)
+
     def ProcessLine(self, line):
         """Process a single line of a patch file or commit log
 
@@ -384,6 +424,18 @@ class PatchStream:
             out = [line]
             self.linenum += 1
             self.skip_blank = False
+
+            # If this is quoted, keep recent lines
+            if self.linenum > 1 and line:
+                if line.startswith('>'):
+                    if not self.was_quoted:
+                        self.FinaliseSnippet()
+                    self.recent_quoted.append(line)
+                    self.was_quoted = True
+                else:
+                    self.recent_unquoted.put(line)
+                    self.was_quoted = False
+
             if self.state == STATE_DIFFS:
                 pass
 
@@ -407,6 +459,7 @@ class PatchStream:
 
     def Finalize(self):
         """Close out processing of this patch stream"""
+        self.FinaliseSnippet()
         self.FinalizeChange()
         self.CloseCommit()
         if self.lines_after_test:
-- 
2.27.0.212.ge8ba1cc988-goog

  parent reply	other threads:[~2020-07-06  3:42 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-06  3:41 [RFC PATCH 00/16] RFC: patman: Collect review tags and comments from Patchwork Simon Glass
2020-07-06  3:41 ` [RFC PATCH 01/16] patman: Use test_util to show test results Simon Glass
2020-07-06  4:46   ` Daniel Axtens
2020-07-06  4:50     ` Daniel Axtens
2020-07-06 14:52       ` Simon Glass
2020-07-07  1:09         ` Daniel Axtens
2020-07-08 17:42           ` Stephen Finucane
2020-07-19 20:49           ` Simon Glass
2020-07-06  3:41 ` [RFC PATCH 02/16] patman: Move main code out to a control module Simon Glass
2020-07-06  3:41 ` [RFC PATCH 03/16] patman: Add a test that uses gitpython Simon Glass
2020-07-06  3:41 ` [RFC PATCH 04/16] patman: Allow creating patches for another branch Simon Glass
2020-07-06  3:41 ` [RFC PATCH 05/16] patman: Allow skipping patches at the end Simon Glass
2020-07-06  3:41 ` [RFC PATCH 06/16] patman: Convert to ArgumentParser Simon Glass
2020-07-06  3:41 ` [RFC PATCH 07/16] patman: Allow different commands Simon Glass
2020-07-06  3:41 ` [RFC PATCH 08/16] patman: Add a 'test' subcommand Simon Glass
2020-07-06  3:41 ` [RFC PATCH 09/16] patman: Allow disabling 'bright' mode with Print output Simon Glass
2020-07-06  3:41 ` [RFC PATCH 10/16] patman: Support collecting response tags in Patchstream Simon Glass
2020-07-06  3:41 ` [RFC PATCH 11/16] patman: Allow linking a series with patchwork Simon Glass
2020-07-06  3:41 ` [RFC PATCH 12/16] patman: Add a -D option to enable debugging Simon Glass
2020-07-06  3:42 ` Simon Glass [this message]
2020-07-06  3:42 ` [RFC PATCH 14/16] patman: Support checking for review tags in patchwork Simon Glass
2020-07-06  3:42 ` [RFC PATCH 15/16] patman: Support updating a branch with review tags Simon Glass
2020-07-06  3:42 ` [RFC PATCH 16/16] patman: Support listing comments from patchwork Simon Glass
2020-07-15  9:10 ` [RFC PATCH 00/16] RFC: patman: Collect review tags and comments from Patchwork Michal Simek
2020-07-19 20:49 ` [RFC PATCH 10/16] patman: Support collecting response tags in Patchstream Simon Glass
2020-07-19 20:49 ` [RFC PATCH 09/16] patman: Allow disabling 'bright' mode with Print output Simon Glass
2020-07-19 20:49 ` [RFC PATCH 08/16] patman: Add a 'test' subcommand Simon Glass
2020-07-19 20:49 ` [RFC PATCH 07/16] patman: Allow different commands Simon Glass
2020-07-19 20:49 ` [RFC PATCH 06/16] patman: Convert to ArgumentParser Simon Glass
2020-07-19 20:49 ` [RFC PATCH 05/16] patman: Allow skipping patches at the end Simon Glass
2020-07-19 20:49 ` [RFC PATCH 04/16] patman: Allow creating patches for another branch Simon Glass
2020-07-19 20:49 ` [RFC PATCH 03/16] patman: Add a test that uses gitpython Simon Glass
2020-07-19 20:49 ` [RFC PATCH 02/16] patman: Move main code out to a control module Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200706034203.2171077-14-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.