Mercurial > public > mercurial-scm > hg
annotate tests/testlib/ext-sidedata-5.py @ 52654:f19a3f1437f3
pyupgrade: drop `coding=UTF-8` comments
PEP-3120[1] (Python 3.0 in 2007) says that UTF-8 is the default encoding. That
should be long enough ago that no reasonable editor would trip over this, and
certainly any supported version of Python won't.
The comments were probably harmless, but as `pyupgrade` has no mechanism to
disable this change, omitting this change makes it unusable as a code checking
tool, and makes it a pain to use occasionally to upgrade the source (since these
changes would need to be manually reverted).
[1] https://peps.python.org/pep-3120/
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Tue, 07 Jan 2025 16:46:21 -0500 |
parents | 6000f5b25c9b |
children |
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 # 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
|
2 # logic |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
3 # |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
4 # 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
|
5 # |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
6 # 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
|
7 # |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
8 # 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
|
9 # 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
|
10 |
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 import hashlib |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
13 import struct |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
14 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
15 from mercurial import ( |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
16 extensions, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
17 revlog, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
18 ) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
19 |
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 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
|
22 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
|
23 |
47078
223b47235d1c
sidedata: enable sidedata computers to optionally rewrite flags
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47073
diff
changeset
|
24 NO_FLAGS = (0, 0) |
223b47235d1c
sidedata: enable sidedata computers to optionally rewrite flags
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47073
diff
changeset
|
25 |
46718
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
26 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
27 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
|
28 sidedata = sidedata.copy() |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
29 if text is None: |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
30 text = revlog.revision(rev) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
31 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
|
32 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
|
33 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
34 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
35 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
|
36 sidedata = sidedata.copy() |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
37 if text is None: |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
38 text = revlog.revision(rev) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
39 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
|
40 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
|
41 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
|
42 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
43 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
44 def reposetup(ui, repo): |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
45 # 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
|
46 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
|
47 repo.register_sidedata_computer( |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
48 kind, |
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 (sidedatamod.SD_TEST1,), |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
51 compute_sidedata_1, |
47078
223b47235d1c
sidedata: enable sidedata computers to optionally rewrite flags
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47073
diff
changeset
|
52 0, |
46718
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
53 ) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
54 repo.register_sidedata_computer( |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
55 kind, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
56 sidedatamod.SD_TEST2, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
57 (sidedatamod.SD_TEST2,), |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
58 compute_sidedata_2, |
47078
223b47235d1c
sidedata: enable sidedata computers to optionally rewrite flags
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47073
diff
changeset
|
59 0, |
46718
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
60 ) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
61 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
62 # 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
|
63 # tests |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
64 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
|
65 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
|
66 |
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 def wrapaddrevision( |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
69 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
|
70 ): |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
71 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
|
72 kwargs['sidedata'] = {} |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
73 sd = kwargs['sidedata'] |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
74 ## 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
|
75 # text length |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
76 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
|
77 # and sha2 hashes |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
78 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
|
79 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
|
80 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
|
81 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
82 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
83 def extsetup(ui): |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
84 extensions.wrapfunction(revlog.revlog, 'addrevision', wrapaddrevision) |