tests/testlib/ext-sidedata-2.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Wed, 21 Feb 2024 11:09:25 +0100
changeset 51419 2eb93812d2a5
parent 48966 6000f5b25c9b
permissions -rw-r--r--
phases: filter revision that are already in the right phase No need to compute new roots if everything is already in order.
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
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    12
import hashlib
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    13
import struct
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    14
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    15
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
    16
from mercurial.revlogutils import constants
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43042
diff changeset
    17
47095
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Raphaël Gomès <rgomes@octobus.net>
parents: 47090
diff changeset
    18
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
    19
43040
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    20
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    21
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
    22
    sidedata = sidedata.copy()
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    23
    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
    24
        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
    25
    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
    26
    return sidedata, NO_FLAGS
43040
ba4072c0a911 sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    27
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43042
diff changeset
    28
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    29
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
    30
    sidedata = sidedata.copy()
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
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: 46722
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: 46722
diff changeset
    33
    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
    34
    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
    35
    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
    36
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43042
diff changeset
    37
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    38
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
    39
    # 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
    40
    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
    41
        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
    42
            kind,
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
            (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
            compute_sidedata_1,
47095
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Raphaël Gomès <rgomes@octobus.net>
parents: 47090
diff changeset
    46
            0,
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    47
        )
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    48
        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
    49
            kind,
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
            (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
            compute_sidedata_2,
47095
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Raphaël Gomès <rgomes@octobus.net>
parents: 47090
diff changeset
    53
            0,
46731
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46722
diff changeset
    54
        )