# HG changeset patch # User Raphaël Gomès # Date 1667473682 -3600 # Node ID 9172bd49cedca183b840c961d9f8787e02146645 # Parent 8ee3889bab927284e2ebb5ad75eb943f40e2fd5f 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. diff -r 8ee3889bab92 -r 9172bd49cedc tests/f --- 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", diff -r 8ee3889bab92 -r 9172bd49cedc tests/test-tools.t --- 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