changeset 377:6b327893a9c3

treesum: Handle comments in .treesum files without accounting for CRCs
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 12 May 2025 09:40:33 +0200
parents 54a6d4534ef4
children 32b937a73068
files cutils/treesum.py
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/cutils/treesum.py	Mon May 05 13:04:49 2025 +0200
+++ b/cutils/treesum.py	Mon May 12 09:40:33 2025 +0200
@@ -1693,7 +1693,8 @@
 
     """
 
-    PATTERN0 = re.compile(br"\A[ \t]*\r?\n\Z")   # empty lines
+    PATTERNC = re.compile(br"\A\s*[#;].*\r?\n\Z")  # comments, no CRC
+    PATTERN0 = re.compile(br"\A[ \t]*\r?\n\Z")     # empty lines
     PATTERN1 = re.compile(br"\A(VERSION|FSENCODING|FLAGS|TIMESTAMP|ISOTIMESTAMP|CRC32)[ \t]*=[ \t]*([^ \t]+)[ \t]*\r?\n\Z")      # noqa: E501  line too long
     PATTERN2 = re.compile(br"\A(ROOT|COMMENT|ERROR|GENERATOR|FNMATCH|ACCEPT-TREESUM)[ \t]*\((.*)\)[ \t]*\r?\n\Z")                                       # noqa: E501  line too long
     PATTERN3 = re.compile(br"\ASIZE[ \t]*\((.*)\)([ \t]*=[ \t]*([0-9., '_]*[0-9]))?[ \t]*\r?\n\Z")                                               # noqa: E501  line too long
@@ -1757,6 +1758,10 @@
         :returns: `None` at EOF or the parsed contents of the line
         :rtype: tuple or None
 
+        .. note:: Empty lines and comment lines are handled differently with
+                  regard to CRCs: empty lines count for the CRC, comment lines
+                  do not.
+
         """
         # Loop to skip empty lines
         while True:
@@ -1770,8 +1775,12 @@
                     if self._expect_crc:
                         logging.warning("CRC32 is missing at EOF")
                 return None
+            # Skip comments and do NOT update CRC for comment lines
+            if self.PATTERNC.search(line):
+                continue
             if not self.PATTERN0.search(line):
                 break
+            # Empty lines count for CRC
             self._update_crc(line)
         #
         # At the beginning transparently skip an eventually  embedded signify