comparison cutils/treesum.py @ 198:c1e875ba4bdc

Put the effective filesystem encoding into the treesum digest file using FSENCODING = <encoding>
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 16 Jan 2025 23:18:04 +0100
parents 48e2610978e5
children 22f92bf3572c
comparison
equal deleted inserted replaced
197:48e2610978e5 198:c1e875ba4bdc
350 350
351 """ 351 """
352 self._outfp = outfp 352 self._outfp = outfp
353 self._outfp.resetdigest() 353 self._outfp.resetdigest()
354 self._outfp.write(format_bsd_line("VERSION", "1", None, False)) 354 self._outfp.write(format_bsd_line("VERSION", "1", None, False))
355 self._outfp.write(format_bsd_line(
356 "FSENCODING", util.n(walk.getfsencoding()), None, False))
355 self._outfp.flush() 357 self._outfp.flush()
356 358
357 # 359 #
358 # Note: Given non-default flags that are relevant for 360 # Note: Given non-default flags that are relevant for
359 # directory traversal. 361 # directory traversal.
626 if not isinstance(what, bytes): 628 if not isinstance(what, bytes):
627 what = what.encode("ascii") 629 what = what.encode("ascii")
628 if what == b"TIMESTAMP": 630 if what == b"TIMESTAMP":
629 assert filename is None 631 assert filename is None
630 return util.interpolate_bytes(b"TIMESTAMP = %d%s", value, ls) 632 return util.interpolate_bytes(b"TIMESTAMP = %d%s", value, ls)
631 if what in (b"ISOTIMESTAMP", b"FLAGS", b"VERSION", b"CRC32"): 633 if what in (b"FSENCODING", b"ISOTIMESTAMP", b"FLAGS", b"VERSION",
634 b"CRC32"):
632 assert filename is None 635 assert filename is None
633 return util.interpolate_bytes(b"%s = %s%s", what, util.b(value), ls) 636 return util.interpolate_bytes(b"%s = %s%s", what, util.b(value), ls)
634 assert filename is not None 637 assert filename is not None
635 if what == b"COMMENT": 638 if what == b"COMMENT":
636 return util.interpolate_bytes( 639 return util.interpolate_bytes(
662 Supports the iterator and context manager protocol. 665 Supports the iterator and context manager protocol.
663 666
664 """ 667 """
665 668
666 PATTERN0 = re.compile(br"\A[ \t]*\r?\n\Z") # empty lines 669 PATTERN0 = re.compile(br"\A[ \t]*\r?\n\Z") # empty lines
667 PATTERN1 = re.compile(br"\A(VERSION|FLAGS|TIMESTAMP|ISOTIMESTAMP|CRC32)[ \t]*=[ \t]*([^ \t]+)[ \t]*\r?\n\Z") # noqa: E501 line too long 670 PATTERN1 = re.compile(br"\A(VERSION|FSENCODING|FLAGS|TIMESTAMP|ISOTIMESTAMP|CRC32)[ \t]*=[ \t]*([^ \t]+)[ \t]*\r?\n\Z") # noqa: E501 line too long
668 PATTERN2 = re.compile(br"\A(ROOT|COMMENT)[ \t]*\((.*)\)[ \t]*\r?\n\Z") 671 PATTERN2 = re.compile(br"\A(ROOT|COMMENT)[ \t]*\((.*)\)[ \t]*\r?\n\Z")
669 PATTERN3 = re.compile(br"\ASIZE[ \t]*\((.*)\)[ \t]*=[ \t]*(\d+)[ \t]*\r?\n\Z") # noqa: E501 line too long 672 PATTERN3 = re.compile(br"\ASIZE[ \t]*\((.*)\)[ \t]*=[ \t]*(\d+)[ \t]*\r?\n\Z") # noqa: E501 line too long
670 PATTERN4 = re.compile(br"\A([A-Za-z0-9_-]+)[ \t]*\((.*)\)[ \t]*=[ \t]*([A-Za-z0-9=+/]+)(,(\d+))?[ \t]*\r?\n\Z") # noqa: E501 line too long 673 PATTERN4 = re.compile(br"\A([A-Za-z0-9_-]+)[ \t]*\((.*)\)[ \t]*=[ \t]*([A-Za-z0-9=+/]+)(,(\d+))?[ \t]*\r?\n\Z") # noqa: E501 line too long
671 674
672 def __init__(self, _fp, _filename, _own_fp): 675 def __init__(self, _fp, _filename, _own_fp):
878 flags = record[1] 881 flags = record[1]
879 elif record[0] == "ROOT": 882 elif record[0] == "ROOT":
880 root = record[1] 883 root = record[1]
881 elif record[0] == "COMMENT": 884 elif record[0] == "COMMENT":
882 comments.append(record[1]) 885 comments.append(record[1])
883 elif record[0] in ("TIMESTAMP", "ISOTIMESTAMP"): 886 elif record[0] in ("FSENCODING", "TIMESTAMP", "ISOTIMESTAMP"):
884 pass 887 pass
885 elif record[0] == "CRC32": 888 elif record[0] == "CRC32":
886 pass 889 pass
887 # in_block = False 890 # in_block = False
888 else: 891 else: