tests/testlib/ext-sidedata.py
changeset 43042 03e769278ef3
parent 43040 ba4072c0a911
child 43076 2372284d9457
equal deleted inserted replaced
43041:559ac8411f12 43042:03e769278ef3
    10 import hashlib
    10 import hashlib
    11 import struct
    11 import struct
    12 
    12 
    13 from mercurial import (
    13 from mercurial import (
    14     extensions,
    14     extensions,
       
    15     node,
    15     revlog,
    16     revlog,
    16 )
    17 )
    17 
    18 
    18 from mercurial.revlogutils import (
    19 from mercurial.revlogutils import (
    19     sidedata,
    20     sidedata,
    30     # and sha2 hashes
    31     # and sha2 hashes
    31     sha256 = hashlib.sha256(text).digest()
    32     sha256 = hashlib.sha256(text).digest()
    32     sd[sidedata.SD_TEST2] = struct.pack('>32s', sha256)
    33     sd[sidedata.SD_TEST2] = struct.pack('>32s', sha256)
    33     return orig(self, text, transaction, link, p1, p2, *args, **kwargs)
    34     return orig(self, text, transaction, link, p1, p2, *args, **kwargs)
    34 
    35 
       
    36 def wraprevision(orig, self, nodeorrev, *args, **kwargs):
       
    37     text = orig(self, nodeorrev, *args, **kwargs)
       
    38     if nodeorrev != node.nullrev and nodeorrev != node.nullid:
       
    39         sd = self.sidedata(nodeorrev)
       
    40         if len(text) != struct.unpack('>I', sd[sidedata.SD_TEST1])[0]:
       
    41             raise RuntimeError('text size mismatch')
       
    42         expected = sd[sidedata.SD_TEST2]
       
    43         got = hashlib.sha256(text).digest()
       
    44         if got != expected:
       
    45             raise RuntimeError('sha256 mismatch')
       
    46     return text
       
    47 
    35 def extsetup(ui):
    48 def extsetup(ui):
    36     extensions.wrapfunction(revlog.revlog, 'addrevision', wrapaddrevision)
    49     extensions.wrapfunction(revlog.revlog, 'addrevision', wrapaddrevision)
       
    50     extensions.wrapfunction(revlog.revlog, 'revision', wraprevision)