Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/treesum.py @ 134:d2c303695fb8
Put a file version number into the output.
While there change the output order: ROOT() not directly before the digests.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 02 Jan 2025 23:03:20 +0100 |
| parents | cf4fb9a33f94 |
| children | dbf27681a1f6 |
comparison
equal
deleted
inserted
replaced
| 133:cf4fb9a33f94 | 134:d2c303695fb8 |
|---|---|
| 140 """ | 140 """ |
| 141 | 141 |
| 142 :param outfp: a *binary* file with a "write()" and a "flush()" method | 142 :param outfp: a *binary* file with a "write()" and a "flush()" method |
| 143 | 143 |
| 144 """ | 144 """ |
| 145 outfp.write(format_bsd_line("ROOT", None, root, False)) | 145 outfp.write(format_bsd_line("VERSION", "1", None, False)) |
| 146 outfp.flush() | 146 outfp.flush() |
| 147 | 147 |
| 148 # Note given non-default flags that are relevant for directory traversal | 148 # Note given non-default flags that are relevant for directory traversal |
| 149 flags = [] | 149 flags = [] |
| 150 if handle_root_logical: | 150 if handle_root_logical: |
| 151 flags.append("logical") | 151 flags.append("logical") |
| 152 if follow_directory_symlinks: | 152 if follow_directory_symlinks: |
| 153 flags.append("follow-directory-symlinks") | 153 flags.append("follow-directory-symlinks") |
| 154 if flags: | 154 if flags: |
| 155 outfp.write(format_bsd_line("FLAGS", ",".join(flags), None, False)) | 155 outfp.write(format_bsd_line("FLAGS", ",".join(flags), None, False)) |
| 156 outfp.flush() | |
| 156 | 157 |
| 157 # Write execution timestamps in POSIX epoch and ISO format | 158 # Write execution timestamps in POSIX epoch and ISO format |
| 158 ts = time.time() | 159 ts = time.time() |
| 159 outfp.write(format_bsd_line("TIMESTAMP", ts, None, False)) | 160 outfp.write(format_bsd_line("TIMESTAMP", ts, None, False)) |
| 160 ts = (datetime.datetime.utcfromtimestamp(ts)).isoformat("T") | 161 ts = (datetime.datetime.utcfromtimestamp(ts)).isoformat("T") |
| 161 outfp.write(format_bsd_line("ISOTIMESTAMP", ts, None, False)) | 162 outfp.write(format_bsd_line("ISOTIMESTAMP", ts, None, False)) |
| 163 outfp.flush() | |
| 164 | |
| 165 outfp.write(format_bsd_line("ROOT", None, root, False)) | |
| 166 outfp.flush() | |
| 162 | 167 |
| 163 dir_digests = {} | 168 dir_digests = {} |
| 164 | 169 |
| 165 if not handle_root_logical and os.path.islink(root): | 170 if not handle_root_logical and os.path.islink(root): |
| 166 linktgt = util.fsencode(os.readlink(root)) | 171 linktgt = util.fsencode(os.readlink(root)) |
| 225 if not isinstance(digestname, bytes): | 230 if not isinstance(digestname, bytes): |
| 226 digestname = digestname.encode("ascii") | 231 digestname = digestname.encode("ascii") |
| 227 if digestname == b"TIMESTAMP": | 232 if digestname == b"TIMESTAMP": |
| 228 assert filename is None | 233 assert filename is None |
| 229 return b"TIMESTAMP = %d%s" % (value, ls) | 234 return b"TIMESTAMP = %d%s" % (value, ls) |
| 230 if digestname in (b"ISOTIMESTAMP", b"FLAGS"): | 235 if digestname in (b"ISOTIMESTAMP", b"FLAGS", b"VERSION"): |
| 231 assert filename is None | 236 assert filename is None |
| 232 if not isinstance(value, bytes): | 237 if not isinstance(value, bytes): |
| 233 value = value.encode("ascii") | 238 value = value.encode("ascii") |
| 234 return b"%s = %s%s" % (digestname, value, ls) | 239 return b"%s = %s%s" % (digestname, value, ls) |
| 235 assert filename is not None | 240 assert filename is not None |
