Patchwork [1,of,5] util: drop Python 2.4 compat by directly importing md5 and sha1

login
register
mail settings
Submitter Siddharth Agarwal
Date Nov. 2, 2015, 8:26 p.m.
Message ID <ff468ef482c26894af3c.1446495990@dev6666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/11262/
State Accepted
Headers show

Comments

Siddharth Agarwal - Nov. 2, 2015, 8:26 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1445727376 25200
#      Sat Oct 24 15:56:16 2015 -0700
# Branch stable
# Node ID ff468ef482c26894af3c7d9b30001d3167db04bc
# Parent  47dd34f2e7272be9e3b2a5a83cd0d20be44293f4
util: drop Python 2.4 compat by directly importing md5 and sha1

There's been a fair amount of cruft here over the years, which we can all
just get rid of now.

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -91,39 +91,7 @@  username = platform.username
 def safehasattr(thing, attr):
     return getattr(thing, attr, _notset) is not _notset
 
-def sha1(s=''):
-    '''
-    Low-overhead wrapper around Python's SHA support
-
-    >>> f = _fastsha1
-    >>> a = sha1()
-    >>> a = f()
-    >>> a.hexdigest()
-    'da39a3ee5e6b4b0d3255bfef95601890afd80709'
-    '''
-
-    return _fastsha1(s)
-
-def _fastsha1(s=''):
-    # This function will import sha1 from hashlib or sha (whichever is
-    # available) and overwrite itself with it on the first call.
-    # Subsequent calls will go directly to the imported function.
-    if sys.version_info >= (2, 5):
-        from hashlib import sha1 as _sha1
-    else:
-        from sha import sha as _sha1
-    global _fastsha1, sha1
-    _fastsha1 = sha1 = _sha1
-    return _sha1(s)
-
-def md5(s=''):
-    try:
-        from hashlib import md5 as _md5
-    except ImportError:
-        from md5 import md5 as _md5
-    global md5
-    md5 = _md5
-    return _md5(s)
+from hashlib import md5, sha1
 
 DIGESTS = {
     'md5': md5,