# HG changeset patch # User Gregory Szorc # Date 2015-12-13 04:30:37 # Node ID 7f5a0bd4c9aa6892f78997ad00aea4477a58b995 # Parent c2effd1ecebff8c3f154edfed7f1c90ce044283a util: make hashlib import unconditional hashlib was added in Python 2.5. As far as I can tell, SHA-512 is always available in 2.6+. So move the hashlib import to the top of the file and remove the one-off handling of SHA-512. diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -23,12 +23,17 @@ import imp, socket, urllib import gc import bz2 import zlib +import hashlib if os.name == 'nt': import windows as platform else: import posix as platform +md5 = hashlib.md5 +sha1 = hashlib.sha1 +sha512 = hashlib.sha512 + cachestat = platform.cachestat checkexec = platform.checkexec checklink = platform.checklink @@ -95,23 +100,13 @@ os.stat_float_times(False) def safehasattr(thing, attr): return getattr(thing, attr, _notset) is not _notset -from hashlib import md5, sha1 - DIGESTS = { 'md5': md5, 'sha1': sha1, + 'sha512': sha512, } # List of digest types from strongest to weakest -DIGESTS_BY_STRENGTH = ['sha1', 'md5'] - -try: - import hashlib - DIGESTS.update({ - 'sha512': hashlib.sha512, - }) - DIGESTS_BY_STRENGTH.insert(0, 'sha512') -except ImportError: - pass +DIGESTS_BY_STRENGTH = ['sha512', 'sha1', 'md5'] for k in DIGESTS_BY_STRENGTH: assert k in DIGESTS