# HG changeset patch # User Augie Fackler # Date 1465531953 14400 # Node ID 0d83ad967bf81ba1a435e095f091aa4c2200b89c # Parent ae92c3eee88ec24089c014d7193cd710ffcd1271 cleanup: replace uses of util.(md5|sha1|sha256|sha512) with hashlib.\1 All versions of Python we support or hope to support make the hash functions available in the same way under the same name, so we may as well drop the util forwards. diff -r ae92c3eee88e -r 0d83ad967bf8 hgext/chgserver.py --- a/hgext/chgserver.py Fri Jun 10 00:25:07 2016 -0400 +++ b/hgext/chgserver.py Fri Jun 10 00:12:33 2016 -0400 @@ -43,6 +43,7 @@ import SocketServer import errno import gc +import hashlib import inspect import os import random @@ -76,7 +77,7 @@ def _hashlist(items): """return sha1 hexdigest for a list""" - return util.sha1(str(items)).hexdigest() + return hashlib.sha1(str(items)).hexdigest() # sensitive config sections affecting confighash _configsections = [ diff -r ae92c3eee88e -r 0d83ad967bf8 hgext/fsmonitor/__init__.py --- a/hgext/fsmonitor/__init__.py Fri Jun 10 00:25:07 2016 -0400 +++ b/hgext/fsmonitor/__init__.py Fri Jun 10 00:12:33 2016 -0400 @@ -91,6 +91,7 @@ from __future__ import absolute_import +import hashlib import os import stat import sys @@ -141,7 +142,7 @@ copy. """ - sha1 = util.sha1() + sha1 = hashlib.sha1() if util.safehasattr(ignore, 'includepat'): sha1.update(ignore.includepat) sha1.update('\0\0') diff -r ae92c3eee88e -r 0d83ad967bf8 hgext/largefiles/lfcommands.py --- a/hgext/largefiles/lfcommands.py Fri Jun 10 00:25:07 2016 -0400 +++ b/hgext/largefiles/lfcommands.py Fri Jun 10 00:12:33 2016 -0400 @@ -10,6 +10,7 @@ from __future__ import absolute_import import errno +import hashlib import os import shutil @@ -229,7 +230,7 @@ raise error.Abort(_('largefile %s becomes symlink') % f) # largefile was modified, update standins - m = util.sha1('') + m = hashlib.sha1('') m.update(ctx[f].data()) hash = m.hexdigest() if f not in lfiletohash or lfiletohash[f] != hash: diff -r ae92c3eee88e -r 0d83ad967bf8 hgext/largefiles/lfutil.py --- a/hgext/largefiles/lfutil.py Fri Jun 10 00:25:07 2016 -0400 +++ b/hgext/largefiles/lfutil.py Fri Jun 10 00:12:33 2016 -0400 @@ -10,6 +10,7 @@ from __future__ import absolute_import import copy +import hashlib import os import platform import stat @@ -359,7 +360,7 @@ def copyandhash(instream, outfile): '''Read bytes from instream (iterable) and write them to outfile, computing the SHA-1 hash of the data along the way. Return the hash.''' - hasher = util.sha1('') + hasher = hashlib.sha1('') for data in instream: hasher.update(data) outfile.write(data) @@ -371,7 +372,7 @@ def hashfile(file): if not os.path.exists(file): return '' - hasher = util.sha1('') + hasher = hashlib.sha1('') fd = open(file, 'rb') for data in util.filechunkiter(fd, 128 * 1024): hasher.update(data) @@ -400,7 +401,7 @@ def hexsha1(data): """hexsha1 returns the hex-encoded sha1 sum of the data in the file-like object data""" - h = util.sha1() + h = hashlib.sha1() for chunk in util.filechunkiter(data): h.update(chunk) return h.hexdigest() diff -r ae92c3eee88e -r 0d83ad967bf8 mercurial/exchange.py --- a/mercurial/exchange.py Fri Jun 10 00:25:07 2016 -0400 +++ b/mercurial/exchange.py Fri Jun 10 00:12:33 2016 -0400 @@ -8,6 +8,7 @@ from __future__ import absolute_import import errno +import hashlib from .i18n import _ from .node import ( @@ -1646,7 +1647,7 @@ Used by peer for unbundling. """ heads = repo.heads() - heads_hash = util.sha1(''.join(sorted(heads))).digest() + heads_hash = hashlib.sha1(''.join(sorted(heads))).digest() if not (their_heads == ['force'] or their_heads == heads or their_heads == ['hashed', heads_hash]): # someone else committed/pushed/unbundled while we diff -r ae92c3eee88e -r 0d83ad967bf8 mercurial/hg.py --- a/mercurial/hg.py Fri Jun 10 00:25:07 2016 -0400 +++ b/mercurial/hg.py Fri Jun 10 00:12:33 2016 -0400 @@ -9,6 +9,7 @@ from __future__ import absolute_import import errno +import hashlib import os import shutil @@ -480,7 +481,8 @@ ui.status(_('(not using pooled storage: ' 'unable to resolve identity of remote)\n')) elif sharenamemode == 'remote': - sharepath = os.path.join(sharepool, util.sha1(source).hexdigest()) + sharepath = os.path.join( + sharepool, hashlib.sha1(source).hexdigest()) else: raise error.Abort('unknown share naming mode: %s' % sharenamemode) diff -r ae92c3eee88e -r 0d83ad967bf8 mercurial/keepalive.py --- a/mercurial/keepalive.py Fri Jun 10 00:25:07 2016 -0400 +++ b/mercurial/keepalive.py Fri Jun 10 00:12:33 2016 -0400 @@ -110,6 +110,7 @@ from __future__ import absolute_import, print_function import errno +import hashlib import httplib import socket import sys @@ -624,8 +625,7 @@ keepalive_handler.close_all() def continuity(url): - from . import util - md5 = util.md5 + md5 = hashlib.md5 format = '%25s: %s' # first fetch the file with the normal http handler diff -r ae92c3eee88e -r 0d83ad967bf8 mercurial/localrepo.py --- a/mercurial/localrepo.py Fri Jun 10 00:25:07 2016 -0400 +++ b/mercurial/localrepo.py Fri Jun 10 00:12:33 2016 -0400 @@ -8,6 +8,7 @@ from __future__ import absolute_import import errno +import hashlib import inspect import os import random @@ -1013,7 +1014,7 @@ hint=_("run 'hg recover' to clean up transaction")) idbase = "%.40f#%f" % (random.random(), time.time()) - txnid = 'TXN:' + util.sha1(idbase).hexdigest() + txnid = 'TXN:' + hashlib.sha1(idbase).hexdigest() self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid) self._writejournal(desc) diff -r ae92c3eee88e -r 0d83ad967bf8 mercurial/merge.py --- a/mercurial/merge.py Fri Jun 10 00:25:07 2016 -0400 +++ b/mercurial/merge.py Fri Jun 10 00:12:33 2016 -0400 @@ -8,6 +8,7 @@ from __future__ import absolute_import import errno +import hashlib import os import shutil import struct @@ -408,7 +409,7 @@ if fcl.isabsent(): hash = nullhex else: - hash = util.sha1(fcl.path()).hexdigest() + hash = hashlib.sha1(fcl.path()).hexdigest() self._repo.vfs.write('merge/' + hash, fcl.data()) self._state[fd] = ['u', hash, fcl.path(), fca.path(), hex(fca.filenode()), diff -r ae92c3eee88e -r 0d83ad967bf8 mercurial/patch.py --- a/mercurial/patch.py Fri Jun 10 00:25:07 2016 -0400 +++ b/mercurial/patch.py Fri Jun 10 00:12:33 2016 -0400 @@ -12,6 +12,7 @@ import copy import email import errno +import hashlib import os import posixpath import re @@ -2412,7 +2413,7 @@ if not text: text = "" l = len(text) - s = util.sha1('blob %d\0' % l) + s = hashlib.sha1('blob %d\0' % l) s.update(text) return s.hexdigest() diff -r ae92c3eee88e -r 0d83ad967bf8 mercurial/repair.py --- a/mercurial/repair.py Fri Jun 10 00:25:07 2016 -0400 +++ b/mercurial/repair.py Fri Jun 10 00:12:33 2016 -0400 @@ -9,6 +9,7 @@ from __future__ import absolute_import import errno +import hashlib from .i18n import _ from .node import short @@ -35,7 +36,7 @@ # Include a hash of all the nodes in the filename for uniqueness allcommits = repo.set('%ln::%ln', bases, heads) allhashes = sorted(c.hex() for c in allcommits) - totalhash = util.sha1(''.join(allhashes)).hexdigest() + totalhash = hashlib.sha1(''.join(allhashes)).hexdigest() name = "%s/%s-%s-%s.hg" % (backupdir, short(node), totalhash[:8], suffix) comp = None diff -r ae92c3eee88e -r 0d83ad967bf8 mercurial/repoview.py --- a/mercurial/repoview.py Fri Jun 10 00:25:07 2016 -0400 +++ b/mercurial/repoview.py Fri Jun 10 00:12:33 2016 -0400 @@ -9,6 +9,7 @@ from __future__ import absolute_import import copy +import hashlib import heapq import struct @@ -18,7 +19,6 @@ obsolete, phases, tags as tagsmod, - util, ) def hideablerevs(repo): @@ -102,7 +102,7 @@ it to the cache. Upon reading we can easily validate by checking the hash against the stored one and discard the cache in case the hashes don't match. """ - h = util.sha1() + h = hashlib.sha1() h.update(''.join(repo.heads())) h.update(str(hash(frozenset(hideable)))) return h.digest() diff -r ae92c3eee88e -r 0d83ad967bf8 mercurial/scmutil.py --- a/mercurial/scmutil.py Fri Jun 10 00:25:07 2016 -0400 +++ b/mercurial/scmutil.py Fri Jun 10 00:12:33 2016 -0400 @@ -10,6 +10,7 @@ import contextlib import errno import glob +import hashlib import os import re import shutil @@ -224,7 +225,7 @@ key = None revs = sorted(r for r in cl.filteredrevs if r <= maxrev) if revs: - s = util.sha1() + s = hashlib.sha1() for rev in revs: s.update('%s;' % rev) key = s.digest() diff -r ae92c3eee88e -r 0d83ad967bf8 mercurial/similar.py --- a/mercurial/similar.py Fri Jun 10 00:25:07 2016 -0400 +++ b/mercurial/similar.py Fri Jun 10 00:12:33 2016 -0400 @@ -7,6 +7,8 @@ from __future__ import absolute_import +import hashlib + from .i18n import _ from . import ( bdiff, @@ -27,14 +29,14 @@ for i, fctx in enumerate(removed): repo.ui.progress(_('searching for exact renames'), i, total=numfiles, unit=_('files')) - h = util.sha1(fctx.data()).digest() + h = hashlib.sha1(fctx.data()).digest() hashes[h] = fctx # For each added file, see if it corresponds to a removed file. for i, fctx in enumerate(added): repo.ui.progress(_('searching for exact renames'), i + len(removed), total=numfiles, unit=_('files')) - h = util.sha1(fctx.data()).digest() + h = hashlib.sha1(fctx.data()).digest() if h in hashes: yield (hashes[h], fctx) diff -r ae92c3eee88e -r 0d83ad967bf8 mercurial/sslutil.py --- a/mercurial/sslutil.py Fri Jun 10 00:25:07 2016 -0400 +++ b/mercurial/sslutil.py Fri Jun 10 00:12:33 2016 -0400 @@ -9,6 +9,7 @@ from __future__ import absolute_import +import hashlib import os import ssl import sys @@ -388,9 +389,9 @@ # If a certificate fingerprint is pinned, use it and only it to # validate the remote cert. peerfingerprints = { - 'sha1': util.sha1(peercert).hexdigest(), - 'sha256': util.sha256(peercert).hexdigest(), - 'sha512': util.sha512(peercert).hexdigest(), + 'sha1': hashlib.sha1(peercert).hexdigest(), + 'sha256': hashlib.sha256(peercert).hexdigest(), + 'sha512': hashlib.sha512(peercert).hexdigest(), } def fmtfingerprint(s): diff -r ae92c3eee88e -r 0d83ad967bf8 mercurial/subrepo.py --- a/mercurial/subrepo.py Fri Jun 10 00:25:07 2016 -0400 +++ b/mercurial/subrepo.py Fri Jun 10 00:12:33 2016 -0400 @@ -9,6 +9,7 @@ import copy import errno +import hashlib import os import posixpath import re @@ -50,7 +51,7 @@ def _getstorehashcachename(remotepath): '''get a unique filename for the store hash cache of a remote repository''' - return util.sha1(_expandedabspath(remotepath)).hexdigest()[0:12] + return hashlib.sha1(_expandedabspath(remotepath)).hexdigest()[0:12] class SubrepoAbort(error.Abort): """Exception class used to avoid handling a subrepo error more than once""" @@ -659,7 +660,7 @@ yield '# %s\n' % _expandedabspath(remotepath) vfs = self._repo.vfs for relname in filelist: - filehash = util.sha1(vfs.tryread(relname)).hexdigest() + filehash = hashlib.sha1(vfs.tryread(relname)).hexdigest() yield '%s = %s\n' % (relname, filehash) @propertycache diff -r ae92c3eee88e -r 0d83ad967bf8 mercurial/wireproto.py --- a/mercurial/wireproto.py Fri Jun 10 00:25:07 2016 -0400 +++ b/mercurial/wireproto.py Fri Jun 10 00:12:33 2016 -0400 @@ -7,6 +7,7 @@ from __future__ import absolute_import +import hashlib import itertools import os import sys @@ -410,7 +411,7 @@ if heads != ['force'] and self.capable('unbundlehash'): heads = encodelist(['hashed', - util.sha1(''.join(sorted(heads))).digest()]) + hashlib.sha1(''.join(sorted(heads))).digest()]) else: heads = encodelist(heads)