Mercurial > hg-stable
changeset 49548:9172bd49cedc stable
testlib: add `--raw-sha1` option to `f`
This will be used in the patch fixing the ignore hash collision in
dirstate-v2 to check the behavior of the new hashing function.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Thu, 03 Nov 2022 12:08:02 +0100 |
parents | 8ee3889bab92 |
children | ca19335e86e5 |
files | tests/f tests/test-tools.t |
diffstat | 2 files changed, 20 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/f Wed Oct 19 16:28:41 2022 +0200 +++ b/tests/f Thu Nov 03 12:08:02 2022 +0100 @@ -63,7 +63,16 @@ if isfile: if opts.type: facts.append(b'file') - if any((opts.hexdump, opts.dump, opts.md5, opts.sha1, opts.sha256)): + needs_reading = ( + opts.hexdump, + opts.dump, + opts.md5, + opts.sha1, + opts.raw_sha1, + opts.sha256, + ) + + if any(needs_reading): with open(f, 'rb') as fobj: content = fobj.read() elif islink: @@ -101,6 +110,9 @@ if opts.md5 and content is not None: h = hashlib.md5(content) facts.append(b'md5=%s' % binascii.hexlify(h.digest())[: opts.bytes]) + if opts.raw_sha1 and content is not None: + h = hashlib.sha1(content) + facts.append(b'raw-sha1=%s' % h.digest()[: opts.bytes]) if opts.sha1 and content is not None: h = hashlib.sha1(content) facts.append( @@ -186,6 +198,12 @@ ) parser.add_option( "", + "--raw-sha1", + action="store_true", + help="show raw bytes of the sha1 hash of the content", + ) + parser.add_option( + "", "--sha256", action="store_true", help="show sha256 hash of the content",
--- a/tests/test-tools.t Wed Oct 19 16:28:41 2022 +0200 +++ b/tests/test-tools.t Thu Nov 03 12:08:02 2022 +0100 @@ -13,6 +13,7 @@ check if file is newer (or same) -r, --recurse recurse into directories -S, --sha1 show sha1 hash of the content + --raw-sha1 show raw bytes of the sha1 hash of the content --sha256 show sha256 hash of the content -M, --md5 show md5 hash of the content -D, --dump dump file content