##// END OF EJS Templates
sidedata: use revlogv2 requirement in the test helper...
marmoute -
r47998:8505d239 default
parent child Browse files
Show More
@@ -1,105 +1,105
1 # ext-sidedata.py - small extension to test the sidedata logic
1 # ext-sidedata.py - small extension to test the sidedata logic
2 #
2 #
3 # Copyright 2019 Pierre-Yves David <pierre-yves.david@octobus.net>
3 # Copyright 2019 Pierre-Yves David <pierre-yves.david@octobus.net>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 import hashlib
10 import hashlib
11 import struct
11 import struct
12
12
13 from mercurial.node import nullrev
13 from mercurial.node import nullrev
14 from mercurial import (
14 from mercurial import (
15 extensions,
15 extensions,
16 requirements,
16 requirements,
17 revlog,
17 revlog,
18 )
18 )
19
19
20 from mercurial.upgrade_utils import engine as upgrade_engine
20 from mercurial.upgrade_utils import engine as upgrade_engine
21
21
22 from mercurial.revlogutils import constants
22 from mercurial.revlogutils import constants
23 from mercurial.revlogutils import sidedata
23 from mercurial.revlogutils import sidedata
24
24
25
25
26 def wrapaddrevision(
26 def wrapaddrevision(
27 orig, self, text, transaction, link, p1, p2, *args, **kwargs
27 orig, self, text, transaction, link, p1, p2, *args, **kwargs
28 ):
28 ):
29 if kwargs.get('sidedata') is None:
29 if kwargs.get('sidedata') is None:
30 kwargs['sidedata'] = {}
30 kwargs['sidedata'] = {}
31 sd = kwargs['sidedata']
31 sd = kwargs['sidedata']
32 ## let's store some arbitrary data just for testing
32 ## let's store some arbitrary data just for testing
33 # text length
33 # text length
34 sd[sidedata.SD_TEST1] = struct.pack('>I', len(text))
34 sd[sidedata.SD_TEST1] = struct.pack('>I', len(text))
35 # and sha2 hashes
35 # and sha2 hashes
36 sha256 = hashlib.sha256(text).digest()
36 sha256 = hashlib.sha256(text).digest()
37 sd[sidedata.SD_TEST2] = struct.pack('>32s', sha256)
37 sd[sidedata.SD_TEST2] = struct.pack('>32s', sha256)
38 return orig(self, text, transaction, link, p1, p2, *args, **kwargs)
38 return orig(self, text, transaction, link, p1, p2, *args, **kwargs)
39
39
40
40
41 def wrap_revisiondata(orig, self, nodeorrev, *args, **kwargs):
41 def wrap_revisiondata(orig, self, nodeorrev, *args, **kwargs):
42 text, sd = orig(self, nodeorrev, *args, **kwargs)
42 text, sd = orig(self, nodeorrev, *args, **kwargs)
43 if getattr(self, 'sidedatanocheck', False):
43 if getattr(self, 'sidedatanocheck', False):
44 return text, sd
44 return text, sd
45 if self.hassidedata:
45 if self.hassidedata:
46 return text, sd
46 return text, sd
47 if nodeorrev != nullrev and nodeorrev != self.nullid:
47 if nodeorrev != nullrev and nodeorrev != self.nullid:
48 cat1 = sd.get(sidedata.SD_TEST1)
48 cat1 = sd.get(sidedata.SD_TEST1)
49 if cat1 is not None and len(text) != struct.unpack('>I', cat1)[0]:
49 if cat1 is not None and len(text) != struct.unpack('>I', cat1)[0]:
50 raise RuntimeError('text size mismatch')
50 raise RuntimeError('text size mismatch')
51 expected = sd.get(sidedata.SD_TEST2)
51 expected = sd.get(sidedata.SD_TEST2)
52 got = hashlib.sha256(text).digest()
52 got = hashlib.sha256(text).digest()
53 if expected is not None and got != expected:
53 if expected is not None and got != expected:
54 raise RuntimeError('sha256 mismatch')
54 raise RuntimeError('sha256 mismatch')
55 return text, sd
55 return text, sd
56
56
57
57
58 def wrapget_sidedata_helpers(orig, srcrepo, dstrepo):
58 def wrapget_sidedata_helpers(orig, srcrepo, dstrepo):
59 repo, computers, removers = orig(srcrepo, dstrepo)
59 repo, computers, removers = orig(srcrepo, dstrepo)
60 assert not computers and not removers # deal with composition later
60 assert not computers and not removers # deal with composition later
61 addedreqs = dstrepo.requirements - srcrepo.requirements
61 addedreqs = dstrepo.requirements - srcrepo.requirements
62
62
63 if requirements.SIDEDATA_REQUIREMENT in addedreqs:
63 if requirements.REVLOGV2_REQUIREMENT in addedreqs:
64
64
65 def computer(repo, revlog, rev, old_sidedata):
65 def computer(repo, revlog, rev, old_sidedata):
66 assert not old_sidedata # not supported yet
66 assert not old_sidedata # not supported yet
67 update = {}
67 update = {}
68 revlog.sidedatanocheck = True
68 revlog.sidedatanocheck = True
69 try:
69 try:
70 text = revlog.revision(rev)
70 text = revlog.revision(rev)
71 finally:
71 finally:
72 del revlog.sidedatanocheck
72 del revlog.sidedatanocheck
73 ## let's store some arbitrary data just for testing
73 ## let's store some arbitrary data just for testing
74 # text length
74 # text length
75 update[sidedata.SD_TEST1] = struct.pack('>I', len(text))
75 update[sidedata.SD_TEST1] = struct.pack('>I', len(text))
76 # and sha2 hashes
76 # and sha2 hashes
77 sha256 = hashlib.sha256(text).digest()
77 sha256 = hashlib.sha256(text).digest()
78 update[sidedata.SD_TEST2] = struct.pack('>32s', sha256)
78 update[sidedata.SD_TEST2] = struct.pack('>32s', sha256)
79 return update, (0, 0)
79 return update, (0, 0)
80
80
81 srcrepo.register_sidedata_computer(
81 srcrepo.register_sidedata_computer(
82 constants.KIND_CHANGELOG,
82 constants.KIND_CHANGELOG,
83 b"whatever",
83 b"whatever",
84 (sidedata.SD_TEST1, sidedata.SD_TEST2),
84 (sidedata.SD_TEST1, sidedata.SD_TEST2),
85 computer,
85 computer,
86 0,
86 0,
87 )
87 )
88 dstrepo.register_wanted_sidedata(b"whatever")
88 dstrepo.register_wanted_sidedata(b"whatever")
89
89
90 return sidedata.get_sidedata_helpers(srcrepo, dstrepo._wanted_sidedata)
90 return sidedata.get_sidedata_helpers(srcrepo, dstrepo._wanted_sidedata)
91
91
92
92
93 def extsetup(ui):
93 def extsetup(ui):
94 extensions.wrapfunction(revlog.revlog, 'addrevision', wrapaddrevision)
94 extensions.wrapfunction(revlog.revlog, 'addrevision', wrapaddrevision)
95 extensions.wrapfunction(revlog.revlog, '_revisiondata', wrap_revisiondata)
95 extensions.wrapfunction(revlog.revlog, '_revisiondata', wrap_revisiondata)
96 extensions.wrapfunction(
96 extensions.wrapfunction(
97 upgrade_engine, 'get_sidedata_helpers', wrapget_sidedata_helpers
97 upgrade_engine, 'get_sidedata_helpers', wrapget_sidedata_helpers
98 )
98 )
99
99
100
100
101 def reposetup(ui, repo):
101 def reposetup(ui, repo):
102 # We don't register sidedata computers because we don't care within these
102 # We don't register sidedata computers because we don't care within these
103 # tests
103 # tests
104 repo.register_wanted_sidedata(sidedata.SD_TEST1)
104 repo.register_wanted_sidedata(sidedata.SD_TEST1)
105 repo.register_wanted_sidedata(sidedata.SD_TEST2)
105 repo.register_wanted_sidedata(sidedata.SD_TEST2)
General Comments 0
You need to be logged in to leave comments. Login now