Mercurial > hg
annotate tests/md5sum.py @ 43256:00de32aa834e
copies: use an unfiltered repository for the changeset centric algorithm
Since the algorithm work form heads to ancestors, we don't need to check
filtering for anything but the two entries.
Using an unfiltered version is noticeably more efficient.
Some timing on the pypy repo:
revision: large amount; added files: large amount; rename small amount; c3b14617fbd7 9ba6ab77fd29
before: ! wall 2.717861 comb 2.720000 user 2.700000 sys 0.020000 (median of 10)
after: ! wall 2.582204 comb 2.580000 user 2.560000 sys 0.020000 (median of 10)
revision: large amount; added files: small amount; rename small amount; c3b14617fbd7 f650a9b140d2
before: ! wall 4.003146 comb 4.010000 user 3.970000 sys 0.040000 (median of 10)
after: ! wall 3.814613 comb 3.810000 user 3.760000 sys 0.050000 (median of 10)
revision: large amount; added files: large amount; rename large amount; 08ea3258278e d9fa043f30c0
before: ! wall 0.704204 comb 0.700000 user 0.700000 sys 0.000000 (median of 13)
after: ! wall 0.657387 comb 0.650000 user 0.640000 sys 0.010000 (best of 14)
revision: small amount; added files: large amount; rename large amount; df6f7a526b60 a83dc6a2d56f
before: ! wall 0.013493 comb 0.020000 user 0.020000 sys 0.000000 (median of 219)
after: ! wall 0.013523 comb 0.020000 user 0.020000 sys 0.000000 (median of 218)
revision: small amount; added files: large amount; rename small amount; 4aa4e1f8e19a 169138063d63
before: ! wall 0.003017 comb 0.000000 user 0.000000 sys 0.000000 (median of 985)
after: ! wall 0.002876 comb 0.000000 user 0.000000 sys 0.000000 (median of 1000)
revision: small amount; added files: small amount; rename small amount; 4bc173b045a6 964879152e2e
before: ! wall 0.000073 comb 0.000000 user 0.000000 sys 0.000000 (median of 12672)
after: ! wall 0.000082 comb 0.000000 user 0.000000 sys 0.000000 (median of 11456)
revision: medium amount; added files: large amount; rename medium amount; c95f1ced15f2 2c68e87c3efe
before: ! wall 0.478061 comb 0.470000 user 0.470000 sys 0.000000 (median of 19)
after: ! wall 0.452420 comb 0.450000 user 0.450000 sys 0.000000 (median of 21)
revision: medium amount; added files: medium amount; rename small amount; d343da0c55a8 d7746d32bf9d
before: ! wall 0.116015 comb 0.110000 user 0.110000 sys 0.000000 (median of 84)
after: ! wall 0.109153 comb 0.100000 user 0.100000 sys 0.000000 (median of 90)
Differential Revision: https://phab.mercurial-scm.org/D7123
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 15 Oct 2019 18:42:03 +0200 |
parents | 2372284d9457 |
children | c102b704edb5 |
rev | line source |
---|---|
4122
306055f5b65c
Unified #! paths for python scripts and removed them for test modules.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3223
diff
changeset
|
1 #!/usr/bin/env python |
1928
50e1c90b0fcf
clarify license on md5sum.py
Peter van Dijk <peter@dataloss.nl>
parents:
1924
diff
changeset
|
2 # |
50e1c90b0fcf
clarify license on md5sum.py
Peter van Dijk <peter@dataloss.nl>
parents:
1924
diff
changeset
|
3 # Based on python's Tools/scripts/md5sum.py |
50e1c90b0fcf
clarify license on md5sum.py
Peter van Dijk <peter@dataloss.nl>
parents:
1924
diff
changeset
|
4 # |
50e1c90b0fcf
clarify license on md5sum.py
Peter van Dijk <peter@dataloss.nl>
parents:
1924
diff
changeset
|
5 # This software may be used and distributed according to the terms |
50e1c90b0fcf
clarify license on md5sum.py
Peter van Dijk <peter@dataloss.nl>
parents:
1924
diff
changeset
|
6 # of the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2, which is |
50e1c90b0fcf
clarify license on md5sum.py
Peter van Dijk <peter@dataloss.nl>
parents:
1924
diff
changeset
|
7 # GPL-compatible. |
50e1c90b0fcf
clarify license on md5sum.py
Peter van Dijk <peter@dataloss.nl>
parents:
1924
diff
changeset
|
8 |
29485
6a98f9408a50
py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
25660
diff
changeset
|
9 from __future__ import absolute_import |
6a98f9408a50
py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
25660
diff
changeset
|
10 |
33873
904bc1dc2694
md5sum: assume hashlib exists now that we're 2.7 only
Augie Fackler <raf@durin42.com>
parents:
32852
diff
changeset
|
11 import hashlib |
29485
6a98f9408a50
py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
25660
diff
changeset
|
12 import os |
6a98f9408a50
py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
25660
diff
changeset
|
13 import sys |
6470
ac0bcd951c2c
python 2.6 compatibility: compatibility wrappers for hash functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6212
diff
changeset
|
14 |
ac0bcd951c2c
python 2.6 compatibility: compatibility wrappers for hash functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6212
diff
changeset
|
15 try: |
7080
a6477aa893b8
tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents:
6470
diff
changeset
|
16 import msvcrt |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
33873
diff
changeset
|
17 |
7080
a6477aa893b8
tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents:
6470
diff
changeset
|
18 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) |
a6477aa893b8
tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents:
6470
diff
changeset
|
19 msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY) |
a6477aa893b8
tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents:
6470
diff
changeset
|
20 except ImportError: |
a6477aa893b8
tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents:
6470
diff
changeset
|
21 pass |
a6477aa893b8
tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents:
6470
diff
changeset
|
22 |
1924
46fb38ef9a91
add md5sum.py required by fix in previous changeset
Peter van Dijk <peter@dataloss.nl>
parents:
diff
changeset
|
23 for filename in sys.argv[1:]: |
46fb38ef9a91
add md5sum.py required by fix in previous changeset
Peter van Dijk <peter@dataloss.nl>
parents:
diff
changeset
|
24 try: |
46fb38ef9a91
add md5sum.py required by fix in previous changeset
Peter van Dijk <peter@dataloss.nl>
parents:
diff
changeset
|
25 fp = open(filename, 'rb') |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
14494
diff
changeset
|
26 except IOError as msg: |
1924
46fb38ef9a91
add md5sum.py required by fix in previous changeset
Peter van Dijk <peter@dataloss.nl>
parents:
diff
changeset
|
27 sys.stderr.write('%s: Can\'t open: %s\n' % (filename, msg)) |
46fb38ef9a91
add md5sum.py required by fix in previous changeset
Peter van Dijk <peter@dataloss.nl>
parents:
diff
changeset
|
28 sys.exit(1) |
3223
53e843840349
Whitespace/Tab cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1928
diff
changeset
|
29 |
33873
904bc1dc2694
md5sum: assume hashlib exists now that we're 2.7 only
Augie Fackler <raf@durin42.com>
parents:
32852
diff
changeset
|
30 m = hashlib.md5() |
1924
46fb38ef9a91
add md5sum.py required by fix in previous changeset
Peter van Dijk <peter@dataloss.nl>
parents:
diff
changeset
|
31 try: |
32852
3a64ac39b893
md5sum: adapt for python 3 support
Augie Fackler <augie@google.com>
parents:
29731
diff
changeset
|
32 for data in iter(lambda: fp.read(8192), b''): |
1924
46fb38ef9a91
add md5sum.py required by fix in previous changeset
Peter van Dijk <peter@dataloss.nl>
parents:
diff
changeset
|
33 m.update(data) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
14494
diff
changeset
|
34 except IOError as msg: |
1924
46fb38ef9a91
add md5sum.py required by fix in previous changeset
Peter van Dijk <peter@dataloss.nl>
parents:
diff
changeset
|
35 sys.stderr.write('%s: I/O error: %s\n' % (filename, msg)) |
46fb38ef9a91
add md5sum.py required by fix in previous changeset
Peter van Dijk <peter@dataloss.nl>
parents:
diff
changeset
|
36 sys.exit(1) |
46fb38ef9a91
add md5sum.py required by fix in previous changeset
Peter van Dijk <peter@dataloss.nl>
parents:
diff
changeset
|
37 sys.stdout.write('%s %s\n' % (m.hexdigest(), filename)) |
46fb38ef9a91
add md5sum.py required by fix in previous changeset
Peter van Dijk <peter@dataloss.nl>
parents:
diff
changeset
|
38 |
46fb38ef9a91
add md5sum.py required by fix in previous changeset
Peter van Dijk <peter@dataloss.nl>
parents:
diff
changeset
|
39 sys.exit(0) |