annotate tests/testlib/ext-sidedata-5.py @ 48670:6d2ddea0721a stable

stream-clone: filter possible missing requirements using all supported one The `supportedformat` requirements is missing some important requirements and it seems better to filter out with all requirements we know, not just an "arbitrary" subset. The `supportedformat` set is lacking some important requirements (for example `revlog-compression-zstd`). This is getting fixed on default (for Mercurial 6.1) However, fixing that in 6.1 means the stream requirements sent over the wire will contains more items. And if we don't apply this fix on older version, they might end up complaining about lacking support for feature they actually support for years. This patch does not fix the deeper problem (advertised stream requirement lacking some of them), but focus on the trivial part : Lets use the full set of supported requirement for looking for unsupported ones. This patch should be simple to backport to older version of Mercurial and packager should be encouraged to do so. This is a graft of d9017df70135 from default. Differential Revision: https://phab.mercurial-scm.org/D12091
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 24 Jan 2022 11:49:06 +0100
parents 223b47235d1c
children 6000f5b25c9b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
47073
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46718
diff changeset
24 from mercurial.revlogutils import constants
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
25
47078
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Raphaël Gomès <rgomes@octobus.net>
parents: 47073
diff changeset
26 NO_FLAGS = (0, 0)
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Raphaël Gomès <rgomes@octobus.net>
parents: 47073
diff changeset
27
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
28
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
29 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
30 sidedata = sidedata.copy()
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
31 if text is None:
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
32 text = revlog.revision(rev)
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
33 sidedata[sidedatamod.SD_TEST1] = struct.pack('>I', len(text))
47078
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Raphaël Gomès <rgomes@octobus.net>
parents: 47073
diff changeset
34 return sidedata, NO_FLAGS
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
35
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
36
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
37 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
38 sidedata = sidedata.copy()
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
39 if text is None:
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
40 text = revlog.revision(rev)
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
41 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
42 sidedata[sidedatamod.SD_TEST2] = struct.pack('>32s', sha256)
47078
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Raphaël Gomès <rgomes@octobus.net>
parents: 47073
diff changeset
43 return sidedata, NO_FLAGS
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
44
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
45
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
46 def reposetup(ui, repo):
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
47 # Sidedata keys happen to be the same as the categories, easier for testing.
47073
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46718
diff changeset
48 for kind in constants.ALL_KINDS:
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
49 repo.register_sidedata_computer(
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
50 kind,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
51 sidedatamod.SD_TEST1,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
52 (sidedatamod.SD_TEST1,),
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
53 compute_sidedata_1,
47078
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Raphaël Gomès <rgomes@octobus.net>
parents: 47073
diff changeset
54 0,
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
55 )
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
56 repo.register_sidedata_computer(
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
57 kind,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
58 sidedatamod.SD_TEST2,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
59 (sidedatamod.SD_TEST2,),
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
60 compute_sidedata_2,
47078
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Raphaël Gomès <rgomes@octobus.net>
parents: 47073
diff changeset
61 0,
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
62 )
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 # 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
65 # tests
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
66 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
67 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
68
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
69
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
70 def wrapaddrevision(
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
71 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
72 ):
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
73 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
74 kwargs['sidedata'] = {}
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
75 sd = kwargs['sidedata']
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
76 ## 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
77 # text length
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
78 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
79 # and sha2 hashes
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
80 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
81 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
82 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
83
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
84
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
85 def extsetup(ui):
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
86 extensions.wrapfunction(revlog.revlog, 'addrevision', wrapaddrevision)