comparison tests/testlib/ext-sidedata.py @ 46722:3d740058b467

sidedata: move to new sidedata storage in revlogv2 The current (experimental) sidedata system uses flagprocessors to signify the presence and store/retrieve sidedata from the raw revlog data. This proved to be quite fragile from an exchange perspective and a lot more complex than simply having a dedicated space in the new revlog format. This change does not handle exchange (ironically), so the test for amend - that uses a bundle - is broken. This functionality is split into the next patches. Differential Revision: https://phab.mercurial-scm.org/D9993
author Rapha?l Gom?s <rgomes@octobus.net>
date Mon, 18 Jan 2021 11:44:51 +0100
parents 59fa3890d40a
children ba8e508a8e69
comparison
equal deleted inserted replaced
46721:358737abeeef 46722:3d740058b467
38 sha256 = hashlib.sha256(text).digest() 38 sha256 = hashlib.sha256(text).digest()
39 sd[sidedata.SD_TEST2] = struct.pack('>32s', sha256) 39 sd[sidedata.SD_TEST2] = struct.pack('>32s', sha256)
40 return orig(self, text, transaction, link, p1, p2, *args, **kwargs) 40 return orig(self, text, transaction, link, p1, p2, *args, **kwargs)
41 41
42 42
43 def wraprevision(orig, self, nodeorrev, *args, **kwargs): 43 def wrap_revisiondata(orig, self, nodeorrev, *args, **kwargs):
44 text = orig(self, nodeorrev, *args, **kwargs) 44 text, sd = orig(self, nodeorrev, *args, **kwargs)
45 if getattr(self, 'sidedatanocheck', False): 45 if getattr(self, 'sidedatanocheck', False):
46 return text 46 return text, sd
47 if self.version & 0xFFFF != 2:
48 return text, sd
47 if nodeorrev != nullrev and nodeorrev != nullid: 49 if nodeorrev != nullrev and nodeorrev != nullid:
48 sd = self.sidedata(nodeorrev)
49 if len(text) != struct.unpack('>I', sd[sidedata.SD_TEST1])[0]: 50 if len(text) != struct.unpack('>I', sd[sidedata.SD_TEST1])[0]:
50 raise RuntimeError('text size mismatch') 51 raise RuntimeError('text size mismatch')
51 expected = sd[sidedata.SD_TEST2] 52 expected = sd[sidedata.SD_TEST2]
52 got = hashlib.sha256(text).digest() 53 got = hashlib.sha256(text).digest()
53 if got != expected: 54 if got != expected:
54 raise RuntimeError('sha256 mismatch') 55 raise RuntimeError('sha256 mismatch')
55 return text 56 return text, sd
56 57
57 58
58 def wrapgetsidedatacompanion(orig, srcrepo, dstrepo): 59 def wrapgetsidedatacompanion(orig, srcrepo, dstrepo):
59 sidedatacompanion = orig(srcrepo, dstrepo) 60 sidedatacompanion = orig(srcrepo, dstrepo)
60 addedreqs = dstrepo.requirements - srcrepo.requirements 61 addedreqs = dstrepo.requirements - srcrepo.requirements
79 return sidedatacompanion 80 return sidedatacompanion
80 81
81 82
82 def extsetup(ui): 83 def extsetup(ui):
83 extensions.wrapfunction(revlog.revlog, 'addrevision', wrapaddrevision) 84 extensions.wrapfunction(revlog.revlog, 'addrevision', wrapaddrevision)
84 extensions.wrapfunction(revlog.revlog, 'revision', wraprevision) 85 extensions.wrapfunction(revlog.revlog, '_revisiondata', wrap_revisiondata)
85 extensions.wrapfunction( 86 extensions.wrapfunction(
86 upgrade_engine, 'getsidedatacompanion', wrapgetsidedatacompanion 87 upgrade_engine, 'getsidedatacompanion', wrapgetsidedatacompanion
87 ) 88 )