Commit a61287a95dc by Augie Fackler

core: migrate uses of hashlib.sha1 to hashutil.sha1

Differential Revision: https://phab.mercurial-scm.org/D7849
parent 7126d8b8e0e
......@@ -41,7 +41,6 @@ Config
from __future__ import absolute_import
import hashlib
import inspect
import os
import re
......@@ -67,6 +66,7 @@ from . import (
)
from .utils import (
hashutil,
procutil,
stringutil,
)
......@@ -74,7 +74,7 @@ from .utils import (
def _hashlist(items):
"""return sha1 hexdigest for a list"""
return node.hex(hashlib.sha1(stringutil.pprint(items)).digest())
return node.hex(hashutil.sha1(stringutil.pprint(items)).digest())
# sensitive config sections affecting confighash
......
......@@ -8,7 +8,6 @@
from __future__ import absolute_import
import collections
import hashlib
from .i18n import _
from .node import (
......@@ -40,7 +39,10 @@ from . import (
wireprototypes,
)
from .interfaces import repository
from .utils import stringutil
from .utils import (
hashutil,
stringutil,
)
urlerr = util.urlerr
urlreq = util.urlreq
......@@ -2705,7 +2707,7 @@ def check_heads(repo, their_heads, context):
Used by peer for unbundling.
"""
heads = repo.heads()
heads_hash = hashlib.sha1(b''.join(sorted(heads))).digest()
heads_hash = hashutil.sha1(b''.join(sorted(heads))).digest()
if not (
their_heads == [b'force']
or their_heads == heads
......
......@@ -9,7 +9,6 @@
from __future__ import absolute_import
import errno
import hashlib
import os
import shutil
import stat
......@@ -48,7 +47,7 @@ from . import (
verify as verifymod,
vfs as vfsmod,
)
from .utils import hashutil
from .interfaces import repository as repositorymod
release = lock.release
......@@ -738,7 +737,7 @@ def clone(
)
elif sharenamemode == b'remote':
sharepath = os.path.join(
sharepool, node.hex(hashlib.sha1(source).digest())
sharepool, node.hex(hashutil.sha1(source).digest())
)
else:
raise error.Abort(
......
......@@ -8,7 +8,6 @@
from __future__ import absolute_import
import errno
import hashlib
import os
import random
import sys
......@@ -74,6 +73,7 @@ from .interfaces import (
)
from .utils import (
hashutil,
procutil,
stringutil,
)
......@@ -2007,7 +2007,7 @@ class localrepository(object):
)
idbase = b"%.40f#%f" % (random.random(), time.time())
ha = hex(hashlib.sha1(idbase).digest())
ha = hex(hashutil.sha1(idbase).digest())
txnid = b'TXN:' + ha
self.hook(b'pretxnopen', throw=True, txnname=desc, txnid=txnid)
......
......@@ -8,7 +8,6 @@
from __future__ import absolute_import
import errno
import hashlib
import shutil
import stat
import struct
......@@ -39,6 +38,7 @@ from . import (
util,
worker,
)
from .utils import hashutil
_pack = struct.pack
_unpack = struct.unpack
......@@ -512,7 +512,7 @@ class mergestate(object):
"""hash the path of a local file context for storage in the .hg/merge
directory."""
return hex(hashlib.sha1(path).digest())
return hex(hashutil.sha1(path).digest())
def add(self, fcl, fco, fca, fd):
"""add a new (potentially?) conflicting file the merge state
......
......@@ -70,7 +70,6 @@ comment associated with each format for details.
from __future__ import absolute_import
import errno
import hashlib
import struct
from .i18n import _
......@@ -85,7 +84,10 @@ from . import (
pycompat,
util,
)
from .utils import dateutil
from .utils import (
dateutil,
hashutil,
)
parsers = policy.importmod('parsers')
......@@ -1028,7 +1030,7 @@ def _computecontentdivergentset(repo):
def makefoldid(relation, user):
folddigest = hashlib.sha1(user)
folddigest = hashutil.sha1(user)
for p in relation[0] + relation[1]:
folddigest.update(b'%d' % p.rev())
folddigest.update(p.node())
......
......@@ -12,7 +12,6 @@ import collections
import contextlib
import copy
import errno
import hashlib
import os
import re
import shutil
......@@ -41,6 +40,7 @@ from . import (
)
from .utils import (
dateutil,
hashutil,
procutil,
stringutil,
)
......@@ -2943,7 +2943,7 @@ def trydiff(
if not text:
text = b""
l = len(text)
s = hashlib.sha1(b'blob %d\0' % l)
s = hashutil.sha1(b'blob %d\0' % l)
s.update(text)
return hex(s.digest())
......
......@@ -9,7 +9,6 @@
from __future__ import absolute_import
import errno
import hashlib
from .i18n import _
from .node import (
......@@ -29,7 +28,10 @@ from . import (
pycompat,
util,
)
from .utils import stringutil
from .utils import (
hashutil,
stringutil,
)
def backupbundle(
......@@ -45,7 +47,7 @@ def backupbundle(
# Include a hash of all the nodes in the filename for uniqueness
allcommits = repo.set(b'%ln::%ln', bases, heads)
allhashes = sorted(c.hex() for c in allcommits)
totalhash = hashlib.sha1(b''.join(allhashes)).digest()
totalhash = hashutil.sha1(b''.join(allhashes)).digest()
name = b"%s/%s-%s-%s.hg" % (
backupdir,
short(node),
......
......@@ -33,10 +33,10 @@ the concept.
from __future__ import absolute_import
import hashlib
import struct
from .. import error
from ..utils import hashutil
## sidedata type constant
# reserve a block for testing purposes.
......@@ -64,7 +64,7 @@ def sidedatawriteprocessor(rl, text, sidedata):
sidedata.sort()
rawtext = [SIDEDATA_HEADER.pack(len(sidedata))]
for key, value in sidedata:
digest = hashlib.sha1(value).digest()
digest = hashutil.sha1(value).digest()
rawtext.append(SIDEDATA_ENTRY.pack(key, len(value), digest))
for key, value in sidedata:
rawtext.append(value)
......@@ -85,7 +85,7 @@ def sidedatareadprocessor(rl, text):
# read the data associated with that entry
nextdataoffset = dataoffset + size
entrytext = text[dataoffset:nextdataoffset]
readdigest = hashlib.sha1(entrytext).digest()
readdigest = hashutil.sha1(entrytext).digest()
if storeddigest != readdigest:
raise error.SidedataHashError(key, storeddigest, readdigest)
sidedata[key] = entrytext
......
......@@ -9,7 +9,6 @@ from __future__ import absolute_import
import errno
import glob
import hashlib
import os
import posixpath
import re
......@@ -48,6 +47,7 @@ from . import (
)
from .utils import (
hashutil,
procutil,
stringutil,
)
......@@ -366,7 +366,7 @@ def filteredhash(repo, maxrev):
key = None
revs = sorted(r for r in cl.filteredrevs if r <= maxrev)
if revs:
s = hashlib.sha1()
s = hashutil.sha1()
for rev in revs:
s.update(b'%d;' % rev)
key = s.digest()
......
......@@ -7,7 +7,6 @@
from __future__ import absolute_import
import hashlib
import os
from .i18n import _
......@@ -24,6 +23,7 @@ from . import (
scmutil,
util,
)
from .utils import hashutil
# Whether sparse features are enabled. This variable is intended to be
# temporary to facilitate porting sparse to core. It should eventually be
......@@ -205,12 +205,12 @@ def configsignature(repo, includetemp=True):
tempsignature = b'0'
if signature is None or (includetemp and tempsignature is None):
signature = hex(hashlib.sha1(repo.vfs.tryread(b'sparse')).digest())
signature = hex(hashutil.sha1(repo.vfs.tryread(b'sparse')).digest())
cache[b'signature'] = signature
if includetemp:
raw = repo.vfs.tryread(b'tempsparse')
tempsignature = hex(hashlib.sha1(raw).digest())
tempsignature = hex(hashutil.sha1(raw).digest())
cache[b'tempsignature'] = tempsignature
return b'%s %s' % (signature, tempsignature)
......
......@@ -9,7 +9,6 @@ from __future__ import absolute_import
import errno
import functools
import hashlib
import os
import stat
......@@ -25,6 +24,7 @@ from . import (
util,
vfs as vfsmod,
)
from .utils import hashutil
parsers = policy.importmod('parsers')
# how much bytes should be read from fncache in one read
......@@ -273,7 +273,7 @@ _maxshortdirslen = 8 * (_dirprefixlen + 1) - 4
def _hashencode(path, dotencode):
digest = node.hex(hashlib.sha1(path).digest())
digest = node.hex(hashutil.sha1(path).digest())
le = lowerencode(path[5:]).split(b'/') # skips prefix 'data/' or 'meta/'
parts = _auxencode(le, dotencode)
basename = parts[-1]
......
......@@ -9,7 +9,6 @@ from __future__ import absolute_import
import copy
import errno
import hashlib
import os
import re
import stat
......@@ -37,6 +36,7 @@ from . import (
)
from .utils import (
dateutil,
hashutil,
procutil,
stringutil,
)
......@@ -61,7 +61,7 @@ def _expandedabspath(path):
def _getstorehashcachename(remotepath):
'''get a unique filename for the store hash cache of a remote repository'''
return node.hex(hashlib.sha1(_expandedabspath(remotepath)).digest())[0:12]
return node.hex(hashutil.sha1(_expandedabspath(remotepath)).digest())[0:12]
class SubrepoAbort(error.Abort):
......@@ -514,7 +514,7 @@ class hgsubrepo(abstractsubrepo):
yield b'# %s\n' % _expandedabspath(remotepath)
vfs = self._repo.vfs
for relname in filelist:
filehash = node.hex(hashlib.sha1(vfs.tryread(relname)).digest())
filehash = node.hex(hashutil.sha1(vfs.tryread(relname)).digest())
yield b'%s = %s\n' % (relname, filehash)
@propertycache
......
......@@ -53,6 +53,7 @@ from . import (
)
from .utils import (
compression,
hashutil,
procutil,
stringutil,
)
......@@ -197,7 +198,7 @@ def nouideprecwarn(msg, version, stacklevel=1):
DIGESTS = {
b'md5': hashlib.md5,
b'sha1': hashlib.sha1,
b'sha1': hashutil.sha1,
b'sha512': hashlib.sha512,
}
# List of digest types from strongest to weakest
......
......@@ -7,7 +7,6 @@
from __future__ import absolute_import
import hashlib
import re
import struct
......@@ -24,8 +23,9 @@ from .. import (
pycompat,
)
from ..interfaces import repository
from ..utils import hashutil
_nullhash = hashlib.sha1(nullid)
_nullhash = hashutil.sha1(nullid)
def hashrevisionsha1(text, p1, p2):
......@@ -48,7 +48,7 @@ def hashrevisionsha1(text, p1, p2):
else:
a = p2
b = p1
s = hashlib.sha1(a)
s = hashutil.sha1(a)
s.update(b)
s.update(text)
return s.digest()
......
......@@ -7,7 +7,6 @@
from __future__ import absolute_import
import hashlib
import sys
import weakref
......@@ -31,6 +30,7 @@ from .interfaces import (
repository,
util as interfaceutil,
)
from .utils import hashutil
urlreq = util.urlreq
......@@ -489,7 +489,7 @@ class wirepeer(repository.peer):
if heads != [b'force'] and self.capable(b'unbundlehash'):
heads = wireprototypes.encodelist(
[b'hashed', hashlib.sha1(b''.join(sorted(heads))).digest()]
[b'hashed', hashutil.sha1(b''.join(sorted(heads))).digest()]
)
else:
heads = wireprototypes.encodelist(heads)
......
......@@ -8,7 +8,6 @@ from __future__ import absolute_import
import collections
import contextlib
import hashlib
from .i18n import _
from .node import (
......@@ -31,6 +30,7 @@ from . import (
from .interfaces import util as interfaceutil
from .utils import (
cborutil,
hashutil,
stringutil,
)
......@@ -858,7 +858,7 @@ def makecommandcachekeyfn(command, localversion=None, allargs=False):
cacher.adjustcachekeystate(state)
hasher = hashlib.sha1()
hasher = hashutil.sha1()
for chunk in cborutil.streamencode(state):
hasher.update(chunk)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment