Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/treesum.py @ 161:df927ada9a37
In directory digests: include the octet-length of the checksums also
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Tue, 07 Jan 2025 19:20:32 +0100 |
| parents | 432fe71300d3 |
| children | bcc4441cf216 |
comparison
equal
deleted
inserted
replaced
| 160:432fe71300d3 | 161:df927ada9a37 |
|---|---|
| 319 linktgt = util.fsencode(os.readlink(root)) | 319 linktgt = util.fsencode(os.readlink(root)) |
| 320 linkdgst = algorithm[0]() | 320 linkdgst = algorithm[0]() |
| 321 linkdgst.update(b"%d:%s," % (len(linktgt), linktgt)) | 321 linkdgst.update(b"%d:%s," % (len(linktgt), linktgt)) |
| 322 dir_dgst = algorithm[0]() | 322 dir_dgst = algorithm[0]() |
| 323 dir_dgst.update(b"1:L,") | 323 dir_dgst.update(b"1:L,") |
| 324 dir_dgst.update(linkdgst.digest()) | 324 dir_dgst.update( |
| 325 b"%d:%s," % (len(linkdgst.digest()), linkdgst.digest())) | |
| 325 outfp.write( | 326 outfp.write( |
| 326 format_bsd_line( | 327 format_bsd_line( |
| 327 algorithm[1], | 328 algorithm[1], |
| 328 dir_dgst.digest(), | 329 dir_dgst.digest(), |
| 329 "./@", | 330 "./@", |
| 342 linkdgst = algorithm[0]() | 343 linkdgst = algorithm[0]() |
| 343 linkdgst.update(b"%d:%s," % (len(linktgt), linktgt)) | 344 linkdgst.update(b"%d:%s," % (len(linktgt), linktgt)) |
| 344 dir_dgst.update(b"1:S,%d:%s," | 345 dir_dgst.update(b"1:S,%d:%s," |
| 345 % (len(fso.fsname), fso.fsname)) | 346 % (len(fso.fsname), fso.fsname)) |
| 346 # no mtime and no mode for symlinks | 347 # no mtime and no mode for symlinks |
| 347 dir_dgst.update(linkdgst.digest()) | 348 dir_dgst.update( |
| 349 b"%d:%s," | |
| 350 % (len(linkdgst.digest()), linkdgst.digest())) | |
| 348 opath = "/".join(top) + "/" + fso.name if top else fso.name | 351 opath = "/".join(top) + "/" + fso.name if top else fso.name |
| 349 outfp.write( | 352 outfp.write( |
| 350 format_bsd_line( | 353 format_bsd_line( |
| 351 algorithm[1], | 354 algorithm[1], |
| 352 linkdgst.digest(), | 355 linkdgst.digest(), |
| 355 outfp.flush() | 358 outfp.flush() |
| 356 continue | 359 continue |
| 357 # fetch from dir_digests | 360 # fetch from dir_digests |
| 358 dgst = dir_digests[top + (fso.name,)] | 361 dgst = dir_digests[top + (fso.name,)] |
| 359 dir_dgst.update(b"1:d,%d:%s," % (len(fso.fsname), fso.fsname)) | 362 dir_dgst.update(b"1:d,%d:%s," % (len(fso.fsname), fso.fsname)) |
| 360 dir_dgst.update(dgst) | 363 dir_dgst.update( |
| 364 b"%d:%s," % (len(dgst), dgst)) | |
| 361 if with_metadata_full_mode: | 365 if with_metadata_full_mode: |
| 362 modestr = normalized_mode_str(fso.stat.st_mode) | 366 modestr = normalized_mode_str(fso.stat.st_mode) |
| 363 if not isinstance(modestr, bytes): | 367 if not isinstance(modestr, bytes): |
| 364 modestr = modestr.encode("ascii") | 368 modestr = modestr.encode("ascii") |
| 365 dir_dgst.update(b"8:fullmode,%d:%s," | 369 dir_dgst.update(b"8:fullmode,%d:%s," |
| 389 if not isinstance(modestr, bytes): | 393 if not isinstance(modestr, bytes): |
| 390 modestr = modestr.encode("ascii") | 394 modestr = modestr.encode("ascii") |
| 391 dir_dgst.update(b"4:mode,%d:%s," % (len(modestr), modestr)) | 395 dir_dgst.update(b"4:mode,%d:%s," % (len(modestr), modestr)) |
| 392 dgst = digest.compute_digest_file( | 396 dgst = digest.compute_digest_file( |
| 393 algorithm[0], fso.path, use_mmap=use_mmap) | 397 algorithm[0], fso.path, use_mmap=use_mmap) |
| 394 dir_dgst.update(dgst) | 398 dir_dgst.update(b"%d:%s," % (len(dgst), dgst)) |
| 395 opath = "/".join(top) + "/" + fso.name if top else fso.name | 399 opath = "/".join(top) + "/" + fso.name if top else fso.name |
| 396 outfp.write( | 400 outfp.write( |
| 397 format_bsd_line( | 401 format_bsd_line( |
| 398 algorithm[1], dgst, opath, use_base64)) | 402 algorithm[1], dgst, opath, use_base64)) |
| 399 outfp.flush() | 403 outfp.flush() |
