annotate tests/testlib/ext-sidedata-2.py @ 52679: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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
1 # ext-sidedata-2.py - small extension to test (differently) the sidedata logic
43040
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
2 #
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
3 # Simulates a client for a complex sidedata exchange.
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
4 #
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
5 # Copyright 2021 Raphaël Gomès <rgomes@octobus.net>
43040
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
6 #
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
7 # This software may be used and distributed according to the terms of the
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
8 # GNU General Public License version 2 or any later version.
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
9
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
10
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
11 import hashlib
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
12 import struct
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
13
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
14 from mercurial.revlogutils import sidedata as sidedatamod
47090
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46731
diff changeset
15 from mercurial.revlogutils import constants
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43042
diff changeset
16
47095
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47090
diff changeset
17 NO_FLAGS = (0, 0) # hoot
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47090
diff changeset
18
43040
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
19
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
20 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: 46722
diff changeset
21 sidedata = sidedata.copy()
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
22 if text is None:
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
23 text = revlog.revision(rev)
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
24 sidedata[sidedatamod.SD_TEST1] = struct.pack('>I', len(text))
47095
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47090
diff changeset
25 return sidedata, NO_FLAGS
43040
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
26
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43042
diff changeset
27
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
28 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: 46722
diff changeset
29 sidedata = sidedata.copy()
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
30 if text is None:
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
31 text = revlog.revision(rev)
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
32 sha256 = hashlib.sha256(text).digest()
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
33 sidedata[sidedatamod.SD_TEST2] = struct.pack('>32s', sha256)
47095
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47090
diff changeset
34 return sidedata, NO_FLAGS
43042
03e769278ef3 sidedata: check that the sidedata safely roundtrip
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43040
diff changeset
35
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43042
diff changeset
36
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
37 def reposetup(ui, repo):
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
38 # Sidedata keys happen to be the same as the categories, easier for testing.
47090
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46731
diff changeset
39 for kind in constants.ALL_KINDS:
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
40 repo.register_sidedata_computer(
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
41 kind,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
42 sidedatamod.SD_TEST1,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
43 (sidedatamod.SD_TEST1,),
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
44 compute_sidedata_1,
47095
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47090
diff changeset
45 0,
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
46 )
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
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: 46722
diff changeset
48 kind,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
49 sidedatamod.SD_TEST2,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
50 (sidedatamod.SD_TEST2,),
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
51 compute_sidedata_2,
47095
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47090
diff changeset
52 0,
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46722
diff changeset
53 )