Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/treesum.py @ 208:85e7edea8ac7
Print the filesystem encoding and the generator in the "info" output also
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Wed, 22 Jan 2025 18:58:52 +0100 |
| parents | 0e8c12ff0f41 |
| children | 1be3af138183 |
comparison
equal
deleted
inserted
replaced
| 207:0e8c12ff0f41 | 208:85e7edea8ac7 |
|---|---|
| 1044 reader = TreesumReader.from_binary_buffer(sys.stdin.buffer) | 1044 reader = TreesumReader.from_binary_buffer(sys.stdin.buffer) |
| 1045 else: | 1045 else: |
| 1046 reader = TreesumReader.from_path(fn) | 1046 reader = TreesumReader.from_path(fn) |
| 1047 | 1047 |
| 1048 with reader: | 1048 with reader: |
| 1049 root = flags = algorithm = digest = size = None | 1049 root = generator = flags = fsencoding = algorithm = digest \ |
| 1050 = size = None | |
| 1050 comments = [] | 1051 comments = [] |
| 1051 in_block = False | 1052 in_block = False |
| 1052 block_no = 0 | 1053 block_no = 0 |
| 1053 for record in reader: | 1054 for record in reader: |
| 1054 if record[0] == "VERSION": | 1055 if record[0] == "VERSION": |
| 1056 # start a new block | 1057 # start a new block |
| 1057 in_block = True | 1058 in_block = True |
| 1058 block_no += 1 | 1059 block_no += 1 |
| 1059 root = flags = algorithm = digest = size = None | 1060 root = flags = algorithm = digest = size = None |
| 1060 comments = [] | 1061 comments = [] |
| 1062 elif record[0] == "GENERATOR": | |
| 1063 generator = record[1] | |
| 1064 elif record[0] == "FSENCODING": | |
| 1065 fsencoding = record[1] | |
| 1061 elif record[0] == "FLAGS": | 1066 elif record[0] == "FLAGS": |
| 1062 flags = record[1] | 1067 flags = record[1] |
| 1063 elif record[0] == "ROOT": | 1068 elif record[0] == "ROOT": |
| 1064 root = record[1] | 1069 root = record[1] |
| 1065 elif record[0] == "COMMENT": | 1070 elif record[0] == "COMMENT": |
| 1066 comments.append(record[1]) | 1071 comments.append(record[1]) |
| 1067 elif record[0] in ("FSENCODING", "TIMESTAMP", "ISOTIMESTAMP"): | 1072 elif record[0] in ("TIMESTAMP", "ISOTIMESTAMP"): |
| 1068 pass | 1073 pass |
| 1069 elif record[0] == "CRC32": | 1074 elif record[0] == "CRC32": |
| 1070 pass | 1075 pass |
| 1071 # in_block = False | 1076 # in_block = False |
| 1072 else: | 1077 else: |
| 1083 digest = record[2] | 1088 digest = record[2] |
| 1084 size = record[3] | 1089 size = record[3] |
| 1085 if not print_only_last_block: | 1090 if not print_only_last_block: |
| 1086 print_block_data( | 1091 print_block_data( |
| 1087 block_no, | 1092 block_no, |
| 1088 root, flags, comments, algorithm, digest, size) | 1093 root, generator, fsencoding, flags, comments, |
| 1094 algorithm, digest, size) | |
| 1089 root = flags = algorithm = digest = size = None | 1095 root = flags = algorithm = digest = size = None |
| 1090 in_block = False | 1096 in_block = False |
| 1091 if print_only_last_block: | 1097 if print_only_last_block: |
| 1092 if not in_block: | 1098 if not in_block: |
| 1093 if digest is not None or size is not None: | 1099 if digest is not None or size is not None: |
| 1094 print_block_data( | 1100 print_block_data( |
| 1095 block_no, | 1101 block_no, |
| 1096 root, flags, comments, algorithm, digest, size) | 1102 root, generator, fsencoding, flags, comments, |
| 1103 algorithm, digest, size) | |
| 1097 else: | 1104 else: |
| 1098 logging.warning("missing block end") | 1105 logging.warning("missing block end") |
| 1099 | 1106 |
| 1100 | 1107 |
| 1101 def print_block_data(block_no, tag, flags, comments, algorithm, digest, size): | 1108 def print_block_data(block_no, tag, generator, fsencoding, flags, comments, |
| 1109 algorithm, digest, size): | |
| 1102 digeststr = util.n(binascii.hexlify(digest)) if digest else "<no digest>" | 1110 digeststr = util.n(binascii.hexlify(digest)) if digest else "<no digest>" |
| 1103 sizestr = str(size) if size is not None else "<no size>" | 1111 sizestr = str(size) if size is not None else "<no size>" |
| 1104 print("BLOCK No %d:" % (block_no,)) | 1112 print("BLOCK No %d:" % (block_no,)) |
| 1105 print(" Tag:", tag) | 1113 print(" Tag:", tag) |
| 1114 print(" FS-Encoding:", fsencoding) | |
| 1115 if generator: | |
| 1116 print(" Generator:", generator) | |
| 1106 print(" Flags:", flags if flags else "<none>") | 1117 print(" Flags:", flags if flags else "<none>") |
| 1107 print(" Comments:", comments if comments else "") | 1118 print(" Comments:", comments if comments else "") |
| 1108 print(" Algorithm:", algorithm) | 1119 print(" Algorithm:", algorithm) |
| 1109 if algorithm != "SIZE": | 1120 if algorithm != "SIZE": |
| 1110 print(" Digest:", digeststr) | 1121 print(" Digest:", digeststr) |
