Mercurial > public > mercurial-scm > hg
annotate tests/testlib/ext-sidedata-5.py @ 46718:ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
When a A exchanges with B, the difference of their supported sidedata categories
is made, and the responsibility is always with the client to generated it:
- If A pushes to B and B requires category `foo` that A does not have, A
will need to generate it when sending it to B.
- If A pulls from B and A needs category `foo`, it will generate `foo`
before the end of the transaction.
- Any category that is not required is removed. If peers are not compatible,
abort.
It is forbidden to rewrite sidedata for a rev that already has sidedata, since
that would introduce unreachable (garbage) data in the data file, something
we're not prepared for yet.
Differential Revision: https://phab.mercurial-scm.org/D10032
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Fri, 19 Feb 2021 11:24:50 +0100 |
parents | |
children | 64cd1496bb70 |
rev | line source |
---|---|
46718
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
1 # coding: utf8 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
2 # ext-sidedata-5.py - small extension to test (differently still) the sidedata |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
3 # logic |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
4 # |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
5 # Simulates a server for a simple sidedata exchange. |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
6 # |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
7 # Copyright 2021 Raphaël Gomès <rgomes@octobus.net> |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
8 # |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
9 # This software may be used and distributed according to the terms of the |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
10 # GNU General Public License version 2 or any later version. |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
11 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
12 from __future__ import absolute_import |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
13 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
14 import hashlib |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
15 import struct |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
16 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
17 from mercurial import ( |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
18 extensions, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
19 revlog, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
20 ) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
21 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
22 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
23 from mercurial.revlogutils import sidedata as sidedatamod |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
24 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
25 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
26 def compute_sidedata_1(repo, revlog, rev, sidedata, text=None): |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
27 sidedata = sidedata.copy() |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
28 if text is None: |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
29 text = revlog.revision(rev) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
30 sidedata[sidedatamod.SD_TEST1] = struct.pack('>I', len(text)) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
31 return sidedata |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
32 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
33 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
34 def compute_sidedata_2(repo, revlog, rev, sidedata, text=None): |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
35 sidedata = sidedata.copy() |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
36 if text is None: |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
37 text = revlog.revision(rev) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
38 sha256 = hashlib.sha256(text).digest() |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
39 sidedata[sidedatamod.SD_TEST2] = struct.pack('>32s', sha256) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
40 return sidedata |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
41 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
42 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
43 def reposetup(ui, repo): |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
44 # Sidedata keys happen to be the same as the categories, easier for testing. |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
45 for kind in (b'changelog', b'manifest', b'filelog'): |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
46 repo.register_sidedata_computer( |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
47 kind, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
48 sidedatamod.SD_TEST1, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
49 (sidedatamod.SD_TEST1,), |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
50 compute_sidedata_1, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
51 ) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
52 repo.register_sidedata_computer( |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
53 kind, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
54 sidedatamod.SD_TEST2, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
55 (sidedatamod.SD_TEST2,), |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
56 compute_sidedata_2, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
57 ) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
58 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
59 # We don't register sidedata computers because we don't care within these |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
60 # tests |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
61 repo.register_wanted_sidedata(sidedatamod.SD_TEST1) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
62 repo.register_wanted_sidedata(sidedatamod.SD_TEST2) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
63 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
64 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
65 def wrapaddrevision( |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
66 orig, self, text, transaction, link, p1, p2, *args, **kwargs |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
67 ): |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
68 if kwargs.get('sidedata') is None: |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
69 kwargs['sidedata'] = {} |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
70 sd = kwargs['sidedata'] |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
71 ## let's store some arbitrary data just for testing |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
72 # text length |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
73 sd[sidedatamod.SD_TEST1] = struct.pack('>I', len(text)) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
74 # and sha2 hashes |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
75 sha256 = hashlib.sha256(text).digest() |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
76 sd[sidedatamod.SD_TEST2] = struct.pack('>32s', sha256) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
77 return orig(self, text, transaction, link, p1, p2, *args, **kwargs) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
78 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
79 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
80 def extsetup(ui): |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
81 extensions.wrapfunction(revlog.revlog, 'addrevision', wrapaddrevision) |