##// END OF EJS Templates
hgext: replace references to hashlib.sha1 with hashutil.sha1...
Augie Fackler -
r44519:2d49482d default
parent child Browse files
Show More
@@ -9,7 +9,6 b' from __future__ import absolute_import'
9
9
10 import collections
10 import collections
11 import contextlib
11 import contextlib
12 import hashlib
13 import os
12 import os
14
13
15 from mercurial.i18n import _
14 from mercurial.i18n import _
@@ -28,7 +27,10 b' from mercurial import ('
28 scmutil,
27 scmutil,
29 util,
28 util,
30 )
29 )
31 from mercurial.utils import stringutil
30 from mercurial.utils import (
31 hashutil,
32 stringutil,
33 )
32
34
33 from . import (
35 from . import (
34 error as faerror,
36 error as faerror,
@@ -148,7 +150,7 b' def hashdiffopts(diffopts):'
148 diffoptstr = stringutil.pprint(
150 diffoptstr = stringutil.pprint(
149 sorted((k, getattr(diffopts, k)) for k in mdiff.diffopts.defaults)
151 sorted((k, getattr(diffopts, k)) for k in mdiff.diffopts.defaults)
150 )
152 )
151 return node.hex(hashlib.sha1(diffoptstr).digest())[:6]
153 return node.hex(hashutil.sha1(diffoptstr).digest())[:6]
152
154
153
155
154 _defaultdiffopthash = hashdiffopts(mdiff.defaultopts)
156 _defaultdiffopthash = hashdiffopts(mdiff.defaultopts)
@@ -108,7 +108,6 b' created.'
108 from __future__ import absolute_import
108 from __future__ import absolute_import
109
109
110 import codecs
110 import codecs
111 import hashlib
112 import os
111 import os
113 import stat
112 import stat
114 import sys
113 import sys
@@ -132,7 +131,10 b' from mercurial import ('
132 util,
131 util,
133 )
132 )
134 from mercurial import match as matchmod
133 from mercurial import match as matchmod
135 from mercurial.utils import stringutil
134 from mercurial.utils import (
135 hashutil,
136 stringutil,
137 )
136
138
137 from . import (
139 from . import (
138 pywatchman,
140 pywatchman,
@@ -235,7 +237,7 b' def _hashignore(ignore):'
235 copy.
237 copy.
236
238
237 """
239 """
238 sha1 = hashlib.sha1()
240 sha1 = hashutil.sha1()
239 sha1.update(pycompat.byterepr(ignore))
241 sha1.update(pycompat.byterepr(ignore))
240 return pycompat.sysbytes(sha1.hexdigest())
242 return pycompat.sysbytes(sha1.hexdigest())
241
243
@@ -6,7 +6,6 b''
6 from __future__ import absolute_import
6 from __future__ import absolute_import
7
7
8 import abc
8 import abc
9 import hashlib
10 import os
9 import os
11 import subprocess
10 import subprocess
12 import tempfile
11 import tempfile
@@ -16,7 +15,10 b' from mercurial import ('
16 node,
15 node,
17 pycompat,
16 pycompat,
18 )
17 )
19 from mercurial.utils import procutil
18 from mercurial.utils import (
19 hashutil,
20 procutil,
21 )
20
22
21 NamedTemporaryFile = tempfile.NamedTemporaryFile
23 NamedTemporaryFile = tempfile.NamedTemporaryFile
22
24
@@ -87,7 +89,7 b' class filebundlestore(object):'
87 return os.path.join(self._dirpath(filename), filename)
89 return os.path.join(self._dirpath(filename), filename)
88
90
89 def write(self, data):
91 def write(self, data):
90 filename = node.hex(hashlib.sha1(data).digest())
92 filename = node.hex(hashutil.sha1(data).digest())
91 dirpath = self._dirpath(filename)
93 dirpath = self._dirpath(filename)
92
94
93 if not os.path.exists(dirpath):
95 if not os.path.exists(dirpath):
@@ -10,7 +10,6 b''
10 from __future__ import absolute_import
10 from __future__ import absolute_import
11
11
12 import errno
12 import errno
13 import hashlib
14 import os
13 import os
15 import shutil
14 import shutil
16
15
@@ -29,6 +28,7 b' from mercurial import ('
29 scmutil,
28 scmutil,
30 util,
29 util,
31 )
30 )
31 from mercurial.utils import hashutil
32
32
33 from ..convert import (
33 from ..convert import (
34 convcmd,
34 convcmd,
@@ -273,7 +273,7 b' def _lfconvert_addchangeset('
273 )
273 )
274
274
275 # largefile was modified, update standins
275 # largefile was modified, update standins
276 m = hashlib.sha1(b'')
276 m = hashutil.sha1(b'')
277 m.update(ctx[f].data())
277 m.update(ctx[f].data())
278 hash = node.hex(m.digest())
278 hash = node.hex(m.digest())
279 if f not in lfiletohash or lfiletohash[f] != hash:
279 if f not in lfiletohash or lfiletohash[f] != hash:
@@ -11,7 +11,6 b' from __future__ import absolute_import'
11
11
12 import contextlib
12 import contextlib
13 import copy
13 import copy
14 import hashlib
15 import os
14 import os
16 import stat
15 import stat
17
16
@@ -32,6 +31,7 b' from mercurial import ('
32 util,
31 util,
33 vfs as vfsmod,
32 vfs as vfsmod,
34 )
33 )
34 from mercurial.utils import hashutil
35
35
36 shortname = b'.hglf'
36 shortname = b'.hglf'
37 shortnameslash = shortname + b'/'
37 shortnameslash = shortname + b'/'
@@ -432,7 +432,7 b' def writestandin(repo, standin, hash, ex'
432 def copyandhash(instream, outfile):
432 def copyandhash(instream, outfile):
433 '''Read bytes from instream (iterable) and write them to outfile,
433 '''Read bytes from instream (iterable) and write them to outfile,
434 computing the SHA-1 hash of the data along the way. Return the hash.'''
434 computing the SHA-1 hash of the data along the way. Return the hash.'''
435 hasher = hashlib.sha1(b'')
435 hasher = hashutil.sha1(b'')
436 for data in instream:
436 for data in instream:
437 hasher.update(data)
437 hasher.update(data)
438 outfile.write(data)
438 outfile.write(data)
@@ -472,7 +472,7 b' def urljoin(first, second, *arg):'
472 def hexsha1(fileobj):
472 def hexsha1(fileobj):
473 """hexsha1 returns the hex-encoded sha1 sum of the data in the file-like
473 """hexsha1 returns the hex-encoded sha1 sum of the data in the file-like
474 object data"""
474 object data"""
475 h = hashlib.sha1()
475 h = hashutil.sha1()
476 for chunk in util.filechunkiter(fileobj):
476 for chunk in util.filechunkiter(fileobj):
477 h.update(chunk)
477 h.update(chunk)
478 return hex(h.digest())
478 return hex(h.digest())
@@ -2,7 +2,6 b' from __future__ import absolute_import'
2
2
3 import collections
3 import collections
4 import errno
4 import errno
5 import hashlib
6 import mmap
5 import mmap
7 import os
6 import os
8 import struct
7 import struct
@@ -20,6 +19,7 b' from mercurial import ('
20 util,
19 util,
21 vfs as vfsmod,
20 vfs as vfsmod,
22 )
21 )
22 from mercurial.utils import hashutil
23 from . import shallowutil
23 from . import shallowutil
24
24
25 osutil = policy.importmod('osutil')
25 osutil = policy.importmod('osutil')
@@ -392,7 +392,7 b' class mutablebasepack(versionmixin):'
392 )
392 )
393 self.packfp = os.fdopen(self.packfp, 'wb+')
393 self.packfp = os.fdopen(self.packfp, 'wb+')
394 self.idxfp = os.fdopen(self.idxfp, 'wb+')
394 self.idxfp = os.fdopen(self.idxfp, 'wb+')
395 self.sha = hashlib.sha1()
395 self.sha = hashutil.sha1()
396 self._closed = False
396 self._closed = False
397
397
398 # The opener provides no way of doing permission fixup on files created
398 # The opener provides no way of doing permission fixup on files created
@@ -1,7 +1,6 b''
1 from __future__ import absolute_import
1 from __future__ import absolute_import
2
2
3 import errno
3 import errno
4 import hashlib
5 import os
4 import os
6 import shutil
5 import shutil
7 import stat
6 import stat
@@ -15,6 +14,7 b' from mercurial import ('
15 pycompat,
14 pycompat,
16 util,
15 util,
17 )
16 )
17 from mercurial.utils import hashutil
18 from . import (
18 from . import (
19 constants,
19 constants,
20 shallowutil,
20 shallowutil,
@@ -166,7 +166,7 b' class basestore(object):'
166
166
167 # Start with a full manifest, since it'll cover the majority of files
167 # Start with a full manifest, since it'll cover the majority of files
168 for filename in self.repo[b'tip'].manifest():
168 for filename in self.repo[b'tip'].manifest():
169 sha = hashlib.sha1(filename).digest()
169 sha = hashutil.sha1(filename).digest()
170 if sha in missingfilename:
170 if sha in missingfilename:
171 filenames[filename] = sha
171 filenames[filename] = sha
172 missingfilename.discard(sha)
172 missingfilename.discard(sha)
@@ -178,7 +178,7 b' class basestore(object):'
178 break
178 break
179 files = cl.readfiles(cl.node(rev))
179 files = cl.readfiles(cl.node(rev))
180 for filename in files:
180 for filename in files:
181 sha = hashlib.sha1(filename).digest()
181 sha = hashutil.sha1(filename).digest()
182 if sha in missingfilename:
182 if sha in missingfilename:
183 filenames[filename] = sha
183 filenames[filename] = sha
184 missingfilename.discard(sha)
184 missingfilename.discard(sha)
@@ -6,7 +6,6 b''
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7 from __future__ import absolute_import
7 from __future__ import absolute_import
8
8
9 import hashlib
10 import os
9 import os
11 import zlib
10 import zlib
12
11
@@ -21,6 +20,7 b' from mercurial import ('
21 pycompat,
20 pycompat,
22 revlog,
21 revlog,
23 )
22 )
23 from mercurial.utils import hashutil
24 from . import (
24 from . import (
25 constants,
25 constants,
26 datapack,
26 datapack,
@@ -61,7 +61,7 b' def debugremotefilelog(ui, path, **opts)'
61
61
62 def buildtemprevlog(repo, file):
62 def buildtemprevlog(repo, file):
63 # get filename key
63 # get filename key
64 filekey = nodemod.hex(hashlib.sha1(file).digest())
64 filekey = nodemod.hex(hashutil.sha1(file).digest())
65 filedir = os.path.join(repo.path, b'store/data', filekey)
65 filedir = os.path.join(repo.path, b'store/data', filekey)
66
66
67 # sort all entries based on linkrev
67 # sort all entries based on linkrev
@@ -421,7 +421,7 b' def dumpdeltachain(ui, deltachain, **opt'
421 % (
421 % (
422 hashformatter(node),
422 hashformatter(node),
423 hashformatter(deltabasenode),
423 hashformatter(deltabasenode),
424 nodemod.hex(hashlib.sha1(delta).digest()),
424 nodemod.hex(hashutil.sha1(delta).digest()),
425 len(delta),
425 len(delta),
426 )
426 )
427 )
427 )
@@ -7,7 +7,6 b''
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 import hashlib
11 import io
10 import io
12 import os
11 import os
13 import threading
12 import threading
@@ -25,7 +24,10 b' from mercurial import ('
25 util,
24 util,
26 wireprotov1peer,
25 wireprotov1peer,
27 )
26 )
28 from mercurial.utils import procutil
27 from mercurial.utils import (
28 hashutil,
29 procutil,
30 )
29
31
30 from . import (
32 from . import (
31 constants,
33 constants,
@@ -45,12 +47,12 b' fetchmisses = 0'
45
47
46
48
47 def getcachekey(reponame, file, id):
49 def getcachekey(reponame, file, id):
48 pathhash = node.hex(hashlib.sha1(file).digest())
50 pathhash = node.hex(hashutil.sha1(file).digest())
49 return os.path.join(reponame, pathhash[:2], pathhash[2:], id)
51 return os.path.join(reponame, pathhash[:2], pathhash[2:], id)
50
52
51
53
52 def getlocalkey(file, id):
54 def getlocalkey(file, id):
53 pathhash = node.hex(hashlib.sha1(file).digest())
55 pathhash = node.hex(hashutil.sha1(file).digest())
54 return os.path.join(pathhash, id)
56 return os.path.join(pathhash, id)
55
57
56
58
@@ -1,6 +1,5 b''
1 from __future__ import absolute_import
1 from __future__ import absolute_import
2
2
3 import hashlib
4 import struct
3 import struct
5
4
6 from mercurial.node import hex, nullid
5 from mercurial.node import hex, nullid
@@ -8,6 +7,7 b' from mercurial import ('
8 pycompat,
7 pycompat,
9 util,
8 util,
10 )
9 )
10 from mercurial.utils import hashutil
11 from . import (
11 from . import (
12 basepack,
12 basepack,
13 constants,
13 constants,
@@ -197,7 +197,7 b' class historypack(basepack.basepack):'
197
197
198 def _findsection(self, name):
198 def _findsection(self, name):
199 params = self.params
199 params = self.params
200 namehash = hashlib.sha1(name).digest()
200 namehash = hashutil.sha1(name).digest()
201 fanoutkey = struct.unpack(
201 fanoutkey = struct.unpack(
202 params.fanoutstruct, namehash[: params.fanoutprefix]
202 params.fanoutstruct, namehash[: params.fanoutprefix]
203 )[0]
203 )[0]
@@ -499,7 +499,7 b' class mutablehistorypack(basepack.mutabl'
499
499
500 # Record metadata for the index
500 # Record metadata for the index
501 self.files[filename] = (sectionstart, sectionlen)
501 self.files[filename] = (sectionstart, sectionlen)
502 node = hashlib.sha1(filename).digest()
502 node = hashutil.sha1(filename).digest()
503 self.entries[node] = node
503 self.entries[node] = node
504
504
505 def close(self, ledger=None):
505 def close(self, ledger=None):
@@ -517,7 +517,7 b' class mutablehistorypack(basepack.mutabl'
517 nodeindexlength = self.NODEINDEXENTRYLENGTH
517 nodeindexlength = self.NODEINDEXENTRYLENGTH
518
518
519 files = (
519 files = (
520 (hashlib.sha1(filename).digest(), filename, offset, size)
520 (hashutil.sha1(filename).digest(), filename, offset, size)
521 for filename, (offset, size) in pycompat.iteritems(self.files)
521 for filename, (offset, size) in pycompat.iteritems(self.files)
522 )
522 )
523 files = sorted(files)
523 files = sorted(files)
@@ -8,7 +8,6 b' from __future__ import absolute_import'
8
8
9 import collections
9 import collections
10 import errno
10 import errno
11 import hashlib
12 import os
11 import os
13 import stat
12 import stat
14 import struct
13 import struct
@@ -24,6 +23,7 b' from mercurial import ('
24 util,
23 util,
25 )
24 )
26 from mercurial.utils import (
25 from mercurial.utils import (
26 hashutil,
27 storageutil,
27 storageutil,
28 stringutil,
28 stringutil,
29 )
29 )
@@ -39,12 +39,12 b' def isenabled(repo):'
39
39
40
40
41 def getcachekey(reponame, file, id):
41 def getcachekey(reponame, file, id):
42 pathhash = node.hex(hashlib.sha1(file).digest())
42 pathhash = node.hex(hashutil.sha1(file).digest())
43 return os.path.join(reponame, pathhash[:2], pathhash[2:], id)
43 return os.path.join(reponame, pathhash[:2], pathhash[2:], id)
44
44
45
45
46 def getlocalkey(file, id):
46 def getlocalkey(file, id):
47 pathhash = node.hex(hashlib.sha1(file).digest())
47 pathhash = node.hex(hashutil.sha1(file).digest())
48 return os.path.join(pathhash, id)
48 return os.path.join(pathhash, id)
49
49
50
50
@@ -45,7 +45,6 b' option to ``sqlite`` to enable new repos'
45
45
46 from __future__ import absolute_import
46 from __future__ import absolute_import
47
47
48 import hashlib
49 import sqlite3
48 import sqlite3
50 import struct
49 import struct
51 import threading
50 import threading
@@ -75,7 +74,10 b' from mercurial.interfaces import ('
75 repository,
74 repository,
76 util as interfaceutil,
75 util as interfaceutil,
77 )
76 )
78 from mercurial.utils import storageutil
77 from mercurial.utils import (
78 hashutil,
79 storageutil,
80 )
79
81
80 try:
82 try:
81 from mercurial import zstd
83 from mercurial import zstd
@@ -807,7 +809,7 b' class sqlitefilestore(object):'
807 self._db, pathid, node, {}, {-1: None}, zstddctx=self._dctx
809 self._db, pathid, node, {}, {-1: None}, zstddctx=self._dctx
808 )
810 )
809
811
810 deltahash = hashlib.sha1(fulltext).digest()
812 deltahash = hashutil.sha1(fulltext).digest()
811
813
812 if self._compengine == b'zstd':
814 if self._compengine == b'zstd':
813 deltablob = self._cctx.compress(fulltext)
815 deltablob = self._cctx.compress(fulltext)
@@ -837,7 +839,7 b' class sqlitefilestore(object):'
837
839
838 # Now create the tombstone delta and replace the delta on the censored
840 # Now create the tombstone delta and replace the delta on the censored
839 # node.
841 # node.
840 deltahash = hashlib.sha1(tombstone).digest()
842 deltahash = hashutil.sha1(tombstone).digest()
841 tombstonedeltaid = insertdelta(
843 tombstonedeltaid = insertdelta(
842 self._db, COMPRESSION_NONE, deltahash, tombstone
844 self._db, COMPRESSION_NONE, deltahash, tombstone
843 )
845 )
@@ -1004,7 +1006,7 b' class sqlitefilestore(object):'
1004 # us to de-duplicate. The table is configured to ignore conflicts
1006 # us to de-duplicate. The table is configured to ignore conflicts
1005 # and it is faster to just insert and silently noop than to look
1007 # and it is faster to just insert and silently noop than to look
1006 # first.
1008 # first.
1007 deltahash = hashlib.sha1(delta).digest()
1009 deltahash = hashutil.sha1(delta).digest()
1008
1010
1009 if self._compengine == b'zstd':
1011 if self._compengine == b'zstd':
1010 deltablob = self._cctx.compress(delta)
1012 deltablob = self._cctx.compress(delta)
General Comments 0
You need to be logged in to leave comments. Login now