tests/test-parseindex
changeset 12476 4cce5194c307
parent 12475 c2b7bee11410
child 12477 e68cd3a90599
equal deleted inserted replaced
12475:c2b7bee11410 12476:4cce5194c307
     1 #!/bin/sh
       
     2 #
       
     3 # revlog.parseindex must be able to parse the index file even if
       
     4 # an index entry is split between two 64k blocks.  The ideal test
       
     5 # would be to create an index file with inline data where
       
     6 # 64k < size < 64k + 64 (64k is the size of the read buffer, 64 is
       
     7 # the size of an index entry) and with an index entry starting right
       
     8 # before the 64k block boundary, and try to read it.
       
     9 #
       
    10 # We approximate that by reducing the read buffer to 1 byte.
       
    11 #
       
    12 
       
    13 hg init a
       
    14 cd a
       
    15 echo abc > foo
       
    16 hg add foo
       
    17 hg commit -m 'add foo'
       
    18 
       
    19 echo >> foo
       
    20 hg commit -m 'change foo'
       
    21 hg log -r 0:
       
    22 
       
    23 cat >> test.py << EOF
       
    24 from mercurial import changelog, util
       
    25 from mercurial.node import *
       
    26 
       
    27 class singlebyteread(object):
       
    28     def __init__(self, real):
       
    29         self.real = real
       
    30 
       
    31     def read(self, size=-1):
       
    32         if size == 65536:
       
    33             size = 1
       
    34         return self.real.read(size)
       
    35 
       
    36     def __getattr__(self, key):
       
    37         return getattr(self.real, key)
       
    38 
       
    39 def opener(*args):
       
    40     o = util.opener(*args)
       
    41     def wrapper(*a):
       
    42         f = o(*a)
       
    43         return singlebyteread(f)
       
    44     return wrapper
       
    45 
       
    46 cl = changelog.changelog(opener('.hg/store'))
       
    47 print len(cl), 'revisions:'
       
    48 for r in cl:
       
    49     print short(cl.node(r))
       
    50 EOF
       
    51 
       
    52 python test.py