Show More
@@ -0,0 +1,36 b'' | |||||
|
1 | # ext-sidedata.py - small extension to test the sidedata logic | |||
|
2 | # | |||
|
3 | # Copyright 2019 Pierre-Yves David <pierre-yves.david@octobus.net) | |||
|
4 | # | |||
|
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. | |||
|
7 | ||||
|
8 | from __future__ import absolute_import | |||
|
9 | ||||
|
10 | import hashlib | |||
|
11 | import struct | |||
|
12 | ||||
|
13 | from mercurial import ( | |||
|
14 | extensions, | |||
|
15 | revlog, | |||
|
16 | ) | |||
|
17 | ||||
|
18 | from mercurial.revlogutils import ( | |||
|
19 | sidedata, | |||
|
20 | ) | |||
|
21 | ||||
|
22 | def wrapaddrevision(orig, self, text, transaction, link, p1, p2, *args, | |||
|
23 | **kwargs): | |||
|
24 | if kwargs.get('sidedata') is None: | |||
|
25 | kwargs['sidedata'] = {} | |||
|
26 | sd = kwargs['sidedata'] | |||
|
27 | ## let's store some arbitrary data just for testing | |||
|
28 | # text length | |||
|
29 | sd[sidedata.SD_TEST1] = struct.pack('>I', len(text)) | |||
|
30 | # and sha2 hashes | |||
|
31 | sha256 = hashlib.sha256(text).digest() | |||
|
32 | sd[sidedata.SD_TEST2] = struct.pack('>32s', sha256) | |||
|
33 | return orig(self, text, transaction, link, p1, p2, *args, **kwargs) | |||
|
34 | ||||
|
35 | def extsetup(ui): | |||
|
36 | extensions.wrapfunction(revlog.revlog, 'addrevision', wrapaddrevision) |
@@ -38,6 +38,17 b' import struct' | |||||
38 |
|
38 | |||
39 | from .. import error |
|
39 | from .. import error | |
40 |
|
40 | |||
|
41 | ## sidedata type constant | |||
|
42 | # reserve a block for testing purposes. | |||
|
43 | SD_TEST1 = 1 | |||
|
44 | SD_TEST2 = 2 | |||
|
45 | SD_TEST3 = 3 | |||
|
46 | SD_TEST4 = 4 | |||
|
47 | SD_TEST5 = 5 | |||
|
48 | SD_TEST6 = 6 | |||
|
49 | SD_TEST7 = 7 | |||
|
50 | ||||
|
51 | # internal format constant | |||
41 | SIDEDATA_HEADER = struct.Struct('>H') |
|
52 | SIDEDATA_HEADER = struct.Struct('>H') | |
42 | SIDEDATA_ENTRY = struct.Struct('>HL20s') |
|
53 | SIDEDATA_ENTRY = struct.Struct('>HL20s') | |
43 |
|
54 |
@@ -2,6 +2,24 b'' | |||||
2 | Test file dedicated to checking side-data related behavior |
|
2 | Test file dedicated to checking side-data related behavior | |
3 | ========================================================== |
|
3 | ========================================================== | |
4 |
|
4 | |||
|
5 | Check data can be written/read from sidedata | |||
|
6 | ============================================ | |||
|
7 | ||||
|
8 | $ cat << EOF >> $HGRCPATH | |||
|
9 | > [extensions] | |||
|
10 | > testsidedata=$TESTDIR/testlib/ext-sidedata.py | |||
|
11 | > EOF | |||
|
12 | ||||
|
13 | $ hg init test-sidedata --config format.use-side-data=yes | |||
|
14 | $ cd test-sidedata | |||
|
15 | $ echo aaa > a | |||
|
16 | $ hg add a | |||
|
17 | $ hg commit -m a --traceback | |||
|
18 | $ echo aaa > b | |||
|
19 | $ hg add b | |||
|
20 | $ hg commit -m b | |||
|
21 | $ echo xxx >> a | |||
|
22 | $ hg commit -m aa | |||
5 |
|
23 | |||
6 | Check upgrade behavior |
|
24 | Check upgrade behavior | |
7 | ====================== |
|
25 | ====================== |
General Comments 0
You need to be logged in to leave comments.
Login now