Author: dsahlberg
Date: Sat Mar  1 19:52:37 2025
New Revision: 1924117

URL: http://svn.apache.org/viewvc?rev=1924117&view=rev
Log:
Update backport/status parser with the end goal of creating an interactive
backport nomination script.

Fix a bug in logsummary parsing where a missing logsummary didn't raise 
an expected exception. This caused unittests to fail.

* dist/backport/status.py
  (StatusEntry.__init__): When parsing the logsummary, also check if the first
    line is a subheader (otherwise the logsummary may incorrectly contain
    that subheader).
  (StatusEntry._is_subheader): Check subheaders against explicit list of known
    subheaders to avoid spurious matches if a text starts with a subheader-
    like text.
  (Test_StatusEntry.test__is_subheader): Test for returning false on subheader-
    like text and non-subheader.


Modified:
    subversion/trunk/tools/dist/backport/status.py

Modified: subversion/trunk/tools/dist/backport/status.py
URL: 
http://svn.apache.org/viewvc/subversion/trunk/tools/dist/backport/status.py?rev=1924117&r1=1924116&r2=1924117&view=diff
==============================================================================
--- subversion/trunk/tools/dist/backport/status.py (original)
+++ subversion/trunk/tools/dist/backport/status.py Sat Mar  1 19:52:37 2025
@@ -380,10 +380,10 @@ class StatusEntry:
 
     # Parse the logsummary.
     while True:
-      self.logsummary.append(lines[0])
-      lines = lines[1:]
       if (not lines) or self._is_subheader(lines[0]):
         break
+      self.logsummary.append(lines[0])
+      lines = lines[1:]
 
     # Parse votes.
     if "Votes:" in lines:
@@ -515,7 +515,11 @@ class StatusEntry:
     #
     # This is currently only used for finding the end of logsummary, and all
     # explicitly special-cased headers (e.g., "Depends:") match this, though.
-    return re.compile(r'^\s*[A-Z]\w*:').match(string)
+    subheaders = "Justification: Notes: Depends: Branch: Votes:".split()
+    for subheader in subheaders:
+      if string.strip().startswith(subheader):
+        return True
+    return False
 
   def unparse(self, stream):
     "Write this entry to STREAM, an open file-like object."
@@ -691,6 +695,9 @@ class Test_StatusEntry(unittest.TestCase
     for subheader in subheaders:
       self.assertTrue(StatusEntry._is_subheader(subheader))
       self.assertTrue(StatusEntry._is_subheader(subheader + " with value"))
+    self.assertFalse(StatusEntry._is_subheader("UnknownSubheader: with value"))
+    self.assertFalse(StatusEntry._is_subheader("UnknownSubheader:"))
+    self.assertFalse(StatusEntry._is_subheader("regular text"))
 
 
 def setUpModule():


Reply via email to