diff tests/f @ 49556: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 6000f5b25c9b
children e9d06ed64161
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",