# HG changeset patch # User Franz Glasner # Date 1747035633 -7200 # Node ID 6b327893a9c35f15c317722618b7cb5a12aad7f9 # Parent 54a6d4534ef400bfe0be75fb8ef2ac9816b5254a treesum: Handle comments in .treesum files without accounting for CRCs diff -r 54a6d4534ef4 -r 6b327893a9c3 cutils/treesum.py --- 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