tests/testlib/ext-sidedata-5.py
changeset 47078 223b47235d1c
parent 47073 64cd1496bb70
child 48875 6000f5b25c9b
equal deleted inserted replaced
47077:119790e1c67c 47078:223b47235d1c
    21 
    21 
    22 
    22 
    23 from mercurial.revlogutils import sidedata as sidedatamod
    23 from mercurial.revlogutils import sidedata as sidedatamod
    24 from mercurial.revlogutils import constants
    24 from mercurial.revlogutils import constants
    25 
    25 
       
    26 NO_FLAGS = (0, 0)
       
    27 
    26 
    28 
    27 def compute_sidedata_1(repo, revlog, rev, sidedata, text=None):
    29 def compute_sidedata_1(repo, revlog, rev, sidedata, text=None):
    28     sidedata = sidedata.copy()
    30     sidedata = sidedata.copy()
    29     if text is None:
    31     if text is None:
    30         text = revlog.revision(rev)
    32         text = revlog.revision(rev)
    31     sidedata[sidedatamod.SD_TEST1] = struct.pack('>I', len(text))
    33     sidedata[sidedatamod.SD_TEST1] = struct.pack('>I', len(text))
    32     return sidedata
    34     return sidedata, NO_FLAGS
    33 
    35 
    34 
    36 
    35 def compute_sidedata_2(repo, revlog, rev, sidedata, text=None):
    37 def compute_sidedata_2(repo, revlog, rev, sidedata, text=None):
    36     sidedata = sidedata.copy()
    38     sidedata = sidedata.copy()
    37     if text is None:
    39     if text is None:
    38         text = revlog.revision(rev)
    40         text = revlog.revision(rev)
    39     sha256 = hashlib.sha256(text).digest()
    41     sha256 = hashlib.sha256(text).digest()
    40     sidedata[sidedatamod.SD_TEST2] = struct.pack('>32s', sha256)
    42     sidedata[sidedatamod.SD_TEST2] = struct.pack('>32s', sha256)
    41     return sidedata
    43     return sidedata, NO_FLAGS
    42 
    44 
    43 
    45 
    44 def reposetup(ui, repo):
    46 def reposetup(ui, repo):
    45     # Sidedata keys happen to be the same as the categories, easier for testing.
    47     # Sidedata keys happen to be the same as the categories, easier for testing.
    46     for kind in constants.ALL_KINDS:
    48     for kind in constants.ALL_KINDS:
    47         repo.register_sidedata_computer(
    49         repo.register_sidedata_computer(
    48             kind,
    50             kind,
    49             sidedatamod.SD_TEST1,
    51             sidedatamod.SD_TEST1,
    50             (sidedatamod.SD_TEST1,),
    52             (sidedatamod.SD_TEST1,),
    51             compute_sidedata_1,
    53             compute_sidedata_1,
       
    54             0,
    52         )
    55         )
    53         repo.register_sidedata_computer(
    56         repo.register_sidedata_computer(
    54             kind,
    57             kind,
    55             sidedatamod.SD_TEST2,
    58             sidedatamod.SD_TEST2,
    56             (sidedatamod.SD_TEST2,),
    59             (sidedatamod.SD_TEST2,),
    57             compute_sidedata_2,
    60             compute_sidedata_2,
       
    61             0,
    58         )
    62         )
    59 
    63 
    60     # We don't register sidedata computers because we don't care within these
    64     # We don't register sidedata computers because we don't care within these
    61     # tests
    65     # tests
    62     repo.register_wanted_sidedata(sidedatamod.SD_TEST1)
    66     repo.register_wanted_sidedata(sidedatamod.SD_TEST1)