tests/testlib/ext-sidedata-2.py
author Gregory Szorc <gregory.szorc@gmail.com>
Sat, 19 Feb 2022 18:42:12 -0700
changeset 48938 4561ec90d3c1
parent 47095 223b47235d1c
child 48966 6000f5b25c9b
permissions -rw-r--r--
automation: delete code related to Python 2.7 support The building of Inno and WiX installers took a python_version argument that allowed us to specify "2" or "3" for the major Python version. Since we no longer support Python 2, we can delete this argument and everything feeding into it. Differential Revision: https://phab.mercurial-scm.org/D12264
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
     1
# coding: utf8
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
     2
# 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
     3
#
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
     4
# 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
     5
#
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
     6
# 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
     7
#
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     8
# 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
     9
# 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
    10
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    11
from __future__ import absolute_import
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    12
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    13
import hashlib
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    14
import struct
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    15
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    16
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
    17
from mercurial.revlogutils import constants
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43042
diff changeset
    18
47095
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Raphaël Gomès <rgomes@octobus.net>
parents: 47090
diff changeset
    19
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
    20
43040
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    21
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    22
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
    23
    sidedata = sidedata.copy()
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    24
    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
    25
        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
    26
    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
    27
    return sidedata, NO_FLAGS
43040
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    28
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43042
diff changeset
    29
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    30
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
    31
    sidedata = sidedata.copy()
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    32
    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
    33
        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
    34
    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
    35
    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
    36
    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
    37
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43042
diff changeset
    38
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    39
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
    40
    # 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
    41
    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
    42
        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
    43
            kind,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    44
            sidedatamod.SD_TEST1,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    45
            (sidedatamod.SD_TEST1,),
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    46
            compute_sidedata_1,
47095
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Raphaël Gomès <rgomes@octobus.net>
parents: 47090
diff changeset
    47
            0,
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    48
        )
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
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: 46722
diff changeset
    50
            kind,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    51
            sidedatamod.SD_TEST2,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    52
            (sidedatamod.SD_TEST2,),
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    53
            compute_sidedata_2,
47095
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Raphaël Gomès <rgomes@octobus.net>
parents: 47090
diff changeset
    54
            0,
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    55
        )