Mercurial > hg
comparison tests/testlib/ext-sidedata.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 03e769278ef3 |
children | 75ad8af9c95e |
comparison
equal
deleted
inserted
replaced
43075:57875cf423c9 | 43076:2372284d9457 |
---|---|
14 extensions, | 14 extensions, |
15 node, | 15 node, |
16 revlog, | 16 revlog, |
17 ) | 17 ) |
18 | 18 |
19 from mercurial.revlogutils import ( | 19 from mercurial.revlogutils import sidedata |
20 sidedata, | |
21 ) | |
22 | 20 |
23 def wrapaddrevision(orig, self, text, transaction, link, p1, p2, *args, | 21 |
24 **kwargs): | 22 def wrapaddrevision( |
23 orig, self, text, transaction, link, p1, p2, *args, **kwargs | |
24 ): | |
25 if kwargs.get('sidedata') is None: | 25 if kwargs.get('sidedata') is None: |
26 kwargs['sidedata'] = {} | 26 kwargs['sidedata'] = {} |
27 sd = kwargs['sidedata'] | 27 sd = kwargs['sidedata'] |
28 ## let's store some arbitrary data just for testing | 28 ## let's store some arbitrary data just for testing |
29 # text length | 29 # text length |
30 sd[sidedata.SD_TEST1] = struct.pack('>I', len(text)) | 30 sd[sidedata.SD_TEST1] = struct.pack('>I', len(text)) |
31 # and sha2 hashes | 31 # and sha2 hashes |
32 sha256 = hashlib.sha256(text).digest() | 32 sha256 = hashlib.sha256(text).digest() |
33 sd[sidedata.SD_TEST2] = struct.pack('>32s', sha256) | 33 sd[sidedata.SD_TEST2] = struct.pack('>32s', sha256) |
34 return orig(self, text, transaction, link, p1, p2, *args, **kwargs) | 34 return orig(self, text, transaction, link, p1, p2, *args, **kwargs) |
35 | |
35 | 36 |
36 def wraprevision(orig, self, nodeorrev, *args, **kwargs): | 37 def wraprevision(orig, self, nodeorrev, *args, **kwargs): |
37 text = orig(self, nodeorrev, *args, **kwargs) | 38 text = orig(self, nodeorrev, *args, **kwargs) |
38 if nodeorrev != node.nullrev and nodeorrev != node.nullid: | 39 if nodeorrev != node.nullrev and nodeorrev != node.nullid: |
39 sd = self.sidedata(nodeorrev) | 40 sd = self.sidedata(nodeorrev) |
43 got = hashlib.sha256(text).digest() | 44 got = hashlib.sha256(text).digest() |
44 if got != expected: | 45 if got != expected: |
45 raise RuntimeError('sha256 mismatch') | 46 raise RuntimeError('sha256 mismatch') |
46 return text | 47 return text |
47 | 48 |
49 | |
48 def extsetup(ui): | 50 def extsetup(ui): |
49 extensions.wrapfunction(revlog.revlog, 'addrevision', wrapaddrevision) | 51 extensions.wrapfunction(revlog.revlog, 'addrevision', wrapaddrevision) |
50 extensions.wrapfunction(revlog.revlog, 'revision', wraprevision) | 52 extensions.wrapfunction(revlog.revlog, 'revision', wraprevision) |