Mercurial > public > mercurial-scm > hg
comparison tests/testlib/ext-sidedata.py @ 43134:75ad8af9c95e
upgrade: allow upgrade to repository using sidedata
Repository can now be migrated to support sidedata. More requirements and
migration will be needed to actual side-data usage. This is a step in that
direction.
To test the feature, we leverage the test extension. It make sure the `update`
part of the side-data migration actually works.
Differential Revision: https://phab.mercurial-scm.org/D6942
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sun, 06 Oct 2019 23:36:51 -0400 |
parents | 2372284d9457 |
children | d7dcc75a3eae |
comparison
equal
deleted
inserted
replaced
43133:3de4d13f22be | 43134:75ad8af9c95e |
---|---|
10 import hashlib | 10 import hashlib |
11 import struct | 11 import struct |
12 | 12 |
13 from mercurial import ( | 13 from mercurial import ( |
14 extensions, | 14 extensions, |
15 localrepo, | |
15 node, | 16 node, |
16 revlog, | 17 revlog, |
18 upgrade, | |
17 ) | 19 ) |
18 | 20 |
19 from mercurial.revlogutils import sidedata | 21 from mercurial.revlogutils import sidedata |
20 | 22 |
21 | 23 |
34 return orig(self, text, transaction, link, p1, p2, *args, **kwargs) | 36 return orig(self, text, transaction, link, p1, p2, *args, **kwargs) |
35 | 37 |
36 | 38 |
37 def wraprevision(orig, self, nodeorrev, *args, **kwargs): | 39 def wraprevision(orig, self, nodeorrev, *args, **kwargs): |
38 text = orig(self, nodeorrev, *args, **kwargs) | 40 text = orig(self, nodeorrev, *args, **kwargs) |
41 if getattr(self, 'sidedatanocheck', False): | |
42 return text | |
39 if nodeorrev != node.nullrev and nodeorrev != node.nullid: | 43 if nodeorrev != node.nullrev and nodeorrev != node.nullid: |
40 sd = self.sidedata(nodeorrev) | 44 sd = self.sidedata(nodeorrev) |
41 if len(text) != struct.unpack('>I', sd[sidedata.SD_TEST1])[0]: | 45 if len(text) != struct.unpack('>I', sd[sidedata.SD_TEST1])[0]: |
42 raise RuntimeError('text size mismatch') | 46 raise RuntimeError('text size mismatch') |
43 expected = sd[sidedata.SD_TEST2] | 47 expected = sd[sidedata.SD_TEST2] |
45 if got != expected: | 49 if got != expected: |
46 raise RuntimeError('sha256 mismatch') | 50 raise RuntimeError('sha256 mismatch') |
47 return text | 51 return text |
48 | 52 |
49 | 53 |
54 def wrapgetsidedatacompanion(orig, srcrepo, dstrepo): | |
55 sidedatacompanion = orig(srcrepo, dstrepo) | |
56 addedreqs = dstrepo.requirements - srcrepo.requirements | |
57 if localrepo.SIDEDATA_REQUIREMENT in addedreqs: | |
58 assert sidedatacompanion is None # deal with composition later | |
59 | |
60 def sidedatacompanion(revlog, rev): | |
61 update = {} | |
62 revlog.sidedatanocheck = True | |
63 try: | |
64 text = revlog.revision(rev) | |
65 finally: | |
66 del revlog.sidedatanocheck | |
67 ## let's store some arbitrary data just for testing | |
68 # text length | |
69 update[sidedata.SD_TEST1] = struct.pack('>I', len(text)) | |
70 # and sha2 hashes | |
71 sha256 = hashlib.sha256(text).digest() | |
72 update[sidedata.SD_TEST2] = struct.pack('>32s', sha256) | |
73 return False, (), update | |
74 | |
75 return sidedatacompanion | |
76 | |
77 | |
50 def extsetup(ui): | 78 def extsetup(ui): |
51 extensions.wrapfunction(revlog.revlog, 'addrevision', wrapaddrevision) | 79 extensions.wrapfunction(revlog.revlog, 'addrevision', wrapaddrevision) |
52 extensions.wrapfunction(revlog.revlog, 'revision', wraprevision) | 80 extensions.wrapfunction(revlog.revlog, 'revision', wraprevision) |
81 extensions.wrapfunction( | |
82 upgrade, 'getsidedatacompanion', wrapgetsidedatacompanion | |
83 ) |