Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/treesum.py @ 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 | 7044c2900890 |
| children | 32b937a73068 |
comparison
equal
deleted
inserted
replaced
| 376:54a6d4534ef4 | 377:6b327893a9c3 |
|---|---|
| 1691 | 1691 |
| 1692 Supports the iterator and context manager protocol. | 1692 Supports the iterator and context manager protocol. |
| 1693 | 1693 |
| 1694 """ | 1694 """ |
| 1695 | 1695 |
| 1696 PATTERN0 = re.compile(br"\A[ \t]*\r?\n\Z") # empty lines | 1696 PATTERNC = re.compile(br"\A\s*[#;].*\r?\n\Z") # comments, no CRC |
| 1697 PATTERN0 = re.compile(br"\A[ \t]*\r?\n\Z") # empty lines | |
| 1697 PATTERN1 = re.compile(br"\A(VERSION|FSENCODING|FLAGS|TIMESTAMP|ISOTIMESTAMP|CRC32)[ \t]*=[ \t]*([^ \t]+)[ \t]*\r?\n\Z") # noqa: E501 line too long | 1698 PATTERN1 = re.compile(br"\A(VERSION|FSENCODING|FLAGS|TIMESTAMP|ISOTIMESTAMP|CRC32)[ \t]*=[ \t]*([^ \t]+)[ \t]*\r?\n\Z") # noqa: E501 line too long |
| 1698 PATTERN2 = re.compile(br"\A(ROOT|COMMENT|ERROR|GENERATOR|FNMATCH|ACCEPT-TREESUM)[ \t]*\((.*)\)[ \t]*\r?\n\Z") # noqa: E501 line too long | 1699 PATTERN2 = re.compile(br"\A(ROOT|COMMENT|ERROR|GENERATOR|FNMATCH|ACCEPT-TREESUM)[ \t]*\((.*)\)[ \t]*\r?\n\Z") # noqa: E501 line too long |
| 1699 PATTERN3 = re.compile(br"\ASIZE[ \t]*\((.*)\)([ \t]*=[ \t]*([0-9., '_]*[0-9]))?[ \t]*\r?\n\Z") # noqa: E501 line too long | 1700 PATTERN3 = re.compile(br"\ASIZE[ \t]*\((.*)\)([ \t]*=[ \t]*([0-9., '_]*[0-9]))?[ \t]*\r?\n\Z") # noqa: E501 line too long |
| 1700 PATTERN4 = re.compile(br"\A([A-Za-z0-9_-]+)[ \t]*\((.*)\)([ \t]*=[ \t]*([A-Za-z0-9=+/]+)?(,([0-9., '_]*[0-9])?)?)?[ \t]*\r?\n\Z") # noqa: E501 line too long | 1701 PATTERN4 = re.compile(br"\A([A-Za-z0-9_-]+)[ \t]*\((.*)\)([ \t]*=[ \t]*([A-Za-z0-9=+/]+)?(,([0-9., '_]*[0-9])?)?)?[ \t]*\r?\n\Z") # noqa: E501 line too long |
| 1701 | 1702 |
| 1754 def read_record(self): | 1755 def read_record(self): |
| 1755 """Read and parse the "next" line. | 1756 """Read and parse the "next" line. |
| 1756 | 1757 |
| 1757 :returns: `None` at EOF or the parsed contents of the line | 1758 :returns: `None` at EOF or the parsed contents of the line |
| 1758 :rtype: tuple or None | 1759 :rtype: tuple or None |
| 1760 | |
| 1761 .. note:: Empty lines and comment lines are handled differently with | |
| 1762 regard to CRCs: empty lines count for the CRC, comment lines | |
| 1763 do not. | |
| 1759 | 1764 |
| 1760 """ | 1765 """ |
| 1761 # Loop to skip empty lines | 1766 # Loop to skip empty lines |
| 1762 while True: | 1767 while True: |
| 1763 line = self._get_next_line() | 1768 line = self._get_next_line() |
| 1768 # | 1773 # |
| 1769 if self._expect_crc is not None: | 1774 if self._expect_crc is not None: |
| 1770 if self._expect_crc: | 1775 if self._expect_crc: |
| 1771 logging.warning("CRC32 is missing at EOF") | 1776 logging.warning("CRC32 is missing at EOF") |
| 1772 return None | 1777 return None |
| 1778 # Skip comments and do NOT update CRC for comment lines | |
| 1779 if self.PATTERNC.search(line): | |
| 1780 continue | |
| 1773 if not self.PATTERN0.search(line): | 1781 if not self.PATTERN0.search(line): |
| 1774 break | 1782 break |
| 1783 # Empty lines count for CRC | |
| 1775 self._update_crc(line) | 1784 self._update_crc(line) |
| 1776 # | 1785 # |
| 1777 # At the beginning transparently skip an eventually embedded signify | 1786 # At the beginning transparently skip an eventually embedded signify |
| 1778 # signature | 1787 # signature |
| 1779 # | 1788 # |
