Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
49555:8ee3889bab92 | 49556:9172bd49cedc |
---|---|
61 content = None | 61 content = None |
62 facts = [] | 62 facts = [] |
63 if isfile: | 63 if isfile: |
64 if opts.type: | 64 if opts.type: |
65 facts.append(b'file') | 65 facts.append(b'file') |
66 if any((opts.hexdump, opts.dump, opts.md5, opts.sha1, opts.sha256)): | 66 needs_reading = ( |
67 opts.hexdump, | |
68 opts.dump, | |
69 opts.md5, | |
70 opts.sha1, | |
71 opts.raw_sha1, | |
72 opts.sha256, | |
73 ) | |
74 | |
75 if any(needs_reading): | |
67 with open(f, 'rb') as fobj: | 76 with open(f, 'rb') as fobj: |
68 content = fobj.read() | 77 content = fobj.read() |
69 elif islink: | 78 elif islink: |
70 if opts.type: | 79 if opts.type: |
71 facts.append(b'link') | 80 facts.append(b'link') |
99 b'older than %s' % opts.newer.encode('utf8', 'replace') | 108 b'older than %s' % opts.newer.encode('utf8', 'replace') |
100 ) | 109 ) |
101 if opts.md5 and content is not None: | 110 if opts.md5 and content is not None: |
102 h = hashlib.md5(content) | 111 h = hashlib.md5(content) |
103 facts.append(b'md5=%s' % binascii.hexlify(h.digest())[: opts.bytes]) | 112 facts.append(b'md5=%s' % binascii.hexlify(h.digest())[: opts.bytes]) |
113 if opts.raw_sha1 and content is not None: | |
114 h = hashlib.sha1(content) | |
115 facts.append(b'raw-sha1=%s' % h.digest()[: opts.bytes]) | |
104 if opts.sha1 and content is not None: | 116 if opts.sha1 and content is not None: |
105 h = hashlib.sha1(content) | 117 h = hashlib.sha1(content) |
106 facts.append( | 118 facts.append( |
107 b'sha1=%s' % binascii.hexlify(h.digest())[: opts.bytes] | 119 b'sha1=%s' % binascii.hexlify(h.digest())[: opts.bytes] |
108 ) | 120 ) |
184 action="store_true", | 196 action="store_true", |
185 help="show sha1 hash of the content", | 197 help="show sha1 hash of the content", |
186 ) | 198 ) |
187 parser.add_option( | 199 parser.add_option( |
188 "", | 200 "", |
201 "--raw-sha1", | |
202 action="store_true", | |
203 help="show raw bytes of the sha1 hash of the content", | |
204 ) | |
205 parser.add_option( | |
206 "", | |
189 "--sha256", | 207 "--sha256", |
190 action="store_true", | 208 action="store_true", |
191 help="show sha256 hash of the content", | 209 help="show sha256 hash of the content", |
192 ) | 210 ) |
193 parser.add_option( | 211 parser.add_option( |